mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-01 19:28:05 +08:00
[ADD] add runtime server and app status manage.update grpc vendor
This commit is contained in:
parent
cae1e2053e
commit
757a6f8938
@ -104,49 +104,6 @@ func (a *AppRuntimeSync) Start(errchan chan error) {
|
||||
|
||||
leader.RunAsLeader(a.conf.KubeClient, a.conf.LeaderElectionNamespace, a.conf.LeaderElectionIdentity, lockName, start, func() {})
|
||||
}
|
||||
func (a *AppRuntimeSync) selectMaster(errchan chan error) {
|
||||
master, err := etcdlock.CreateMasterLock(a.conf.EtcdEndPoints, "/rainbond/workermaster", fmt.Sprintf("%s:%d", a.hostIP, 6535), 10)
|
||||
if err != nil {
|
||||
errchan <- err
|
||||
return
|
||||
}
|
||||
a.master = master
|
||||
master.Start()
|
||||
defer master.Stop()
|
||||
for {
|
||||
select {
|
||||
case event := <-master.EventsChan():
|
||||
if event.Type == etcdlock.MasterAdded {
|
||||
if err := a.srss.Start(); err != nil {
|
||||
errchan <- err
|
||||
return
|
||||
}
|
||||
go a.startAppRuntimeSync()
|
||||
if err := a.registServer(); err != nil {
|
||||
errchan <- err
|
||||
return
|
||||
}
|
||||
a.masterRun = true
|
||||
}
|
||||
if event.Type == etcdlock.MasterDeleted {
|
||||
if a.masterRun {
|
||||
errchan <- fmt.Errorf("master node delete")
|
||||
}
|
||||
return
|
||||
}
|
||||
if event.Type == etcdlock.MasterError {
|
||||
if event.Error.Error() == "elect: session expired" {
|
||||
//TODO:if etcd error. worker restart
|
||||
}
|
||||
//if this is master node, exit
|
||||
if a.masterRun {
|
||||
errchan <- event.Error
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Stop stop app runtime sync server
|
||||
func (a *AppRuntimeSync) Stop() error {
|
||||
|
@ -45,6 +45,7 @@ type Config struct {
|
||||
NodeAPI string
|
||||
Listen string
|
||||
HostIP string
|
||||
ServerPort int
|
||||
KubeClient *kubernetes.Clientset
|
||||
LeaderElectionNamespace string
|
||||
LeaderElectionIdentity string
|
||||
@ -79,6 +80,7 @@ func (a *Worker) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.StringVar(&a.RunMode, "run", "sync", "sync data when worker start")
|
||||
fs.StringVar(&a.NodeName, "node-name", "", "the name of this worker,it must be global unique name")
|
||||
fs.StringVar(&a.HostIP, "host-ip", "", "the ip of this worker,it must be global connected ip")
|
||||
fs.IntVar(&a.ServerPort, "server-port", 6535, "the listen port that app runtime server")
|
||||
fs.StringVar(&a.NodeAPI, "node-api", "http://172.30.42.1:6100", "node discover api, node docker endpoints")
|
||||
flag.StringVar(&a.LeaderElectionNamespace, "leader-election-namespace", "rainbond", "Namespace where this attacher runs.")
|
||||
flag.StringVar(&a.LeaderElectionIdentity, "leader-election-identity", "", "Unique idenity of this attcher. Typically name of the pod where the attacher runs.")
|
||||
|
@ -19,28 +19,23 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/goodrain/rainbond/appruntimesync"
|
||||
"github.com/goodrain/rainbond/appruntimesync/client"
|
||||
"github.com/goodrain/rainbond/worker/server"
|
||||
|
||||
"github.com/goodrain/rainbond/cmd/worker/option"
|
||||
"github.com/goodrain/rainbond/db"
|
||||
"github.com/goodrain/rainbond/db/config"
|
||||
"github.com/goodrain/rainbond/event"
|
||||
"github.com/goodrain/rainbond/worker/appm"
|
||||
"github.com/goodrain/rainbond/worker/appm/controller"
|
||||
"github.com/goodrain/rainbond/worker/appm/store"
|
||||
"github.com/goodrain/rainbond/worker/discover"
|
||||
"github.com/goodrain/rainbond/worker/executor"
|
||||
"github.com/goodrain/rainbond/worker/monitor"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -79,7 +74,7 @@ func Run(s *option.Worker) error {
|
||||
return err
|
||||
}
|
||||
s.Config.KubeClient = clientset
|
||||
|
||||
//step 3: create resource store
|
||||
cachestore := store.NewStore(db.GetManager(), s.Config)
|
||||
if err := cachestore.Start(); err != nil {
|
||||
logrus.Error("start kube cache store error", err)
|
||||
@ -87,53 +82,23 @@ func Run(s *option.Worker) error {
|
||||
}
|
||||
controllerManager := controller.NewManager(cachestore, clientset)
|
||||
defer controllerManager.Stop()
|
||||
//step 3 : create and start app runtime module
|
||||
ars := appruntimesync.CreateAppRuntimeSync(s.Config)
|
||||
go ars.Start(errChan)
|
||||
defer ars.Stop()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
statusClient, err := client.NewClient(ctx, client.AppRuntimeSyncClientConf{
|
||||
EtcdEndpoints: s.Config.EtcdEndPoints,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
appmm, err := appm.NewManager(s.Config, statusClient)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer appmm.Stop()
|
||||
|
||||
if s.RunMode == "sync" {
|
||||
go appmm.SyncData()
|
||||
}
|
||||
//step 4 : create executor module
|
||||
executorManager, err := executor.NewManager(s.Config, statusClient, appmm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
executorManager.Start()
|
||||
defer executorManager.Stop()
|
||||
//step 5 : create discover module
|
||||
taskManager := discover.NewTaskManager(s.Config, executorManager, cachestore, statusClient, controllerManager)
|
||||
//step 4 : create discover module
|
||||
taskManager := discover.NewTaskManager(s.Config, cachestore, controllerManager)
|
||||
if err := taskManager.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
defer taskManager.Stop()
|
||||
|
||||
//step 6 :create application use resource exporter.
|
||||
exporterManager := monitor.NewManager(s.Config, statusClient)
|
||||
//step 5: start app runtimer server
|
||||
runtimeServer := server.CreaterRuntimeServer(s.Config, cachestore)
|
||||
runtimeServer.Start(errChan)
|
||||
//step 6: create application use resource exporter.
|
||||
exporterManager := monitor.NewManager(s.Config, nil)
|
||||
if err := exporterManager.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
defer exporterManager.Stop()
|
||||
|
||||
//step 7 :enable pprof api
|
||||
logrus.Info("pprof api listen port 3229")
|
||||
go http.ListenAndServe(":3229", nil)
|
||||
|
||||
logrus.Info("worker begin running...")
|
||||
|
||||
//step finally: listen Signal
|
||||
|
18
util/uuid.go
18
util/uuid.go
@ -18,11 +18,25 @@
|
||||
|
||||
package util
|
||||
|
||||
import "github.com/twinj/uuid"
|
||||
import "strings"
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/twinj/uuid"
|
||||
)
|
||||
|
||||
//NewUUID 创建无-的32位uuid
|
||||
func NewUUID() string {
|
||||
uid := uuid.NewV4().String()
|
||||
return strings.Replace(uid, "-", "", -1)
|
||||
}
|
||||
|
||||
//TimeVersion time version
|
||||
type TimeVersion string
|
||||
|
||||
//NewTimeVersion return version string by time
|
||||
func NewTimeVersion() TimeVersion {
|
||||
now := time.Now()
|
||||
return TimeVersion(fmt.Sprintf("%d", now.UnixNano()))
|
||||
}
|
||||
|
26
util/uuid_test.go
Normal file
26
util/uuid_test.go
Normal file
@ -0,0 +1,26 @@
|
||||
// RAINBOND, Application Management Platform
|
||||
// Copyright (C) 2014-2017 Goodrain Co., Ltd.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version. For any non-GPL usage of Rainbond,
|
||||
// one or multiple Commercial Licenses authorized by Goodrain Co., Ltd.
|
||||
// must be obtained first.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package util
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestTimeVersion(t *testing.T) {
|
||||
version := NewTimeVersion()
|
||||
t.Log(version)
|
||||
}
|
6
vendor/github.com/coreos/etcd/clientv3/naming/grpc.go
generated
vendored
6
vendor/github.com/coreos/etcd/clientv3/naming/grpc.go
generated
vendored
@ -74,9 +74,11 @@ type gRPCWatcher struct {
|
||||
// Calls to Next should be serialized; concurrent calls are not safe since
|
||||
// there is no way to reconcile the update ordering.
|
||||
func (gw *gRPCWatcher) Next() ([]*naming.Update, error) {
|
||||
|
||||
if gw.wch == nil {
|
||||
// first Next() returns all addresses
|
||||
return gw.firstNext()
|
||||
all, err := gw.firstNext()
|
||||
return all, err
|
||||
}
|
||||
if gw.err != nil {
|
||||
return nil, gw.err
|
||||
@ -118,7 +120,6 @@ func (gw *gRPCWatcher) firstNext() ([]*naming.Update, error) {
|
||||
if gw.err = err; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
updates := make([]*naming.Update, 0, len(resp.Kvs))
|
||||
for _, kv := range resp.Kvs {
|
||||
var jupdate naming.Update
|
||||
@ -127,7 +128,6 @@ func (gw *gRPCWatcher) firstNext() ([]*naming.Update, error) {
|
||||
}
|
||||
updates = append(updates, &jupdate)
|
||||
}
|
||||
|
||||
opts := []etcd.OpOption{etcd.WithRev(resp.Header.Revision + 1), etcd.WithPrefix(), etcd.WithPrevKV()}
|
||||
gw.wch = gw.c.Watch(gw.ctx, gw.target, opts...)
|
||||
return updates, nil
|
||||
|
16
vendor/github.com/golang/protobuf/.gitignore
generated
vendored
16
vendor/github.com/golang/protobuf/.gitignore
generated
vendored
@ -1,16 +0,0 @@
|
||||
.DS_Store
|
||||
*.[568ao]
|
||||
*.ao
|
||||
*.so
|
||||
*.pyc
|
||||
._*
|
||||
.nfs.*
|
||||
[568a].out
|
||||
*~
|
||||
*.orig
|
||||
core
|
||||
_obj
|
||||
_test
|
||||
_testmain.go
|
||||
protoc-gen-go/testdata/multi/*.pb.go
|
||||
_conformance/_conformance
|
3
vendor/github.com/golang/protobuf/AUTHORS
generated
vendored
3
vendor/github.com/golang/protobuf/AUTHORS
generated
vendored
@ -1,3 +0,0 @@
|
||||
# This source code refers to The Go Authors for copyright purposes.
|
||||
# The master list of authors is in the main Go distribution,
|
||||
# visible at http://tip.golang.org/AUTHORS.
|
3
vendor/github.com/golang/protobuf/CONTRIBUTORS
generated
vendored
3
vendor/github.com/golang/protobuf/CONTRIBUTORS
generated
vendored
@ -1,3 +0,0 @@
|
||||
# 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.
|
40
vendor/github.com/golang/protobuf/Make.protobuf
generated
vendored
40
vendor/github.com/golang/protobuf/Make.protobuf
generated
vendored
@ -1,40 +0,0 @@
|
||||
# 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.
|
||||
|
||||
# Includable Makefile to add a rule for generating .pb.go files from .proto files
|
||||
# (Google protocol buffer descriptions).
|
||||
# Typical use if myproto.proto is a file in package mypackage in this directory:
|
||||
#
|
||||
# include $(GOROOT)/src/pkg/github.com/golang/protobuf/Make.protobuf
|
||||
|
||||
%.pb.go: %.proto
|
||||
protoc --go_out=. $<
|
||||
|
55
vendor/github.com/golang/protobuf/Makefile
generated
vendored
55
vendor/github.com/golang/protobuf/Makefile
generated
vendored
@ -1,55 +0,0 @@
|
||||
# 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: install
|
||||
|
||||
install:
|
||||
go install ./proto ./jsonpb ./ptypes
|
||||
go install ./protoc-gen-go
|
||||
|
||||
test:
|
||||
go test ./proto ./jsonpb ./ptypes
|
||||
make -C protoc-gen-go/testdata test
|
||||
|
||||
clean:
|
||||
go clean ./...
|
||||
|
||||
nuke:
|
||||
go clean -i ./...
|
||||
|
||||
regenerate:
|
||||
make -C protoc-gen-go/descriptor regenerate
|
||||
make -C protoc-gen-go/plugin regenerate
|
||||
make -C protoc-gen-go/testdata regenerate
|
||||
make -C proto/testdata regenerate
|
||||
make -C jsonpb/jsonpb_test_proto regenerate
|
||||
make -C _conformance regenerate
|
33
vendor/github.com/golang/protobuf/_conformance/Makefile
generated
vendored
33
vendor/github.com/golang/protobuf/_conformance/Makefile
generated
vendored
@ -1,33 +0,0 @@
|
||||
# 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 --go_out=Mgoogle/protobuf/any.proto=github.com/golang/protobuf/ptypes/any,Mgoogle/protobuf/duration.proto=github.com/golang/protobuf/ptypes/duration,Mgoogle/protobuf/struct.proto=github.com/golang/protobuf/ptypes/struct,Mgoogle/protobuf/timestamp.proto=github.com/golang/protobuf/ptypes/timestamp,Mgoogle/protobuf/wrappers.proto=github.com/golang/protobuf/ptypes/wrappers,Mgoogle/protobuf/field_mask.proto=google.golang.org/genproto/protobuf:. conformance_proto/conformance.proto
|
161
vendor/github.com/golang/protobuf/_conformance/conformance.go
generated
vendored
161
vendor/github.com/golang/protobuf/_conformance/conformance.go
generated
vendored
@ -1,161 +0,0 @@
|
||||
// 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/golang/protobuf/_conformance/conformance_proto"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/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",
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
1885
vendor/github.com/golang/protobuf/_conformance/conformance_proto/conformance.pb.go
generated
vendored
1885
vendor/github.com/golang/protobuf/_conformance/conformance_proto/conformance.pb.go
generated
vendored
File diff suppressed because it is too large
Load Diff
285
vendor/github.com/golang/protobuf/_conformance/conformance_proto/conformance.proto
generated
vendored
285
vendor/github.com/golang/protobuf/_conformance/conformance_proto/conformance.proto
generated
vendored
@ -1,285 +0,0 @@
|
||||
// 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 <sfixed32, sfixed32> map_sfixed32_sfixed32 = 64;
|
||||
map <sfixed64, sfixed64> 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;
|
||||
}
|
93
vendor/github.com/golang/protobuf/descriptor/descriptor.go
generated
vendored
93
vendor/github.com/golang/protobuf/descriptor/descriptor.go
generated
vendored
@ -1,93 +0,0 @@
|
||||
// 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 descriptor provides functions for obtaining protocol buffer
|
||||
// descriptors for generated Go types.
|
||||
//
|
||||
// These functions cannot go in package proto because they depend on the
|
||||
// generated protobuf descriptor messages, which themselves depend on proto.
|
||||
package descriptor
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
protobuf "github.com/golang/protobuf/protoc-gen-go/descriptor"
|
||||
)
|
||||
|
||||
// extractFile extracts a FileDescriptorProto from a gzip'd buffer.
|
||||
func extractFile(gz []byte) (*protobuf.FileDescriptorProto, error) {
|
||||
r, err := gzip.NewReader(bytes.NewReader(gz))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open gzip reader: %v", err)
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
b, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to uncompress descriptor: %v", err)
|
||||
}
|
||||
|
||||
fd := new(protobuf.FileDescriptorProto)
|
||||
if err := proto.Unmarshal(b, fd); err != nil {
|
||||
return nil, fmt.Errorf("malformed FileDescriptorProto: %v", err)
|
||||
}
|
||||
|
||||
return fd, nil
|
||||
}
|
||||
|
||||
// Message is a proto.Message with a method to return its descriptor.
|
||||
//
|
||||
// Message types generated by the protocol compiler always satisfy
|
||||
// the Message interface.
|
||||
type Message interface {
|
||||
proto.Message
|
||||
Descriptor() ([]byte, []int)
|
||||
}
|
||||
|
||||
// ForMessage returns a FileDescriptorProto and a DescriptorProto from within it
|
||||
// describing the given message.
|
||||
func ForMessage(msg Message) (fd *protobuf.FileDescriptorProto, md *protobuf.DescriptorProto) {
|
||||
gz, path := msg.Descriptor()
|
||||
fd, err := extractFile(gz)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("invalid FileDescriptorProto for %T: %v", msg, err))
|
||||
}
|
||||
|
||||
md = fd.MessageType[path[0]]
|
||||
for _, i := range path[1:] {
|
||||
md = md.NestedType[i]
|
||||
}
|
||||
return fd, md
|
||||
}
|
32
vendor/github.com/golang/protobuf/descriptor/descriptor_test.go
generated
vendored
32
vendor/github.com/golang/protobuf/descriptor/descriptor_test.go
generated
vendored
@ -1,32 +0,0 @@
|
||||
package descriptor_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/protobuf/descriptor"
|
||||
tpb "github.com/golang/protobuf/proto/testdata"
|
||||
protobuf "github.com/golang/protobuf/protoc-gen-go/descriptor"
|
||||
)
|
||||
|
||||
func TestMessage(t *testing.T) {
|
||||
var msg *protobuf.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.
|
||||
}
|
1045
vendor/github.com/golang/protobuf/jsonpb/jsonpb.go
generated
vendored
1045
vendor/github.com/golang/protobuf/jsonpb/jsonpb.go
generated
vendored
File diff suppressed because it is too large
Load Diff
768
vendor/github.com/golang/protobuf/jsonpb/jsonpb_test.go
generated
vendored
768
vendor/github.com/golang/protobuf/jsonpb/jsonpb_test.go
generated
vendored
@ -1,768 +0,0 @@
|
||||
// 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"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
|
||||
pb "github.com/golang/protobuf/jsonpb/jsonpb_test_proto"
|
||||
proto3pb "github.com/golang/protobuf/proto/proto3_proto"
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
anypb "github.com/golang/protobuf/ptypes/any"
|
||||
durpb "github.com/golang/protobuf/ptypes/duration"
|
||||
stpb "github.com/golang/protobuf/ptypes/struct"
|
||||
tspb "github.com/golang/protobuf/ptypes/timestamp"
|
||||
wpb "github.com/golang/protobuf/ptypes/wrappers"
|
||||
)
|
||||
|
||||
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"),
|
||||
}
|
||||
|
||||
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"` +
|
||||
`}`
|
||||
|
||||
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"
|
||||
}`
|
||||
|
||||
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: &anypb.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: &anypb.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<int64, int32>", marshaler, &pb.Mappy{Nummy: map[int64]int32{1: 2, 3: 4}}, `{"nummy":{"1":2,"3":4}}`},
|
||||
{"map<int64, int32>", marshalerAllOptions, &pb.Mappy{Nummy: map[int64]int32{1: 2, 3: 4}}, nummyPrettyJSON},
|
||||
{"map<string, string>", marshaler,
|
||||
&pb.Mappy{Strry: map[string]string{`"one"`: "two", "three": "four"}},
|
||||
`{"strry":{"\"one\"":"two","three":"four"}}`},
|
||||
{"map<int32, Object>", marshaler,
|
||||
&pb.Mappy{Objjy: map[int32]*pb.Simple3{1: &pb.Simple3{Dub: 1}}}, `{"objjy":{"1":{"dub":1}}}`},
|
||||
{"map<int32, Object>", marshalerAllOptions,
|
||||
&pb.Mappy{Objjy: map[int32]*pb.Simple3{1: &pb.Simple3{Dub: 1}}}, objjyPrettyJSON},
|
||||
{"map<int64, string>", marshaler, &pb.Mappy{Buggy: map[int64]string{1234: "yup"}},
|
||||
`{"buggy":{"1234":"yup"}}`},
|
||||
{"map<bool, bool>", marshaler, &pb.Mappy{Booly: map[bool]bool{false: true}}, `{"booly":{"false":true}}`},
|
||||
// TODO: This is broken.
|
||||
//{"map<string, enum>", marshaler, &pb.Mappy{Enumy: map[string]pb.Numeral{"XIV": pb.Numeral_ROMAN}}, `{"enumy":{"XIV":"ROMAN"}`},
|
||||
{"map<string, enum as int>", Marshaler{EnumsAsInts: true}, &pb.Mappy{Enumy: map[string]pb.Numeral{"XIV": pb.Numeral_ROMAN}}, `{"enumy":{"XIV":2}}`},
|
||||
{"map<int32, bool>", 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<int64, bool>", 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<uint32, bool>", 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<uint64, bool>", 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<int64, string>", marshaler, &pb.Maps{MInt64Str: map[int64]string{213: "cat"}},
|
||||
`{"mInt64Str":{"213":"cat"}}`},
|
||||
{"proto2 map<bool, Object>", marshaler,
|
||||
&pb.Maps{MBoolSimple: map[bool]*pb.Simple{true: &pb.Simple{OInt32: proto.Int32(1)}}},
|
||||
`{"mBoolSimple":{"true":{"oInt32":1}}}`},
|
||||
{"oneof, not set", marshaler, &pb.MsgWithOneof{}, `{}`},
|
||||
{"oneof, set", marshaler, &pb.MsgWithOneof{Union: &pb.MsgWithOneof_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: &durpb.Duration{Seconds: 3}}, `{"dur":"3.000s"}`},
|
||||
{"Struct", marshaler, &pb.KnownTypes{St: &stpb.Struct{
|
||||
Fields: map[string]*stpb.Value{
|
||||
"one": {Kind: &stpb.Value_StringValue{"loneliest number"}},
|
||||
"two": {Kind: &stpb.Value_NullValue{stpb.NullValue_NULL_VALUE}},
|
||||
},
|
||||
}}, `{"st":{"one":"loneliest number","two":null}}`},
|
||||
{"empty ListValue", marshaler, &pb.KnownTypes{Lv: &stpb.ListValue{}}, `{"lv":[]}`},
|
||||
{"basic ListValue", marshaler, &pb.KnownTypes{Lv: &stpb.ListValue{Values: []*stpb.Value{
|
||||
{Kind: &stpb.Value_StringValue{"x"}},
|
||||
{Kind: &stpb.Value_NullValue{}},
|
||||
{Kind: &stpb.Value_NumberValue{3}},
|
||||
{Kind: &stpb.Value_BoolValue{true}},
|
||||
}}}, `{"lv":["x",null,3,true]}`},
|
||||
{"Timestamp", marshaler, &pb.KnownTypes{Ts: &tspb.Timestamp{Seconds: 14e8, Nanos: 21e6}}, `{"ts":"2014-05-13T16:53:20.021Z"}`},
|
||||
{"number Value", marshaler, &pb.KnownTypes{Val: &stpb.Value{Kind: &stpb.Value_NumberValue{1}}}, `{"val":1}`},
|
||||
{"null Value", marshaler, &pb.KnownTypes{Val: &stpb.Value{Kind: &stpb.Value_NullValue{stpb.NullValue_NULL_VALUE}}}, `{"val":null}`},
|
||||
{"string number value", marshaler, &pb.KnownTypes{Val: &stpb.Value{Kind: &stpb.Value_StringValue{"9223372036854775807"}}}, `{"val":"9223372036854775807"}`},
|
||||
{"list of lists Value", marshaler, &pb.KnownTypes{Val: &stpb.Value{
|
||||
Kind: &stpb.Value_ListValue{&stpb.ListValue{
|
||||
Values: []*stpb.Value{
|
||||
{Kind: &stpb.Value_StringValue{"x"}},
|
||||
{Kind: &stpb.Value_ListValue{&stpb.ListValue{
|
||||
Values: []*stpb.Value{
|
||||
{Kind: &stpb.Value_ListValue{&stpb.ListValue{
|
||||
Values: []*stpb.Value{{Kind: &stpb.Value_StringValue{"y"}}},
|
||||
}}},
|
||||
{Kind: &stpb.Value_StringValue{"z"}},
|
||||
},
|
||||
}}},
|
||||
},
|
||||
}},
|
||||
}}, `{"val":["x",[["y"],"z"]]}`},
|
||||
|
||||
{"DoubleValue", marshaler, &pb.KnownTypes{Dbl: &wpb.DoubleValue{Value: 1.2}}, `{"dbl":1.2}`},
|
||||
{"FloatValue", marshaler, &pb.KnownTypes{Flt: &wpb.FloatValue{Value: 1.2}}, `{"flt":1.2}`},
|
||||
{"Int64Value", marshaler, &pb.KnownTypes{I64: &wpb.Int64Value{Value: -3}}, `{"i64":"-3"}`},
|
||||
{"UInt64Value", marshaler, &pb.KnownTypes{U64: &wpb.UInt64Value{Value: 3}}, `{"u64":"3"}`},
|
||||
{"Int32Value", marshaler, &pb.KnownTypes{I32: &wpb.Int32Value{Value: -4}}, `{"i32":-4}`},
|
||||
{"UInt32Value", marshaler, &pb.KnownTypes{U32: &wpb.UInt32Value{Value: 4}}, `{"u32":4}`},
|
||||
{"BoolValue", marshaler, &pb.KnownTypes{Bool: &wpb.BoolValue{Value: true}}, `{"bool":true}`},
|
||||
{"StringValue", marshaler, &pb.KnownTypes{Str: &wpb.StringValue{Value: "plush"}}, `{"str":"plush"}`},
|
||||
{"BytesValue", marshaler, &pb.KnownTypes{Bytes: &wpb.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 := ptypes.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<int64, int32>", Unmarshaler{}, `{"nummy":{"1":2,"3":4}}`, &pb.Mappy{Nummy: map[int64]int32{1: 2, 3: 4}}},
|
||||
{"map<string, string>", Unmarshaler{}, `{"strry":{"\"one\"":"two","three":"four"}}`, &pb.Mappy{Strry: map[string]string{`"one"`: "two", "three": "four"}}},
|
||||
{"map<int32, Object>", Unmarshaler{}, `{"objjy":{"1":{"dub":1}}}`, &pb.Mappy{Objjy: map[int32]*pb.Simple3{1: &pb.Simple3{Dub: 1}}}},
|
||||
{"proto2 extension", Unmarshaler{}, realNumberJSON, realNumber},
|
||||
{"Any with message", Unmarshaler{}, anySimpleJSON, anySimple},
|
||||
{"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<string, enum>", Unmarshaler{}, `{"enumy":{"XIV":"ROMAN"}`, &pb.Mappy{Enumy: map[string]pb.Numeral{"XIV": pb.Numeral_ROMAN}}},
|
||||
{"map<string, enum as int>", 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{31000}}},
|
||||
{"oneof spec name", Unmarshaler{}, `{"Country":"Australia"}`, &pb.MsgWithOneof{Union: &pb.MsgWithOneof_Country{"Australia"}}},
|
||||
{"oneof orig_name", Unmarshaler{}, `{"Country":"Australia"}`, &pb.MsgWithOneof{Union: &pb.MsgWithOneof_Country{"Australia"}}},
|
||||
{"oneof spec name2", Unmarshaler{}, `{"homeAddress":"Australia"}`, &pb.MsgWithOneof{Union: &pb.MsgWithOneof_HomeAddress{"Australia"}}},
|
||||
{"oneof orig_name2", Unmarshaler{}, `{"home_address":"Australia"}`, &pb.MsgWithOneof{Union: &pb.MsgWithOneof_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: &durpb.Duration{Seconds: 3}}},
|
||||
{"null Duration", Unmarshaler{}, `{"dur":null}`, &pb.KnownTypes{Dur: nil}},
|
||||
{"Timestamp", Unmarshaler{}, `{"ts":"2014-05-13T16:53:20.021Z"}`, &pb.KnownTypes{Ts: &tspb.Timestamp{Seconds: 14e8, Nanos: 21e6}}},
|
||||
{"PreEpochTimestamp", Unmarshaler{}, `{"ts":"1969-12-31T23:59:58.999999995Z"}`, &pb.KnownTypes{Ts: &tspb.Timestamp{Seconds: -2, Nanos: 999999995}}},
|
||||
{"ZeroTimeTimestamp", Unmarshaler{}, `{"ts":"0001-01-01T00:00:00Z"}`, &pb.KnownTypes{Ts: &tspb.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: &stpb.Struct{}}},
|
||||
{"basic Struct", Unmarshaler{}, `{"st": {"a": "x", "b": null, "c": 3, "d": true}}`, &pb.KnownTypes{St: &stpb.Struct{Fields: map[string]*stpb.Value{
|
||||
"a": {Kind: &stpb.Value_StringValue{"x"}},
|
||||
"b": {Kind: &stpb.Value_NullValue{}},
|
||||
"c": {Kind: &stpb.Value_NumberValue{3}},
|
||||
"d": {Kind: &stpb.Value_BoolValue{true}},
|
||||
}}}},
|
||||
{"nested Struct", Unmarshaler{}, `{"st": {"a": {"b": 1, "c": [{"d": true}, "f"]}}}`, &pb.KnownTypes{St: &stpb.Struct{Fields: map[string]*stpb.Value{
|
||||
"a": {Kind: &stpb.Value_StructValue{&stpb.Struct{Fields: map[string]*stpb.Value{
|
||||
"b": {Kind: &stpb.Value_NumberValue{1}},
|
||||
"c": {Kind: &stpb.Value_ListValue{&stpb.ListValue{Values: []*stpb.Value{
|
||||
{Kind: &stpb.Value_StructValue{&stpb.Struct{Fields: map[string]*stpb.Value{"d": {Kind: &stpb.Value_BoolValue{true}}}}}},
|
||||
{Kind: &stpb.Value_StringValue{"f"}},
|
||||
}}}},
|
||||
}}}},
|
||||
}}}},
|
||||
{"null ListValue", Unmarshaler{}, `{"lv": null}`, &pb.KnownTypes{Lv: nil}},
|
||||
{"empty ListValue", Unmarshaler{}, `{"lv": []}`, &pb.KnownTypes{Lv: &stpb.ListValue{}}},
|
||||
{"basic ListValue", Unmarshaler{}, `{"lv": ["x", null, 3, true]}`, &pb.KnownTypes{Lv: &stpb.ListValue{Values: []*stpb.Value{
|
||||
{Kind: &stpb.Value_StringValue{"x"}},
|
||||
{Kind: &stpb.Value_NullValue{}},
|
||||
{Kind: &stpb.Value_NumberValue{3}},
|
||||
{Kind: &stpb.Value_BoolValue{true}},
|
||||
}}}},
|
||||
{"number Value", Unmarshaler{}, `{"val":1}`, &pb.KnownTypes{Val: &stpb.Value{Kind: &stpb.Value_NumberValue{1}}}},
|
||||
{"null Value", Unmarshaler{}, `{"val":null}`, &pb.KnownTypes{Val: &stpb.Value{Kind: &stpb.Value_NullValue{stpb.NullValue_NULL_VALUE}}}},
|
||||
{"bool Value", Unmarshaler{}, `{"val":true}`, &pb.KnownTypes{Val: &stpb.Value{Kind: &stpb.Value_BoolValue{true}}}},
|
||||
{"string Value", Unmarshaler{}, `{"val":"x"}`, &pb.KnownTypes{Val: &stpb.Value{Kind: &stpb.Value_StringValue{"x"}}}},
|
||||
{"string number value", Unmarshaler{}, `{"val":"9223372036854775807"}`, &pb.KnownTypes{Val: &stpb.Value{Kind: &stpb.Value_StringValue{"9223372036854775807"}}}},
|
||||
{"list of lists Value", Unmarshaler{}, `{"val":["x", [["y"], "z"]]}`, &pb.KnownTypes{Val: &stpb.Value{
|
||||
Kind: &stpb.Value_ListValue{&stpb.ListValue{
|
||||
Values: []*stpb.Value{
|
||||
{Kind: &stpb.Value_StringValue{"x"}},
|
||||
{Kind: &stpb.Value_ListValue{&stpb.ListValue{
|
||||
Values: []*stpb.Value{
|
||||
{Kind: &stpb.Value_ListValue{&stpb.ListValue{
|
||||
Values: []*stpb.Value{{Kind: &stpb.Value_StringValue{"y"}}},
|
||||
}}},
|
||||
{Kind: &stpb.Value_StringValue{"z"}},
|
||||
},
|
||||
}}},
|
||||
},
|
||||
}}}}},
|
||||
|
||||
{"DoubleValue", Unmarshaler{}, `{"dbl":1.2}`, &pb.KnownTypes{Dbl: &wpb.DoubleValue{Value: 1.2}}},
|
||||
{"FloatValue", Unmarshaler{}, `{"flt":1.2}`, &pb.KnownTypes{Flt: &wpb.FloatValue{Value: 1.2}}},
|
||||
{"Int64Value", Unmarshaler{}, `{"i64":"-3"}`, &pb.KnownTypes{I64: &wpb.Int64Value{Value: -3}}},
|
||||
{"UInt64Value", Unmarshaler{}, `{"u64":"3"}`, &pb.KnownTypes{U64: &wpb.UInt64Value{Value: 3}}},
|
||||
{"Int32Value", Unmarshaler{}, `{"i32":-4}`, &pb.KnownTypes{I32: &wpb.Int32Value{Value: -4}}},
|
||||
{"UInt32Value", Unmarshaler{}, `{"u32":4}`, &pb.KnownTypes{U32: &wpb.UInt32Value{Value: 4}}},
|
||||
{"BoolValue", Unmarshaler{}, `{"bool":true}`, &pb.KnownTypes{Bool: &wpb.BoolValue{Value: true}}},
|
||||
{"StringValue", Unmarshaler{}, `{"str":"plush"}`, &pb.KnownTypes{Str: &wpb.StringValue{Value: "plush"}}},
|
||||
{"BytesValue", Unmarshaler{}, `{"bytes":"d293"}`, &pb.KnownTypes{Bytes: &wpb.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 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 TestUnmarshalAnyJSONPBUnmarshaler(t *testing.T) {
|
||||
rawJson := `{ "@type": "blah.com/` + dynamicMessageName + `", "foo": "bar", "baz": [0, 1, 2, 3] }`
|
||||
var got anypb.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 anypb.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)
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
33
vendor/github.com/golang/protobuf/jsonpb/jsonpb_test_proto/Makefile
generated
vendored
33
vendor/github.com/golang/protobuf/jsonpb/jsonpb_test_proto/Makefile
generated
vendored
@ -1,33 +0,0 @@
|
||||
# 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 --go_out=Mgoogle/protobuf/any.proto=github.com/golang/protobuf/ptypes/any,Mgoogle/protobuf/duration.proto=github.com/golang/protobuf/ptypes/duration,Mgoogle/protobuf/struct.proto=github.com/golang/protobuf/ptypes/struct,Mgoogle/protobuf/timestamp.proto=github.com/golang/protobuf/ptypes/timestamp,Mgoogle/protobuf/wrappers.proto=github.com/golang/protobuf/ptypes/wrappers:. *.proto
|
266
vendor/github.com/golang/protobuf/jsonpb/jsonpb_test_proto/more_test_objects.pb.go
generated
vendored
266
vendor/github.com/golang/protobuf/jsonpb/jsonpb_test_proto/more_test_objects.pb.go
generated
vendored
@ -1,266 +0,0 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: more_test_objects.proto
|
||||
|
||||
/*
|
||||
Package jsonpb is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
more_test_objects.proto
|
||||
test_objects.proto
|
||||
|
||||
It has these top-level messages:
|
||||
Simple3
|
||||
SimpleSlice3
|
||||
SimpleMap3
|
||||
SimpleNull3
|
||||
Mappy
|
||||
Simple
|
||||
NonFinites
|
||||
Repeats
|
||||
Widget
|
||||
Maps
|
||||
MsgWithOneof
|
||||
Real
|
||||
Complex
|
||||
KnownTypes
|
||||
*/
|
||||
package jsonpb
|
||||
|
||||
import proto "github.com/golang/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.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
type Numeral int32
|
||||
|
||||
const (
|
||||
Numeral_UNKNOWN Numeral = 0
|
||||
Numeral_ARABIC Numeral = 1
|
||||
Numeral_ROMAN Numeral = 2
|
||||
)
|
||||
|
||||
var Numeral_name = map[int32]string{
|
||||
0: "UNKNOWN",
|
||||
1: "ARABIC",
|
||||
2: "ROMAN",
|
||||
}
|
||||
var Numeral_value = map[string]int32{
|
||||
"UNKNOWN": 0,
|
||||
"ARABIC": 1,
|
||||
"ROMAN": 2,
|
||||
}
|
||||
|
||||
func (x Numeral) String() string {
|
||||
return proto.EnumName(Numeral_name, int32(x))
|
||||
}
|
||||
func (Numeral) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
||||
|
||||
type Simple3 struct {
|
||||
Dub float64 `protobuf:"fixed64,1,opt,name=dub" json:"dub,omitempty"`
|
||||
}
|
||||
|
||||
func (m *Simple3) Reset() { *m = Simple3{} }
|
||||
func (m *Simple3) String() string { return proto.CompactTextString(m) }
|
||||
func (*Simple3) ProtoMessage() {}
|
||||
func (*Simple3) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
||||
|
||||
func (m *Simple3) GetDub() float64 {
|
||||
if m != nil {
|
||||
return m.Dub
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type SimpleSlice3 struct {
|
||||
Slices []string `protobuf:"bytes,1,rep,name=slices" json:"slices,omitempty"`
|
||||
}
|
||||
|
||||
func (m *SimpleSlice3) Reset() { *m = SimpleSlice3{} }
|
||||
func (m *SimpleSlice3) String() string { return proto.CompactTextString(m) }
|
||||
func (*SimpleSlice3) ProtoMessage() {}
|
||||
func (*SimpleSlice3) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
|
||||
|
||||
func (m *SimpleSlice3) GetSlices() []string {
|
||||
if m != nil {
|
||||
return m.Slices
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type SimpleMap3 struct {
|
||||
Stringy map[string]string `protobuf:"bytes,1,rep,name=stringy" json:"stringy,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
|
||||
}
|
||||
|
||||
func (m *SimpleMap3) Reset() { *m = SimpleMap3{} }
|
||||
func (m *SimpleMap3) String() string { return proto.CompactTextString(m) }
|
||||
func (*SimpleMap3) ProtoMessage() {}
|
||||
func (*SimpleMap3) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
|
||||
|
||||
func (m *SimpleMap3) GetStringy() map[string]string {
|
||||
if m != nil {
|
||||
return m.Stringy
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type SimpleNull3 struct {
|
||||
Simple *Simple3 `protobuf:"bytes,1,opt,name=simple" json:"simple,omitempty"`
|
||||
}
|
||||
|
||||
func (m *SimpleNull3) Reset() { *m = SimpleNull3{} }
|
||||
func (m *SimpleNull3) String() string { return proto.CompactTextString(m) }
|
||||
func (*SimpleNull3) ProtoMessage() {}
|
||||
func (*SimpleNull3) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
|
||||
|
||||
func (m *SimpleNull3) GetSimple() *Simple3 {
|
||||
if m != nil {
|
||||
return m.Simple
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Mappy struct {
|
||||
Nummy map[int64]int32 `protobuf:"bytes,1,rep,name=nummy" json:"nummy,omitempty" protobuf_key:"varint,1,opt,name=key" protobuf_val:"varint,2,opt,name=value"`
|
||||
Strry map[string]string `protobuf:"bytes,2,rep,name=strry" json:"strry,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
|
||||
Objjy map[int32]*Simple3 `protobuf:"bytes,3,rep,name=objjy" json:"objjy,omitempty" protobuf_key:"varint,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
|
||||
Buggy map[int64]string `protobuf:"bytes,4,rep,name=buggy" json:"buggy,omitempty" protobuf_key:"varint,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
|
||||
Booly map[bool]bool `protobuf:"bytes,5,rep,name=booly" json:"booly,omitempty" protobuf_key:"varint,1,opt,name=key" protobuf_val:"varint,2,opt,name=value"`
|
||||
Enumy map[string]Numeral `protobuf:"bytes,6,rep,name=enumy" json:"enumy,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"varint,2,opt,name=value,enum=jsonpb.Numeral"`
|
||||
S32Booly map[int32]bool `protobuf:"bytes,7,rep,name=s32booly" json:"s32booly,omitempty" protobuf_key:"varint,1,opt,name=key" protobuf_val:"varint,2,opt,name=value"`
|
||||
S64Booly map[int64]bool `protobuf:"bytes,8,rep,name=s64booly" json:"s64booly,omitempty" protobuf_key:"varint,1,opt,name=key" protobuf_val:"varint,2,opt,name=value"`
|
||||
U32Booly map[uint32]bool `protobuf:"bytes,9,rep,name=u32booly" json:"u32booly,omitempty" protobuf_key:"varint,1,opt,name=key" protobuf_val:"varint,2,opt,name=value"`
|
||||
U64Booly map[uint64]bool `protobuf:"bytes,10,rep,name=u64booly" json:"u64booly,omitempty" protobuf_key:"varint,1,opt,name=key" protobuf_val:"varint,2,opt,name=value"`
|
||||
}
|
||||
|
||||
func (m *Mappy) Reset() { *m = Mappy{} }
|
||||
func (m *Mappy) String() string { return proto.CompactTextString(m) }
|
||||
func (*Mappy) ProtoMessage() {}
|
||||
func (*Mappy) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} }
|
||||
|
||||
func (m *Mappy) GetNummy() map[int64]int32 {
|
||||
if m != nil {
|
||||
return m.Nummy
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Mappy) GetStrry() map[string]string {
|
||||
if m != nil {
|
||||
return m.Strry
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Mappy) GetObjjy() map[int32]*Simple3 {
|
||||
if m != nil {
|
||||
return m.Objjy
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Mappy) GetBuggy() map[int64]string {
|
||||
if m != nil {
|
||||
return m.Buggy
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Mappy) GetBooly() map[bool]bool {
|
||||
if m != nil {
|
||||
return m.Booly
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Mappy) GetEnumy() map[string]Numeral {
|
||||
if m != nil {
|
||||
return m.Enumy
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Mappy) GetS32Booly() map[int32]bool {
|
||||
if m != nil {
|
||||
return m.S32Booly
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Mappy) GetS64Booly() map[int64]bool {
|
||||
if m != nil {
|
||||
return m.S64Booly
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Mappy) GetU32Booly() map[uint32]bool {
|
||||
if m != nil {
|
||||
return m.U32Booly
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Mappy) GetU64Booly() map[uint64]bool {
|
||||
if m != nil {
|
||||
return m.U64Booly
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*Simple3)(nil), "jsonpb.Simple3")
|
||||
proto.RegisterType((*SimpleSlice3)(nil), "jsonpb.SimpleSlice3")
|
||||
proto.RegisterType((*SimpleMap3)(nil), "jsonpb.SimpleMap3")
|
||||
proto.RegisterType((*SimpleNull3)(nil), "jsonpb.SimpleNull3")
|
||||
proto.RegisterType((*Mappy)(nil), "jsonpb.Mappy")
|
||||
proto.RegisterEnum("jsonpb.Numeral", Numeral_name, Numeral_value)
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("more_test_objects.proto", fileDescriptor0) }
|
||||
|
||||
var fileDescriptor0 = []byte{
|
||||
// 526 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x94, 0xdd, 0x6b, 0xdb, 0x3c,
|
||||
0x14, 0x87, 0x5f, 0x27, 0xf5, 0xd7, 0x49, 0xfb, 0x2e, 0x88, 0xb1, 0x99, 0xf4, 0x62, 0xc5, 0xb0,
|
||||
0xad, 0x0c, 0xe6, 0x8b, 0x78, 0x74, 0x5d, 0x77, 0x95, 0x8e, 0x5e, 0x94, 0x11, 0x07, 0x1c, 0xc2,
|
||||
0x2e, 0x4b, 0xdc, 0x99, 0x90, 0xcc, 0x5f, 0xd8, 0xd6, 0xc0, 0xd7, 0xfb, 0xbb, 0x07, 0xe3, 0x48,
|
||||
0x72, 0x2d, 0x07, 0x85, 0x6c, 0x77, 0x52, 0x7e, 0xcf, 0xe3, 0x73, 0x24, 0x1d, 0x02, 0x2f, 0xd3,
|
||||
0xbc, 0x8c, 0x1f, 0xea, 0xb8, 0xaa, 0x1f, 0xf2, 0x68, 0x17, 0x3f, 0xd6, 0x95, 0x57, 0x94, 0x79,
|
||||
0x9d, 0x13, 0x63, 0x57, 0xe5, 0x59, 0x11, 0xb9, 0xe7, 0x60, 0x2e, 0xb7, 0x69, 0x91, 0xc4, 0x3e,
|
||||
0x19, 0xc3, 0xf0, 0x3b, 0x8d, 0x1c, 0xed, 0x42, 0xbb, 0xd4, 0x42, 0x5c, 0xba, 0x6f, 0xe0, 0x94,
|
||||
0x87, 0xcb, 0x64, 0xfb, 0x18, 0xfb, 0xe4, 0x05, 0x18, 0x15, 0xae, 0x2a, 0x47, 0xbb, 0x18, 0x5e,
|
||||
0xda, 0xa1, 0xd8, 0xb9, 0xbf, 0x34, 0x00, 0x0e, 0xce, 0xd7, 0x85, 0x4f, 0x3e, 0x81, 0x59, 0xd5,
|
||||
0xe5, 0x36, 0xdb, 0x34, 0x8c, 0x1b, 0x4d, 0x5f, 0x79, 0xbc, 0x9a, 0xd7, 0x41, 0xde, 0x92, 0x13,
|
||||
0x77, 0x59, 0x5d, 0x36, 0x61, 0xcb, 0x4f, 0x6e, 0xe0, 0x54, 0x0e, 0xb0, 0xa7, 0x1f, 0x71, 0xc3,
|
||||
0x7a, 0xb2, 0x43, 0x5c, 0x92, 0xe7, 0xa0, 0xff, 0x5c, 0x27, 0x34, 0x76, 0x06, 0xec, 0x37, 0xbe,
|
||||
0xb9, 0x19, 0x5c, 0x6b, 0xee, 0x15, 0x8c, 0xf8, 0xf7, 0x03, 0x9a, 0x24, 0x3e, 0x79, 0x0b, 0x46,
|
||||
0xc5, 0xb6, 0xcc, 0x1e, 0x4d, 0x9f, 0xf5, 0x9b, 0xf0, 0x43, 0x11, 0xbb, 0xbf, 0x2d, 0xd0, 0xe7,
|
||||
0xeb, 0xa2, 0x68, 0x88, 0x07, 0x7a, 0x46, 0xd3, 0xb4, 0x6d, 0xdb, 0x69, 0x0d, 0x96, 0x7a, 0x01,
|
||||
0x46, 0xbc, 0x5f, 0x8e, 0x21, 0x5f, 0xd5, 0x65, 0xd9, 0x38, 0x03, 0x15, 0xbf, 0xc4, 0x48, 0xf0,
|
||||
0x0c, 0x43, 0x3e, 0x8f, 0x76, 0xbb, 0xc6, 0x19, 0xaa, 0xf8, 0x05, 0x46, 0x82, 0x67, 0x18, 0xf2,
|
||||
0x11, 0xdd, 0x6c, 0x1a, 0xe7, 0x44, 0xc5, 0xdf, 0x62, 0x24, 0x78, 0x86, 0x31, 0x3e, 0xcf, 0x93,
|
||||
0xc6, 0xd1, 0x95, 0x3c, 0x46, 0x2d, 0x8f, 0x6b, 0xe4, 0xe3, 0x8c, 0xa6, 0x8d, 0x63, 0xa8, 0xf8,
|
||||
0x3b, 0x8c, 0x04, 0xcf, 0x30, 0xf2, 0x11, 0xac, 0xca, 0x9f, 0xf2, 0x12, 0x26, 0x53, 0xce, 0xf7,
|
||||
0x8e, 0x2c, 0x52, 0x6e, 0x3d, 0xc1, 0x4c, 0xbc, 0xfa, 0xc0, 0x45, 0x4b, 0x29, 0x8a, 0xb4, 0x15,
|
||||
0xc5, 0x16, 0x45, 0xda, 0x56, 0xb4, 0x55, 0xe2, 0xaa, 0x5f, 0x91, 0x4a, 0x15, 0x69, 0x5b, 0x11,
|
||||
0x94, 0x62, 0xbf, 0x62, 0x0b, 0x4f, 0xae, 0x01, 0xba, 0x87, 0x96, 0xe7, 0x6f, 0xa8, 0x98, 0x3f,
|
||||
0x5d, 0x9a, 0x3f, 0x34, 0xbb, 0x27, 0xff, 0x97, 0xc9, 0x9d, 0xdc, 0x03, 0x74, 0x8f, 0x2f, 0x9b,
|
||||
0x3a, 0x37, 0x5f, 0xcb, 0xa6, 0x62, 0x92, 0xfb, 0x4d, 0x74, 0x73, 0x71, 0xac, 0x7d, 0x7b, 0xdf,
|
||||
0x7c, 0xba, 0x10, 0xd9, 0xb4, 0x14, 0xa6, 0xb5, 0xd7, 0x7e, 0x37, 0x2b, 0x8a, 0x83, 0xf7, 0xda,
|
||||
0xff, 0xbf, 0x6b, 0x3f, 0xa0, 0x69, 0x5c, 0xae, 0x13, 0xf9, 0x53, 0x9f, 0xe1, 0xac, 0x37, 0x43,
|
||||
0x8a, 0xcb, 0x38, 0xdc, 0x07, 0xca, 0xf2, 0xab, 0x1e, 0x3b, 0xfe, 0xbe, 0xbc, 0x3a, 0x54, 0xf9,
|
||||
0xec, 0x6f, 0xe4, 0x43, 0x95, 0x4f, 0x8e, 0xc8, 0xef, 0xde, 0x83, 0x29, 0x6e, 0x82, 0x8c, 0xc0,
|
||||
0x5c, 0x05, 0x5f, 0x83, 0xc5, 0xb7, 0x60, 0xfc, 0x1f, 0x01, 0x30, 0x66, 0xe1, 0xec, 0xf6, 0xfe,
|
||||
0xcb, 0x58, 0x23, 0x36, 0xe8, 0xe1, 0x62, 0x3e, 0x0b, 0xc6, 0x83, 0xc8, 0x60, 0x7f, 0xe0, 0xfe,
|
||||
0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xdc, 0x84, 0x34, 0xaf, 0xdb, 0x05, 0x00, 0x00,
|
||||
}
|
852
vendor/github.com/golang/protobuf/jsonpb/jsonpb_test_proto/test_objects.pb.go
generated
vendored
852
vendor/github.com/golang/protobuf/jsonpb/jsonpb_test_proto/test_objects.pb.go
generated
vendored
@ -1,852 +0,0 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: test_objects.proto
|
||||
|
||||
package jsonpb
|
||||
|
||||
import proto "github.com/golang/protobuf/proto"
|
||||
import fmt "fmt"
|
||||
import math "math"
|
||||
import google_protobuf "github.com/golang/protobuf/ptypes/any"
|
||||
import google_protobuf1 "github.com/golang/protobuf/ptypes/duration"
|
||||
import google_protobuf2 "github.com/golang/protobuf/ptypes/struct"
|
||||
import google_protobuf3 "github.com/golang/protobuf/ptypes/timestamp"
|
||||
import google_protobuf4 "github.com/golang/protobuf/ptypes/wrappers"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
type Widget_Color int32
|
||||
|
||||
const (
|
||||
Widget_RED Widget_Color = 0
|
||||
Widget_GREEN Widget_Color = 1
|
||||
Widget_BLUE Widget_Color = 2
|
||||
)
|
||||
|
||||
var Widget_Color_name = map[int32]string{
|
||||
0: "RED",
|
||||
1: "GREEN",
|
||||
2: "BLUE",
|
||||
}
|
||||
var Widget_Color_value = map[string]int32{
|
||||
"RED": 0,
|
||||
"GREEN": 1,
|
||||
"BLUE": 2,
|
||||
}
|
||||
|
||||
func (x Widget_Color) Enum() *Widget_Color {
|
||||
p := new(Widget_Color)
|
||||
*p = x
|
||||
return p
|
||||
}
|
||||
func (x Widget_Color) String() string {
|
||||
return proto.EnumName(Widget_Color_name, int32(x))
|
||||
}
|
||||
func (x *Widget_Color) UnmarshalJSON(data []byte) error {
|
||||
value, err := proto.UnmarshalJSONEnum(Widget_Color_value, data, "Widget_Color")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*x = Widget_Color(value)
|
||||
return nil
|
||||
}
|
||||
func (Widget_Color) EnumDescriptor() ([]byte, []int) { return fileDescriptor1, []int{3, 0} }
|
||||
|
||||
// Test message for holding primitive types.
|
||||
type Simple struct {
|
||||
OBool *bool `protobuf:"varint,1,opt,name=o_bool,json=oBool" json:"o_bool,omitempty"`
|
||||
OInt32 *int32 `protobuf:"varint,2,opt,name=o_int32,json=oInt32" json:"o_int32,omitempty"`
|
||||
OInt64 *int64 `protobuf:"varint,3,opt,name=o_int64,json=oInt64" json:"o_int64,omitempty"`
|
||||
OUint32 *uint32 `protobuf:"varint,4,opt,name=o_uint32,json=oUint32" json:"o_uint32,omitempty"`
|
||||
OUint64 *uint64 `protobuf:"varint,5,opt,name=o_uint64,json=oUint64" json:"o_uint64,omitempty"`
|
||||
OSint32 *int32 `protobuf:"zigzag32,6,opt,name=o_sint32,json=oSint32" json:"o_sint32,omitempty"`
|
||||
OSint64 *int64 `protobuf:"zigzag64,7,opt,name=o_sint64,json=oSint64" json:"o_sint64,omitempty"`
|
||||
OFloat *float32 `protobuf:"fixed32,8,opt,name=o_float,json=oFloat" json:"o_float,omitempty"`
|
||||
ODouble *float64 `protobuf:"fixed64,9,opt,name=o_double,json=oDouble" json:"o_double,omitempty"`
|
||||
OString *string `protobuf:"bytes,10,opt,name=o_string,json=oString" json:"o_string,omitempty"`
|
||||
OBytes []byte `protobuf:"bytes,11,opt,name=o_bytes,json=oBytes" json:"o_bytes,omitempty"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Simple) Reset() { *m = Simple{} }
|
||||
func (m *Simple) String() string { return proto.CompactTextString(m) }
|
||||
func (*Simple) ProtoMessage() {}
|
||||
func (*Simple) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{0} }
|
||||
|
||||
func (m *Simple) GetOBool() bool {
|
||||
if m != nil && m.OBool != nil {
|
||||
return *m.OBool
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (m *Simple) GetOInt32() int32 {
|
||||
if m != nil && m.OInt32 != nil {
|
||||
return *m.OInt32
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *Simple) GetOInt64() int64 {
|
||||
if m != nil && m.OInt64 != nil {
|
||||
return *m.OInt64
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *Simple) GetOUint32() uint32 {
|
||||
if m != nil && m.OUint32 != nil {
|
||||
return *m.OUint32
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *Simple) GetOUint64() uint64 {
|
||||
if m != nil && m.OUint64 != nil {
|
||||
return *m.OUint64
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *Simple) GetOSint32() int32 {
|
||||
if m != nil && m.OSint32 != nil {
|
||||
return *m.OSint32
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *Simple) GetOSint64() int64 {
|
||||
if m != nil && m.OSint64 != nil {
|
||||
return *m.OSint64
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *Simple) GetOFloat() float32 {
|
||||
if m != nil && m.OFloat != nil {
|
||||
return *m.OFloat
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *Simple) GetODouble() float64 {
|
||||
if m != nil && m.ODouble != nil {
|
||||
return *m.ODouble
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *Simple) GetOString() string {
|
||||
if m != nil && m.OString != nil {
|
||||
return *m.OString
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *Simple) GetOBytes() []byte {
|
||||
if m != nil {
|
||||
return m.OBytes
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Test message for holding special non-finites primitives.
|
||||
type NonFinites struct {
|
||||
FNan *float32 `protobuf:"fixed32,1,opt,name=f_nan,json=fNan" json:"f_nan,omitempty"`
|
||||
FPinf *float32 `protobuf:"fixed32,2,opt,name=f_pinf,json=fPinf" json:"f_pinf,omitempty"`
|
||||
FNinf *float32 `protobuf:"fixed32,3,opt,name=f_ninf,json=fNinf" json:"f_ninf,omitempty"`
|
||||
DNan *float64 `protobuf:"fixed64,4,opt,name=d_nan,json=dNan" json:"d_nan,omitempty"`
|
||||
DPinf *float64 `protobuf:"fixed64,5,opt,name=d_pinf,json=dPinf" json:"d_pinf,omitempty"`
|
||||
DNinf *float64 `protobuf:"fixed64,6,opt,name=d_ninf,json=dNinf" json:"d_ninf,omitempty"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (m *NonFinites) Reset() { *m = NonFinites{} }
|
||||
func (m *NonFinites) String() string { return proto.CompactTextString(m) }
|
||||
func (*NonFinites) ProtoMessage() {}
|
||||
func (*NonFinites) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{1} }
|
||||
|
||||
func (m *NonFinites) GetFNan() float32 {
|
||||
if m != nil && m.FNan != nil {
|
||||
return *m.FNan
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *NonFinites) GetFPinf() float32 {
|
||||
if m != nil && m.FPinf != nil {
|
||||
return *m.FPinf
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *NonFinites) GetFNinf() float32 {
|
||||
if m != nil && m.FNinf != nil {
|
||||
return *m.FNinf
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *NonFinites) GetDNan() float64 {
|
||||
if m != nil && m.DNan != nil {
|
||||
return *m.DNan
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *NonFinites) GetDPinf() float64 {
|
||||
if m != nil && m.DPinf != nil {
|
||||
return *m.DPinf
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *NonFinites) GetDNinf() float64 {
|
||||
if m != nil && m.DNinf != nil {
|
||||
return *m.DNinf
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// Test message for holding repeated primitives.
|
||||
type Repeats struct {
|
||||
RBool []bool `protobuf:"varint,1,rep,name=r_bool,json=rBool" json:"r_bool,omitempty"`
|
||||
RInt32 []int32 `protobuf:"varint,2,rep,name=r_int32,json=rInt32" json:"r_int32,omitempty"`
|
||||
RInt64 []int64 `protobuf:"varint,3,rep,name=r_int64,json=rInt64" json:"r_int64,omitempty"`
|
||||
RUint32 []uint32 `protobuf:"varint,4,rep,name=r_uint32,json=rUint32" json:"r_uint32,omitempty"`
|
||||
RUint64 []uint64 `protobuf:"varint,5,rep,name=r_uint64,json=rUint64" json:"r_uint64,omitempty"`
|
||||
RSint32 []int32 `protobuf:"zigzag32,6,rep,name=r_sint32,json=rSint32" json:"r_sint32,omitempty"`
|
||||
RSint64 []int64 `protobuf:"zigzag64,7,rep,name=r_sint64,json=rSint64" json:"r_sint64,omitempty"`
|
||||
RFloat []float32 `protobuf:"fixed32,8,rep,name=r_float,json=rFloat" json:"r_float,omitempty"`
|
||||
RDouble []float64 `protobuf:"fixed64,9,rep,name=r_double,json=rDouble" json:"r_double,omitempty"`
|
||||
RString []string `protobuf:"bytes,10,rep,name=r_string,json=rString" json:"r_string,omitempty"`
|
||||
RBytes [][]byte `protobuf:"bytes,11,rep,name=r_bytes,json=rBytes" json:"r_bytes,omitempty"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Repeats) Reset() { *m = Repeats{} }
|
||||
func (m *Repeats) String() string { return proto.CompactTextString(m) }
|
||||
func (*Repeats) ProtoMessage() {}
|
||||
func (*Repeats) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{2} }
|
||||
|
||||
func (m *Repeats) GetRBool() []bool {
|
||||
if m != nil {
|
||||
return m.RBool
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Repeats) GetRInt32() []int32 {
|
||||
if m != nil {
|
||||
return m.RInt32
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Repeats) GetRInt64() []int64 {
|
||||
if m != nil {
|
||||
return m.RInt64
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Repeats) GetRUint32() []uint32 {
|
||||
if m != nil {
|
||||
return m.RUint32
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Repeats) GetRUint64() []uint64 {
|
||||
if m != nil {
|
||||
return m.RUint64
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Repeats) GetRSint32() []int32 {
|
||||
if m != nil {
|
||||
return m.RSint32
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Repeats) GetRSint64() []int64 {
|
||||
if m != nil {
|
||||
return m.RSint64
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Repeats) GetRFloat() []float32 {
|
||||
if m != nil {
|
||||
return m.RFloat
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Repeats) GetRDouble() []float64 {
|
||||
if m != nil {
|
||||
return m.RDouble
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Repeats) GetRString() []string {
|
||||
if m != nil {
|
||||
return m.RString
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Repeats) GetRBytes() [][]byte {
|
||||
if m != nil {
|
||||
return m.RBytes
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Test message for holding enums and nested messages.
|
||||
type Widget struct {
|
||||
Color *Widget_Color `protobuf:"varint,1,opt,name=color,enum=jsonpb.Widget_Color" json:"color,omitempty"`
|
||||
RColor []Widget_Color `protobuf:"varint,2,rep,name=r_color,json=rColor,enum=jsonpb.Widget_Color" json:"r_color,omitempty"`
|
||||
Simple *Simple `protobuf:"bytes,10,opt,name=simple" json:"simple,omitempty"`
|
||||
RSimple []*Simple `protobuf:"bytes,11,rep,name=r_simple,json=rSimple" json:"r_simple,omitempty"`
|
||||
Repeats *Repeats `protobuf:"bytes,20,opt,name=repeats" json:"repeats,omitempty"`
|
||||
RRepeats []*Repeats `protobuf:"bytes,21,rep,name=r_repeats,json=rRepeats" json:"r_repeats,omitempty"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Widget) Reset() { *m = Widget{} }
|
||||
func (m *Widget) String() string { return proto.CompactTextString(m) }
|
||||
func (*Widget) ProtoMessage() {}
|
||||
func (*Widget) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{3} }
|
||||
|
||||
func (m *Widget) GetColor() Widget_Color {
|
||||
if m != nil && m.Color != nil {
|
||||
return *m.Color
|
||||
}
|
||||
return Widget_RED
|
||||
}
|
||||
|
||||
func (m *Widget) GetRColor() []Widget_Color {
|
||||
if m != nil {
|
||||
return m.RColor
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Widget) GetSimple() *Simple {
|
||||
if m != nil {
|
||||
return m.Simple
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Widget) GetRSimple() []*Simple {
|
||||
if m != nil {
|
||||
return m.RSimple
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Widget) GetRepeats() *Repeats {
|
||||
if m != nil {
|
||||
return m.Repeats
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Widget) GetRRepeats() []*Repeats {
|
||||
if m != nil {
|
||||
return m.RRepeats
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Maps struct {
|
||||
MInt64Str map[int64]string `protobuf:"bytes,1,rep,name=m_int64_str,json=mInt64Str" json:"m_int64_str,omitempty" protobuf_key:"varint,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
|
||||
MBoolSimple map[bool]*Simple `protobuf:"bytes,2,rep,name=m_bool_simple,json=mBoolSimple" json:"m_bool_simple,omitempty" protobuf_key:"varint,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Maps) Reset() { *m = Maps{} }
|
||||
func (m *Maps) String() string { return proto.CompactTextString(m) }
|
||||
func (*Maps) ProtoMessage() {}
|
||||
func (*Maps) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{4} }
|
||||
|
||||
func (m *Maps) GetMInt64Str() map[int64]string {
|
||||
if m != nil {
|
||||
return m.MInt64Str
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Maps) GetMBoolSimple() map[bool]*Simple {
|
||||
if m != nil {
|
||||
return m.MBoolSimple
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type MsgWithOneof struct {
|
||||
// Types that are valid to be assigned to Union:
|
||||
// *MsgWithOneof_Title
|
||||
// *MsgWithOneof_Salary
|
||||
// *MsgWithOneof_Country
|
||||
// *MsgWithOneof_HomeAddress
|
||||
Union isMsgWithOneof_Union `protobuf_oneof:"union"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (m *MsgWithOneof) Reset() { *m = MsgWithOneof{} }
|
||||
func (m *MsgWithOneof) String() string { return proto.CompactTextString(m) }
|
||||
func (*MsgWithOneof) ProtoMessage() {}
|
||||
func (*MsgWithOneof) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{5} }
|
||||
|
||||
type isMsgWithOneof_Union interface {
|
||||
isMsgWithOneof_Union()
|
||||
}
|
||||
|
||||
type MsgWithOneof_Title struct {
|
||||
Title string `protobuf:"bytes,1,opt,name=title,oneof"`
|
||||
}
|
||||
type MsgWithOneof_Salary struct {
|
||||
Salary int64 `protobuf:"varint,2,opt,name=salary,oneof"`
|
||||
}
|
||||
type MsgWithOneof_Country struct {
|
||||
Country string `protobuf:"bytes,3,opt,name=Country,oneof"`
|
||||
}
|
||||
type MsgWithOneof_HomeAddress struct {
|
||||
HomeAddress string `protobuf:"bytes,4,opt,name=home_address,json=homeAddress,oneof"`
|
||||
}
|
||||
|
||||
func (*MsgWithOneof_Title) isMsgWithOneof_Union() {}
|
||||
func (*MsgWithOneof_Salary) isMsgWithOneof_Union() {}
|
||||
func (*MsgWithOneof_Country) isMsgWithOneof_Union() {}
|
||||
func (*MsgWithOneof_HomeAddress) isMsgWithOneof_Union() {}
|
||||
|
||||
func (m *MsgWithOneof) GetUnion() isMsgWithOneof_Union {
|
||||
if m != nil {
|
||||
return m.Union
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MsgWithOneof) GetTitle() string {
|
||||
if x, ok := m.GetUnion().(*MsgWithOneof_Title); ok {
|
||||
return x.Title
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *MsgWithOneof) GetSalary() int64 {
|
||||
if x, ok := m.GetUnion().(*MsgWithOneof_Salary); ok {
|
||||
return x.Salary
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *MsgWithOneof) GetCountry() string {
|
||||
if x, ok := m.GetUnion().(*MsgWithOneof_Country); ok {
|
||||
return x.Country
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *MsgWithOneof) GetHomeAddress() string {
|
||||
if x, ok := m.GetUnion().(*MsgWithOneof_HomeAddress); ok {
|
||||
return x.HomeAddress
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// XXX_OneofFuncs is for the internal use of the proto package.
|
||||
func (*MsgWithOneof) 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 _MsgWithOneof_OneofMarshaler, _MsgWithOneof_OneofUnmarshaler, _MsgWithOneof_OneofSizer, []interface{}{
|
||||
(*MsgWithOneof_Title)(nil),
|
||||
(*MsgWithOneof_Salary)(nil),
|
||||
(*MsgWithOneof_Country)(nil),
|
||||
(*MsgWithOneof_HomeAddress)(nil),
|
||||
}
|
||||
}
|
||||
|
||||
func _MsgWithOneof_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
|
||||
m := msg.(*MsgWithOneof)
|
||||
// union
|
||||
switch x := m.Union.(type) {
|
||||
case *MsgWithOneof_Title:
|
||||
b.EncodeVarint(1<<3 | proto.WireBytes)
|
||||
b.EncodeStringBytes(x.Title)
|
||||
case *MsgWithOneof_Salary:
|
||||
b.EncodeVarint(2<<3 | proto.WireVarint)
|
||||
b.EncodeVarint(uint64(x.Salary))
|
||||
case *MsgWithOneof_Country:
|
||||
b.EncodeVarint(3<<3 | proto.WireBytes)
|
||||
b.EncodeStringBytes(x.Country)
|
||||
case *MsgWithOneof_HomeAddress:
|
||||
b.EncodeVarint(4<<3 | proto.WireBytes)
|
||||
b.EncodeStringBytes(x.HomeAddress)
|
||||
case nil:
|
||||
default:
|
||||
return fmt.Errorf("MsgWithOneof.Union has unexpected type %T", x)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func _MsgWithOneof_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
|
||||
m := msg.(*MsgWithOneof)
|
||||
switch tag {
|
||||
case 1: // union.title
|
||||
if wire != proto.WireBytes {
|
||||
return true, proto.ErrInternalBadWireType
|
||||
}
|
||||
x, err := b.DecodeStringBytes()
|
||||
m.Union = &MsgWithOneof_Title{x}
|
||||
return true, err
|
||||
case 2: // union.salary
|
||||
if wire != proto.WireVarint {
|
||||
return true, proto.ErrInternalBadWireType
|
||||
}
|
||||
x, err := b.DecodeVarint()
|
||||
m.Union = &MsgWithOneof_Salary{int64(x)}
|
||||
return true, err
|
||||
case 3: // union.Country
|
||||
if wire != proto.WireBytes {
|
||||
return true, proto.ErrInternalBadWireType
|
||||
}
|
||||
x, err := b.DecodeStringBytes()
|
||||
m.Union = &MsgWithOneof_Country{x}
|
||||
return true, err
|
||||
case 4: // union.home_address
|
||||
if wire != proto.WireBytes {
|
||||
return true, proto.ErrInternalBadWireType
|
||||
}
|
||||
x, err := b.DecodeStringBytes()
|
||||
m.Union = &MsgWithOneof_HomeAddress{x}
|
||||
return true, err
|
||||
default:
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
func _MsgWithOneof_OneofSizer(msg proto.Message) (n int) {
|
||||
m := msg.(*MsgWithOneof)
|
||||
// union
|
||||
switch x := m.Union.(type) {
|
||||
case *MsgWithOneof_Title:
|
||||
n += proto.SizeVarint(1<<3 | proto.WireBytes)
|
||||
n += proto.SizeVarint(uint64(len(x.Title)))
|
||||
n += len(x.Title)
|
||||
case *MsgWithOneof_Salary:
|
||||
n += proto.SizeVarint(2<<3 | proto.WireVarint)
|
||||
n += proto.SizeVarint(uint64(x.Salary))
|
||||
case *MsgWithOneof_Country:
|
||||
n += proto.SizeVarint(3<<3 | proto.WireBytes)
|
||||
n += proto.SizeVarint(uint64(len(x.Country)))
|
||||
n += len(x.Country)
|
||||
case *MsgWithOneof_HomeAddress:
|
||||
n += proto.SizeVarint(4<<3 | proto.WireBytes)
|
||||
n += proto.SizeVarint(uint64(len(x.HomeAddress)))
|
||||
n += len(x.HomeAddress)
|
||||
case nil:
|
||||
default:
|
||||
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
type Real struct {
|
||||
Value *float64 `protobuf:"fixed64,1,opt,name=value" json:"value,omitempty"`
|
||||
proto.XXX_InternalExtensions `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Real) Reset() { *m = Real{} }
|
||||
func (m *Real) String() string { return proto.CompactTextString(m) }
|
||||
func (*Real) ProtoMessage() {}
|
||||
func (*Real) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{6} }
|
||||
|
||||
var extRange_Real = []proto.ExtensionRange{
|
||||
{100, 536870911},
|
||||
}
|
||||
|
||||
func (*Real) ExtensionRangeArray() []proto.ExtensionRange {
|
||||
return extRange_Real
|
||||
}
|
||||
|
||||
func (m *Real) GetValue() float64 {
|
||||
if m != nil && m.Value != nil {
|
||||
return *m.Value
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type Complex struct {
|
||||
Imaginary *float64 `protobuf:"fixed64,1,opt,name=imaginary" json:"imaginary,omitempty"`
|
||||
proto.XXX_InternalExtensions `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Complex) Reset() { *m = Complex{} }
|
||||
func (m *Complex) String() string { return proto.CompactTextString(m) }
|
||||
func (*Complex) ProtoMessage() {}
|
||||
func (*Complex) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{7} }
|
||||
|
||||
var extRange_Complex = []proto.ExtensionRange{
|
||||
{100, 536870911},
|
||||
}
|
||||
|
||||
func (*Complex) ExtensionRangeArray() []proto.ExtensionRange {
|
||||
return extRange_Complex
|
||||
}
|
||||
|
||||
func (m *Complex) GetImaginary() float64 {
|
||||
if m != nil && m.Imaginary != nil {
|
||||
return *m.Imaginary
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
var E_Complex_RealExtension = &proto.ExtensionDesc{
|
||||
ExtendedType: (*Real)(nil),
|
||||
ExtensionType: (*Complex)(nil),
|
||||
Field: 123,
|
||||
Name: "jsonpb.Complex.real_extension",
|
||||
Tag: "bytes,123,opt,name=real_extension,json=realExtension",
|
||||
Filename: "test_objects.proto",
|
||||
}
|
||||
|
||||
type KnownTypes struct {
|
||||
An *google_protobuf.Any `protobuf:"bytes,14,opt,name=an" json:"an,omitempty"`
|
||||
Dur *google_protobuf1.Duration `protobuf:"bytes,1,opt,name=dur" json:"dur,omitempty"`
|
||||
St *google_protobuf2.Struct `protobuf:"bytes,12,opt,name=st" json:"st,omitempty"`
|
||||
Ts *google_protobuf3.Timestamp `protobuf:"bytes,2,opt,name=ts" json:"ts,omitempty"`
|
||||
Lv *google_protobuf2.ListValue `protobuf:"bytes,15,opt,name=lv" json:"lv,omitempty"`
|
||||
Val *google_protobuf2.Value `protobuf:"bytes,16,opt,name=val" json:"val,omitempty"`
|
||||
Dbl *google_protobuf4.DoubleValue `protobuf:"bytes,3,opt,name=dbl" json:"dbl,omitempty"`
|
||||
Flt *google_protobuf4.FloatValue `protobuf:"bytes,4,opt,name=flt" json:"flt,omitempty"`
|
||||
I64 *google_protobuf4.Int64Value `protobuf:"bytes,5,opt,name=i64" json:"i64,omitempty"`
|
||||
U64 *google_protobuf4.UInt64Value `protobuf:"bytes,6,opt,name=u64" json:"u64,omitempty"`
|
||||
I32 *google_protobuf4.Int32Value `protobuf:"bytes,7,opt,name=i32" json:"i32,omitempty"`
|
||||
U32 *google_protobuf4.UInt32Value `protobuf:"bytes,8,opt,name=u32" json:"u32,omitempty"`
|
||||
Bool *google_protobuf4.BoolValue `protobuf:"bytes,9,opt,name=bool" json:"bool,omitempty"`
|
||||
Str *google_protobuf4.StringValue `protobuf:"bytes,10,opt,name=str" json:"str,omitempty"`
|
||||
Bytes *google_protobuf4.BytesValue `protobuf:"bytes,11,opt,name=bytes" json:"bytes,omitempty"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (m *KnownTypes) Reset() { *m = KnownTypes{} }
|
||||
func (m *KnownTypes) String() string { return proto.CompactTextString(m) }
|
||||
func (*KnownTypes) ProtoMessage() {}
|
||||
func (*KnownTypes) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{8} }
|
||||
|
||||
func (m *KnownTypes) GetAn() *google_protobuf.Any {
|
||||
if m != nil {
|
||||
return m.An
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *KnownTypes) GetDur() *google_protobuf1.Duration {
|
||||
if m != nil {
|
||||
return m.Dur
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *KnownTypes) GetSt() *google_protobuf2.Struct {
|
||||
if m != nil {
|
||||
return m.St
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *KnownTypes) GetTs() *google_protobuf3.Timestamp {
|
||||
if m != nil {
|
||||
return m.Ts
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *KnownTypes) GetLv() *google_protobuf2.ListValue {
|
||||
if m != nil {
|
||||
return m.Lv
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *KnownTypes) GetVal() *google_protobuf2.Value {
|
||||
if m != nil {
|
||||
return m.Val
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *KnownTypes) GetDbl() *google_protobuf4.DoubleValue {
|
||||
if m != nil {
|
||||
return m.Dbl
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *KnownTypes) GetFlt() *google_protobuf4.FloatValue {
|
||||
if m != nil {
|
||||
return m.Flt
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *KnownTypes) GetI64() *google_protobuf4.Int64Value {
|
||||
if m != nil {
|
||||
return m.I64
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *KnownTypes) GetU64() *google_protobuf4.UInt64Value {
|
||||
if m != nil {
|
||||
return m.U64
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *KnownTypes) GetI32() *google_protobuf4.Int32Value {
|
||||
if m != nil {
|
||||
return m.I32
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *KnownTypes) GetU32() *google_protobuf4.UInt32Value {
|
||||
if m != nil {
|
||||
return m.U32
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *KnownTypes) GetBool() *google_protobuf4.BoolValue {
|
||||
if m != nil {
|
||||
return m.Bool
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *KnownTypes) GetStr() *google_protobuf4.StringValue {
|
||||
if m != nil {
|
||||
return m.Str
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *KnownTypes) GetBytes() *google_protobuf4.BytesValue {
|
||||
if m != nil {
|
||||
return m.Bytes
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var E_Name = &proto.ExtensionDesc{
|
||||
ExtendedType: (*Real)(nil),
|
||||
ExtensionType: (*string)(nil),
|
||||
Field: 124,
|
||||
Name: "jsonpb.name",
|
||||
Tag: "bytes,124,opt,name=name",
|
||||
Filename: "test_objects.proto",
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*Simple)(nil), "jsonpb.Simple")
|
||||
proto.RegisterType((*NonFinites)(nil), "jsonpb.NonFinites")
|
||||
proto.RegisterType((*Repeats)(nil), "jsonpb.Repeats")
|
||||
proto.RegisterType((*Widget)(nil), "jsonpb.Widget")
|
||||
proto.RegisterType((*Maps)(nil), "jsonpb.Maps")
|
||||
proto.RegisterType((*MsgWithOneof)(nil), "jsonpb.MsgWithOneof")
|
||||
proto.RegisterType((*Real)(nil), "jsonpb.Real")
|
||||
proto.RegisterType((*Complex)(nil), "jsonpb.Complex")
|
||||
proto.RegisterType((*KnownTypes)(nil), "jsonpb.KnownTypes")
|
||||
proto.RegisterEnum("jsonpb.Widget_Color", Widget_Color_name, Widget_Color_value)
|
||||
proto.RegisterExtension(E_Complex_RealExtension)
|
||||
proto.RegisterExtension(E_Name)
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("test_objects.proto", fileDescriptor1) }
|
||||
|
||||
var fileDescriptor1 = []byte{
|
||||
// 1160 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x95, 0x41, 0x73, 0xdb, 0x44,
|
||||
0x14, 0xc7, 0x23, 0xc9, 0x92, 0xed, 0x75, 0x92, 0x9a, 0x6d, 0xda, 0x2a, 0x26, 0x80, 0xc6, 0x94,
|
||||
0x22, 0x0a, 0x75, 0x07, 0xc7, 0xe3, 0x61, 0x0a, 0x97, 0xa4, 0x71, 0x29, 0x43, 0x13, 0x98, 0x4d,
|
||||
0x43, 0x8f, 0x1e, 0x39, 0x5a, 0xbb, 0x2a, 0xf2, 0xae, 0x67, 0x77, 0x95, 0xd4, 0x03, 0x87, 0x9c,
|
||||
0x39, 0x32, 0x7c, 0x05, 0xf8, 0x08, 0x1c, 0xf8, 0x74, 0xcc, 0xdb, 0x95, 0xac, 0xc4, 0x8e, 0x4f,
|
||||
0xf1, 0x7b, 0xef, 0xff, 0xfe, 0x59, 0xed, 0x6f, 0x77, 0x1f, 0xc2, 0x8a, 0x4a, 0x35, 0xe4, 0xa3,
|
||||
0x77, 0xf4, 0x5c, 0xc9, 0xce, 0x4c, 0x70, 0xc5, 0xb1, 0xf7, 0x4e, 0x72, 0x36, 0x1b, 0xb5, 0x76,
|
||||
0x27, 0x9c, 0x4f, 0x52, 0xfa, 0x54, 0x67, 0x47, 0xd9, 0xf8, 0x69, 0xc4, 0xe6, 0x46, 0xd2, 0xfa,
|
||||
0x78, 0xb9, 0x14, 0x67, 0x22, 0x52, 0x09, 0x67, 0x79, 0x7d, 0x6f, 0xb9, 0x2e, 0x95, 0xc8, 0xce,
|
||||
0x55, 0x5e, 0xfd, 0x64, 0xb9, 0xaa, 0x92, 0x29, 0x95, 0x2a, 0x9a, 0xce, 0xd6, 0xd9, 0x5f, 0x8a,
|
||||
0x68, 0x36, 0xa3, 0x22, 0x5f, 0x61, 0xfb, 0x6f, 0x1b, 0x79, 0xa7, 0xc9, 0x74, 0x96, 0x52, 0x7c,
|
||||
0x0f, 0x79, 0x7c, 0x38, 0xe2, 0x3c, 0xf5, 0xad, 0xc0, 0x0a, 0x6b, 0xc4, 0xe5, 0x87, 0x9c, 0xa7,
|
||||
0xf8, 0x01, 0xaa, 0xf2, 0x61, 0xc2, 0xd4, 0x7e, 0xd7, 0xb7, 0x03, 0x2b, 0x74, 0x89, 0xc7, 0x7f,
|
||||
0x80, 0x68, 0x51, 0xe8, 0xf7, 0x7c, 0x27, 0xb0, 0x42, 0xc7, 0x14, 0xfa, 0x3d, 0xbc, 0x8b, 0x6a,
|
||||
0x7c, 0x98, 0x99, 0x96, 0x4a, 0x60, 0x85, 0x5b, 0xa4, 0xca, 0xcf, 0x74, 0x58, 0x96, 0xfa, 0x3d,
|
||||
0xdf, 0x0d, 0xac, 0xb0, 0x92, 0x97, 0x8a, 0x2e, 0x69, 0xba, 0xbc, 0xc0, 0x0a, 0x3f, 0x20, 0x55,
|
||||
0x7e, 0x7a, 0xad, 0x4b, 0x9a, 0xae, 0x6a, 0x60, 0x85, 0x38, 0x2f, 0xf5, 0x7b, 0x66, 0x11, 0xe3,
|
||||
0x94, 0x47, 0xca, 0xaf, 0x05, 0x56, 0x68, 0x13, 0x8f, 0xbf, 0x80, 0xc8, 0xf4, 0xc4, 0x3c, 0x1b,
|
||||
0xa5, 0xd4, 0xaf, 0x07, 0x56, 0x68, 0x91, 0x2a, 0x3f, 0xd2, 0x61, 0x6e, 0xa7, 0x44, 0xc2, 0x26,
|
||||
0x3e, 0x0a, 0xac, 0xb0, 0x0e, 0x76, 0x3a, 0x34, 0x76, 0xa3, 0xb9, 0xa2, 0xd2, 0x6f, 0x04, 0x56,
|
||||
0xb8, 0x49, 0x3c, 0x7e, 0x08, 0x51, 0xfb, 0x4f, 0x0b, 0xa1, 0x13, 0xce, 0x5e, 0x24, 0x2c, 0x51,
|
||||
0x54, 0xe2, 0xbb, 0xc8, 0x1d, 0x0f, 0x59, 0xc4, 0xf4, 0x56, 0xd9, 0xa4, 0x32, 0x3e, 0x89, 0x18,
|
||||
0x6c, 0xe0, 0x78, 0x38, 0x4b, 0xd8, 0x58, 0x6f, 0x94, 0x4d, 0xdc, 0xf1, 0xcf, 0x09, 0x1b, 0x9b,
|
||||
0x34, 0x83, 0xb4, 0x93, 0xa7, 0x4f, 0x20, 0x7d, 0x17, 0xb9, 0xb1, 0xb6, 0xa8, 0xe8, 0xd5, 0x55,
|
||||
0xe2, 0xdc, 0x22, 0x36, 0x16, 0xae, 0xce, 0xba, 0x71, 0x61, 0x11, 0x1b, 0x0b, 0x2f, 0x4f, 0x83,
|
||||
0x45, 0xfb, 0x1f, 0x1b, 0x55, 0x09, 0x9d, 0xd1, 0x48, 0x49, 0x90, 0x88, 0x82, 0x9e, 0x03, 0xf4,
|
||||
0x44, 0x41, 0x4f, 0x2c, 0xe8, 0x39, 0x40, 0x4f, 0x2c, 0xe8, 0x89, 0x05, 0x3d, 0x07, 0xe8, 0x89,
|
||||
0x05, 0x3d, 0x51, 0xd2, 0x73, 0x80, 0x9e, 0x28, 0xe9, 0x89, 0x92, 0x9e, 0x03, 0xf4, 0x44, 0x49,
|
||||
0x4f, 0x94, 0xf4, 0x1c, 0xa0, 0x27, 0x4e, 0xaf, 0x75, 0x2d, 0xe8, 0x39, 0x40, 0x4f, 0x94, 0xf4,
|
||||
0xc4, 0x82, 0x9e, 0x03, 0xf4, 0xc4, 0x82, 0x9e, 0x28, 0xe9, 0x39, 0x40, 0x4f, 0x94, 0xf4, 0x44,
|
||||
0x49, 0xcf, 0x01, 0x7a, 0xa2, 0xa4, 0x27, 0x16, 0xf4, 0x1c, 0xa0, 0x27, 0x0c, 0xbd, 0x7f, 0x6d,
|
||||
0xe4, 0xbd, 0x49, 0xe2, 0x09, 0x55, 0xf8, 0x31, 0x72, 0xcf, 0x79, 0xca, 0x85, 0x26, 0xb7, 0xdd,
|
||||
0xdd, 0xe9, 0x98, 0x2b, 0xda, 0x31, 0xe5, 0xce, 0x73, 0xa8, 0x11, 0x23, 0xc1, 0x4f, 0xc0, 0xcf,
|
||||
0xa8, 0x61, 0xf3, 0xd6, 0xa9, 0x3d, 0xa1, 0xff, 0xe2, 0x47, 0xc8, 0x93, 0xfa, 0x2a, 0xe9, 0x53,
|
||||
0xd5, 0xe8, 0x6e, 0x17, 0x6a, 0x73, 0xc1, 0x48, 0x5e, 0xc5, 0x5f, 0x98, 0x0d, 0xd1, 0x4a, 0x58,
|
||||
0xe7, 0xaa, 0x12, 0x36, 0x28, 0x97, 0x56, 0x85, 0x01, 0xec, 0xef, 0x68, 0xcf, 0x3b, 0x85, 0x32,
|
||||
0xe7, 0x4e, 0x8a, 0x3a, 0xfe, 0x0a, 0xd5, 0xc5, 0xb0, 0x10, 0xdf, 0xd3, 0xb6, 0x2b, 0xe2, 0x9a,
|
||||
0xc8, 0x7f, 0xb5, 0x3f, 0x43, 0xae, 0x59, 0x74, 0x15, 0x39, 0x64, 0x70, 0xd4, 0xdc, 0xc0, 0x75,
|
||||
0xe4, 0x7e, 0x4f, 0x06, 0x83, 0x93, 0xa6, 0x85, 0x6b, 0xa8, 0x72, 0xf8, 0xea, 0x6c, 0xd0, 0xb4,
|
||||
0xdb, 0x7f, 0xd9, 0xa8, 0x72, 0x1c, 0xcd, 0x24, 0xfe, 0x16, 0x35, 0xa6, 0xe6, 0xb8, 0xc0, 0xde,
|
||||
0xeb, 0x33, 0xd6, 0xe8, 0x7e, 0x58, 0xf8, 0x83, 0xa4, 0x73, 0xac, 0xcf, 0xcf, 0xa9, 0x12, 0x03,
|
||||
0xa6, 0xc4, 0x9c, 0xd4, 0xa7, 0x45, 0x8c, 0x0f, 0xd0, 0xd6, 0x54, 0x9f, 0xcd, 0xe2, 0xab, 0x6d,
|
||||
0xdd, 0xfe, 0xd1, 0xcd, 0x76, 0x38, 0xaf, 0xe6, 0xb3, 0x8d, 0x41, 0x63, 0x5a, 0x66, 0x5a, 0xdf,
|
||||
0xa1, 0xed, 0x9b, 0xfe, 0xb8, 0x89, 0x9c, 0x5f, 0xe9, 0x5c, 0x63, 0x74, 0x08, 0xfc, 0xc4, 0x3b,
|
||||
0xc8, 0xbd, 0x88, 0xd2, 0x8c, 0xea, 0xeb, 0x57, 0x27, 0x26, 0x78, 0x66, 0x7f, 0x63, 0xb5, 0x4e,
|
||||
0x50, 0x73, 0xd9, 0xfe, 0x7a, 0x7f, 0xcd, 0xf4, 0x3f, 0xbc, 0xde, 0xbf, 0x0a, 0xa5, 0xf4, 0x6b,
|
||||
0xff, 0x61, 0xa1, 0xcd, 0x63, 0x39, 0x79, 0x93, 0xa8, 0xb7, 0x3f, 0x31, 0xca, 0xc7, 0xf8, 0x3e,
|
||||
0x72, 0x55, 0xa2, 0x52, 0xaa, 0xed, 0xea, 0x2f, 0x37, 0x88, 0x09, 0xb1, 0x8f, 0x3c, 0x19, 0xa5,
|
||||
0x91, 0x98, 0x6b, 0x4f, 0xe7, 0xe5, 0x06, 0xc9, 0x63, 0xdc, 0x42, 0xd5, 0xe7, 0x3c, 0x83, 0x95,
|
||||
0xe8, 0x67, 0x01, 0x7a, 0x8a, 0x04, 0xfe, 0x14, 0x6d, 0xbe, 0xe5, 0x53, 0x3a, 0x8c, 0xe2, 0x58,
|
||||
0x50, 0x29, 0xf5, 0x0b, 0x01, 0x82, 0x06, 0x64, 0x0f, 0x4c, 0xf2, 0xb0, 0x8a, 0xdc, 0x8c, 0x25,
|
||||
0x9c, 0xb5, 0x1f, 0xa1, 0x0a, 0xa1, 0x51, 0x5a, 0x7e, 0xbe, 0x65, 0xde, 0x08, 0x1d, 0x3c, 0xae,
|
||||
0xd5, 0xe2, 0xe6, 0xd5, 0xd5, 0xd5, 0x95, 0xdd, 0xbe, 0x84, 0xff, 0x08, 0x5f, 0xf2, 0x1e, 0xef,
|
||||
0xa1, 0x7a, 0x32, 0x8d, 0x26, 0x09, 0x83, 0x95, 0x19, 0x79, 0x99, 0x28, 0x5b, 0xba, 0x47, 0x68,
|
||||
0x5b, 0xd0, 0x28, 0x1d, 0xd2, 0xf7, 0x8a, 0x32, 0x99, 0x70, 0x86, 0x37, 0xcb, 0x23, 0x15, 0xa5,
|
||||
0xfe, 0x6f, 0x37, 0xcf, 0x64, 0x6e, 0x4f, 0xb6, 0xa0, 0x69, 0x50, 0xf4, 0xb4, 0xff, 0x73, 0x11,
|
||||
0xfa, 0x91, 0xf1, 0x4b, 0xf6, 0x7a, 0x3e, 0xa3, 0x12, 0x3f, 0x44, 0x76, 0xc4, 0xfc, 0x6d, 0xdd,
|
||||
0xba, 0xd3, 0x31, 0xf3, 0xa9, 0x53, 0xcc, 0xa7, 0xce, 0x01, 0x9b, 0x13, 0x3b, 0x62, 0xf8, 0x4b,
|
||||
0xe4, 0xc4, 0x99, 0xb9, 0xa5, 0x8d, 0xee, 0xee, 0x8a, 0xec, 0x28, 0x9f, 0x92, 0x04, 0x54, 0xf8,
|
||||
0x73, 0x64, 0x4b, 0xe5, 0x6f, 0x6a, 0xed, 0x83, 0x15, 0xed, 0xa9, 0x9e, 0x98, 0xc4, 0x96, 0x70,
|
||||
0xfb, 0x6d, 0x25, 0x73, 0xbe, 0xad, 0x15, 0xe1, 0xeb, 0x62, 0x78, 0x12, 0x5b, 0x49, 0xd0, 0xa6,
|
||||
0x17, 0xfe, 0x9d, 0x35, 0xda, 0x57, 0x89, 0x54, 0xbf, 0xc0, 0x0e, 0x13, 0x3b, 0xbd, 0xc0, 0x21,
|
||||
0x72, 0x2e, 0xa2, 0xd4, 0x6f, 0x6a, 0xf1, 0xfd, 0x15, 0xb1, 0x11, 0x82, 0x04, 0x77, 0x90, 0x13,
|
||||
0x8f, 0x52, 0xcd, 0xbc, 0xd1, 0xdd, 0x5b, 0xfd, 0x2e, 0xfd, 0xc8, 0xe5, 0xfa, 0x78, 0x94, 0xe2,
|
||||
0x27, 0xc8, 0x19, 0xa7, 0x4a, 0x1f, 0x01, 0xb8, 0x70, 0xcb, 0x7a, 0xfd, 0x5c, 0xe6, 0xf2, 0x71,
|
||||
0xaa, 0x40, 0x9e, 0xe4, 0xb3, 0xf5, 0x36, 0xb9, 0xbe, 0x42, 0xb9, 0x3c, 0xe9, 0xf7, 0x60, 0x35,
|
||||
0x59, 0xbf, 0xa7, 0xa7, 0xca, 0x6d, 0xab, 0x39, 0xbb, 0xae, 0xcf, 0xfa, 0x3d, 0x6d, 0xbf, 0xdf,
|
||||
0xd5, 0x43, 0x78, 0x8d, 0xfd, 0x7e, 0xb7, 0xb0, 0xdf, 0xef, 0x6a, 0xfb, 0xfd, 0xae, 0x9e, 0xcc,
|
||||
0xeb, 0xec, 0x17, 0xfa, 0x4c, 0xeb, 0x2b, 0x7a, 0x84, 0xd5, 0xd7, 0x6c, 0x3a, 0xdc, 0x61, 0x23,
|
||||
0xd7, 0x3a, 0xf0, 0x87, 0xd7, 0x08, 0xad, 0xf1, 0x37, 0x63, 0x21, 0xf7, 0x97, 0x4a, 0xe0, 0xaf,
|
||||
0x91, 0x5b, 0x0e, 0xf7, 0xdb, 0x3e, 0x40, 0x8f, 0x0b, 0xd3, 0x60, 0x94, 0xcf, 0x02, 0x54, 0x61,
|
||||
0xd1, 0x94, 0x2e, 0x1d, 0xfc, 0xdf, 0xf5, 0x0b, 0xa3, 0x2b, 0xff, 0x07, 0x00, 0x00, 0xff, 0xff,
|
||||
0xd5, 0x39, 0x32, 0x09, 0xf9, 0x09, 0x00, 0x00,
|
||||
}
|
147
vendor/github.com/golang/protobuf/jsonpb/jsonpb_test_proto/test_objects.proto
generated
vendored
147
vendor/github.com/golang/protobuf/jsonpb/jsonpb_test_proto/test_objects.proto
generated
vendored
@ -1,147 +0,0 @@
|
||||
// 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;
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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<int64, string> m_int64_str = 1;
|
||||
map<bool, Simple> 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;
|
||||
}
|
43
vendor/github.com/golang/protobuf/proto/Makefile
generated
vendored
43
vendor/github.com/golang/protobuf/proto/Makefile
generated
vendored
@ -1,43 +0,0 @@
|
||||
# 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 --go_out=Mtestdata/test.proto=github.com/golang/protobuf/proto/testdata,Mgoogle/protobuf/any.proto=github.com/golang/protobuf/ptypes/any:. proto3_proto/proto3.proto
|
||||
make
|
604
vendor/github.com/golang/protobuf/proto/all_test.go
generated
vendored
604
vendor/github.com/golang/protobuf/proto/all_test.go
generated
vendored
@ -41,11 +41,13 @@ import (
|
||||
"reflect"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
. "github.com/golang/protobuf/proto"
|
||||
. "github.com/golang/protobuf/proto/testdata"
|
||||
pb3 "github.com/golang/protobuf/proto/proto3_proto"
|
||||
. "github.com/golang/protobuf/proto/test_proto"
|
||||
)
|
||||
|
||||
var globalO *Buffer
|
||||
@ -114,6 +116,8 @@ func initGoTest(setdefaults bool) *GoTest {
|
||||
pb.F_BytesDefaulted = Default_GoTest_F_BytesDefaulted
|
||||
pb.F_Sint32Defaulted = Int32(Default_GoTest_F_Sint32Defaulted)
|
||||
pb.F_Sint64Defaulted = Int64(Default_GoTest_F_Sint64Defaulted)
|
||||
pb.F_Sfixed32Defaulted = Int32(Default_GoTest_F_Sfixed32Defaulted)
|
||||
pb.F_Sfixed64Defaulted = Int64(Default_GoTest_F_Sfixed64Defaulted)
|
||||
}
|
||||
|
||||
pb.Kind = GoTest_TIME.Enum()
|
||||
@ -131,135 +135,13 @@ func initGoTest(setdefaults bool) *GoTest {
|
||||
pb.F_BytesRequired = []byte("bytes")
|
||||
pb.F_Sint32Required = Int32(-32)
|
||||
pb.F_Sint64Required = Int64(-64)
|
||||
pb.F_Sfixed32Required = Int32(-32)
|
||||
pb.F_Sfixed64Required = 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'
|
||||
@ -482,6 +364,48 @@ func TestMarshalerEncoding(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure that Buffer.Marshal uses O(N) memory for N messages
|
||||
func TestBufferMarshalAllocs(t *testing.T) {
|
||||
value := &OtherMessage{Key: Int64(1)}
|
||||
msg := &MyMessage{Count: Int32(1), Others: []*OtherMessage{value}}
|
||||
|
||||
reallocSize := func(t *testing.T, items int, prealloc int) (int64, int64) {
|
||||
var b Buffer
|
||||
b.SetBuf(make([]byte, 0, prealloc))
|
||||
|
||||
var allocSpace int64
|
||||
prevCap := cap(b.Bytes())
|
||||
for i := 0; i < items; i++ {
|
||||
err := b.Marshal(msg)
|
||||
if err != nil {
|
||||
t.Errorf("Marshal err = %q", err)
|
||||
break
|
||||
}
|
||||
if c := cap(b.Bytes()); prevCap != c {
|
||||
allocSpace += int64(c)
|
||||
prevCap = c
|
||||
}
|
||||
}
|
||||
needSpace := int64(len(b.Bytes()))
|
||||
return allocSpace, needSpace
|
||||
}
|
||||
|
||||
for _, prealloc := range []int{0, 100, 10000} {
|
||||
for _, items := range []int{1, 2, 5, 10, 20, 50, 100, 200, 500, 1000} {
|
||||
runtimeSpace, need := reallocSize(t, items, prealloc)
|
||||
totalSpace := int64(prealloc) + runtimeSpace
|
||||
|
||||
runtimeRatio := float64(runtimeSpace) / float64(need)
|
||||
totalRatio := float64(totalSpace) / float64(need)
|
||||
|
||||
if totalRatio < 1 || runtimeRatio > 4 {
|
||||
t.Errorf("needed %dB, allocated %dB total (ratio %.1f), allocated %dB at runtime (ratio %.1f)",
|
||||
need, totalSpace, totalRatio, runtimeSpace, runtimeRatio)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Simple tests for bytes
|
||||
func TestBytesPrimitives(t *testing.T) {
|
||||
o := old()
|
||||
@ -519,7 +443,7 @@ func TestRequiredBit(t *testing.T) {
|
||||
err := o.Marshal(pb)
|
||||
if err == nil {
|
||||
t.Error("did not catch missing required fields")
|
||||
} else if strings.Index(err.Error(), "Kind") < 0 {
|
||||
} else if !strings.Contains(err.Error(), "Kind") {
|
||||
t.Error("wrong error type:", err)
|
||||
}
|
||||
}
|
||||
@ -612,7 +536,9 @@ func TestEncodeDecode1(t *testing.T) {
|
||||
"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
|
||||
"b8067f"+ // field 103, encoding 0, 0x7f zigzag64
|
||||
"c506e0ffffff"+ // field 104, encoding 5, -32 fixed32
|
||||
"c906c0ffffffffffffff") // field 105, encoding 1, -64 fixed64
|
||||
}
|
||||
|
||||
// All required fields set, defaults provided.
|
||||
@ -647,9 +573,13 @@ func TestEncodeDecode2(t *testing.T) {
|
||||
"aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
|
||||
"b0063f"+ // field 102, encoding 0, 0x3f zigzag32
|
||||
"b8067f"+ // field 103, encoding 0, 0x7f zigzag64
|
||||
"c506e0ffffff"+ // field 104, encoding 5, -32 fixed32
|
||||
"c906c0ffffffffffffff"+ // field 105, encoding 1, -64 fixed64
|
||||
"8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose"
|
||||
"90193f"+ // field 402, encoding 0, value 63
|
||||
"98197f") // field 403, encoding 0, value 127
|
||||
"98197f"+ // field 403, encoding 0, value 127
|
||||
"a519e0ffffff"+ // field 404, encoding 5, -32 fixed32
|
||||
"a919c0ffffffffffffff") // field 405, encoding 1, -64 fixed64
|
||||
|
||||
}
|
||||
|
||||
@ -669,6 +599,8 @@ func TestEncodeDecode3(t *testing.T) {
|
||||
pb.F_BytesDefaulted = []byte("Bignose")
|
||||
pb.F_Sint32Defaulted = Int32(-32)
|
||||
pb.F_Sint64Defaulted = Int64(-64)
|
||||
pb.F_Sfixed32Defaulted = Int32(-32)
|
||||
pb.F_Sfixed64Defaulted = Int64(-64)
|
||||
|
||||
overify(t, pb,
|
||||
"0807"+ // field 1, encoding 0, value 7
|
||||
@ -699,9 +631,13 @@ func TestEncodeDecode3(t *testing.T) {
|
||||
"aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
|
||||
"b0063f"+ // field 102, encoding 0, 0x3f zigzag32
|
||||
"b8067f"+ // field 103, encoding 0, 0x7f zigzag64
|
||||
"c506e0ffffff"+ // field 104, encoding 5, -32 fixed32
|
||||
"c906c0ffffffffffffff"+ // field 105, encoding 1, -64 fixed64
|
||||
"8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose"
|
||||
"90193f"+ // field 402, encoding 0, value 63
|
||||
"98197f") // field 403, encoding 0, value 127
|
||||
"98197f"+ // field 403, encoding 0, value 127
|
||||
"a519e0ffffff"+ // field 404, encoding 5, -32 fixed32
|
||||
"a919c0ffffffffffffff") // field 405, encoding 1, -64 fixed64
|
||||
|
||||
}
|
||||
|
||||
@ -724,6 +660,8 @@ func TestEncodeDecode4(t *testing.T) {
|
||||
pb.F_BytesOptional = []byte("Bignose")
|
||||
pb.F_Sint32Optional = Int32(-32)
|
||||
pb.F_Sint64Optional = Int64(-64)
|
||||
pb.F_Sfixed32Optional = Int32(-32)
|
||||
pb.F_Sfixed64Optional = Int64(-64)
|
||||
pb.Optionalgroup = initGoTest_OptionalGroup()
|
||||
|
||||
overify(t, pb,
|
||||
@ -771,12 +709,18 @@ func TestEncodeDecode4(t *testing.T) {
|
||||
"aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
|
||||
"b0063f"+ // field 102, encoding 0, 0x3f zigzag32
|
||||
"b8067f"+ // field 103, encoding 0, 0x7f zigzag64
|
||||
"c506e0ffffff"+ // field 104, encoding 5, -32 fixed32
|
||||
"c906c0ffffffffffffff"+ // field 105, encoding 1, -64 fixed64
|
||||
"ea1207"+"4269676e6f7365"+ // field 301, encoding 2, string "Bignose"
|
||||
"f0123f"+ // field 302, encoding 0, value 63
|
||||
"f8127f"+ // field 303, encoding 0, value 127
|
||||
"8513e0ffffff"+ // field 304, encoding 5, -32 fixed32
|
||||
"8913c0ffffffffffffff"+ // field 305, encoding 1, -64 fixed64
|
||||
"8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose"
|
||||
"90193f"+ // field 402, encoding 0, value 63
|
||||
"98197f") // field 403, encoding 0, value 127
|
||||
"98197f"+ // field 403, encoding 0, value 127
|
||||
"a519e0ffffff"+ // field 404, encoding 5, -32 fixed32
|
||||
"a919c0ffffffffffffff") // field 405, encoding 1, -64 fixed64
|
||||
|
||||
}
|
||||
|
||||
@ -797,6 +741,8 @@ func TestEncodeDecode5(t *testing.T) {
|
||||
pb.F_BytesRepeated = [][]byte{[]byte("big"), []byte("nose")}
|
||||
pb.F_Sint32Repeated = []int32{32, -32}
|
||||
pb.F_Sint64Repeated = []int64{64, -64}
|
||||
pb.F_Sfixed32Repeated = []int32{32, -32}
|
||||
pb.F_Sfixed64Repeated = []int64{64, -64}
|
||||
pb.Repeatedgroup = []*GoTest_RepeatedGroup{initGoTest_RepeatedGroup(), initGoTest_RepeatedGroup()}
|
||||
|
||||
overify(t, pb,
|
||||
@ -856,15 +802,23 @@ func TestEncodeDecode5(t *testing.T) {
|
||||
"aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
|
||||
"b0063f"+ // field 102, encoding 0, 0x3f zigzag32
|
||||
"b8067f"+ // field 103, encoding 0, 0x7f zigzag64
|
||||
"c506e0ffffff"+ // field 104, encoding 5, -32 fixed32
|
||||
"c906c0ffffffffffffff"+ // field 105, encoding 1, -64 fixed64
|
||||
"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
|
||||
"e50c20000000"+ // field 204, encoding 5, 32 fixed32
|
||||
"e50ce0ffffff"+ // field 204, encoding 5, -32 fixed32
|
||||
"e90c4000000000000000"+ // field 205, encoding 1, 64 fixed64
|
||||
"e90cc0ffffffffffffff"+ // field 205, encoding 1, -64 fixed64
|
||||
"8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose"
|
||||
"90193f"+ // field 402, encoding 0, value 63
|
||||
"98197f") // field 403, encoding 0, value 127
|
||||
"98197f"+ // field 403, encoding 0, value 127
|
||||
"a519e0ffffff"+ // field 404, encoding 5, -32 fixed32
|
||||
"a919c0ffffffffffffff") // field 405, encoding 1, -64 fixed64
|
||||
|
||||
}
|
||||
|
||||
@ -882,6 +836,8 @@ func TestEncodeDecode6(t *testing.T) {
|
||||
pb.F_DoubleRepeatedPacked = []float64{64., 65.}
|
||||
pb.F_Sint32RepeatedPacked = []int32{32, -32}
|
||||
pb.F_Sint64RepeatedPacked = []int64{64, -64}
|
||||
pb.F_Sfixed32RepeatedPacked = []int32{32, -32}
|
||||
pb.F_Sfixed64RepeatedPacked = []int64{64, -64}
|
||||
|
||||
overify(t, pb,
|
||||
"0807"+ // field 1, encoding 0, value 7
|
||||
@ -917,10 +873,17 @@ func TestEncodeDecode6(t *testing.T) {
|
||||
"aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
|
||||
"b0063f"+ // field 102, encoding 0, 0x3f zigzag32
|
||||
"b8067f"+ // field 103, encoding 0, 0x7f zigzag64
|
||||
"c506e0ffffff"+ // field 104, encoding 5, -32 fixed32
|
||||
"c906c0ffffffffffffff"+ // field 105, encoding 1, -64 fixed64
|
||||
"b21f02"+ // field 502, encoding 2, 2 bytes
|
||||
"403f"+ // value 32, value -32
|
||||
"ba1f03"+ // field 503, encoding 2, 3 bytes
|
||||
"80017f") // value 64, value -64
|
||||
"80017f"+ // value 64, value -64
|
||||
"c21f08"+ // field 504, encoding 2, 8 bytes
|
||||
"20000000e0ffffff"+ // value 32, value -32
|
||||
"ca1f10"+ // field 505, encoding 2, 16 bytes
|
||||
"4000000000000000c0ffffffffffffff") // value 64, value -64
|
||||
|
||||
}
|
||||
|
||||
// Test that we can encode empty bytes fields.
|
||||
@ -1167,13 +1130,10 @@ func TestBigRepeated(t *testing.T) {
|
||||
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 {
|
||||
if x := uint64(pbd.F_Sint64Repeated[i]); x != i {
|
||||
t.Error("pbd.F_Sint64Repeated bad", x, i)
|
||||
}
|
||||
x = uint64(pbd.F_Sint32Repeated[i])
|
||||
if x != i {
|
||||
if x := uint64(pbd.F_Sint32Repeated[i]); x != i {
|
||||
t.Error("pbd.F_Sint32Repeated bad", x, i)
|
||||
}
|
||||
s := fmt.Sprint(i)
|
||||
@ -1181,39 +1141,31 @@ func TestBigRepeated(t *testing.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 {
|
||||
if x := uint64(pbd.F_DoubleRepeated[i]); x != i {
|
||||
t.Error("pbd.F_DoubleRepeated bad", x, i)
|
||||
}
|
||||
x = uint64(pbd.F_FloatRepeated[i])
|
||||
if x != i {
|
||||
if x := uint64(pbd.F_FloatRepeated[i]); x != i {
|
||||
t.Error("pbd.F_FloatRepeated bad", x, i)
|
||||
}
|
||||
x = pbd.F_Uint64Repeated[i]
|
||||
if x != i {
|
||||
if x := pbd.F_Uint64Repeated[i]; x != i {
|
||||
t.Error("pbd.F_Uint64Repeated bad", x, i)
|
||||
}
|
||||
x = uint64(pbd.F_Uint32Repeated[i])
|
||||
if x != i {
|
||||
if x := uint64(pbd.F_Uint32Repeated[i]); x != i {
|
||||
t.Error("pbd.F_Uint32Repeated bad", x, i)
|
||||
}
|
||||
x = pbd.F_Fixed64Repeated[i]
|
||||
if x != i {
|
||||
if x := pbd.F_Fixed64Repeated[i]; x != i {
|
||||
t.Error("pbd.F_Fixed64Repeated bad", x, i)
|
||||
}
|
||||
x = uint64(pbd.F_Fixed32Repeated[i])
|
||||
if x != i {
|
||||
if x := uint64(pbd.F_Fixed32Repeated[i]); x != i {
|
||||
t.Error("pbd.F_Fixed32Repeated bad", x, i)
|
||||
}
|
||||
x = uint64(pbd.F_Int64Repeated[i])
|
||||
if x != i {
|
||||
if x := uint64(pbd.F_Int64Repeated[i]); x != i {
|
||||
t.Error("pbd.F_Int64Repeated bad", x, i)
|
||||
}
|
||||
x = uint64(pbd.F_Int32Repeated[i])
|
||||
if x != i {
|
||||
if x := uint64(pbd.F_Int32Repeated[i]); x != i {
|
||||
t.Error("pbd.F_Int32Repeated bad", x, i)
|
||||
}
|
||||
if pbd.F_BoolRepeated[i] != (i%2 == 0) {
|
||||
if x := pbd.F_BoolRepeated[i]; x != (i%2 == 0) {
|
||||
t.Error("pbd.F_BoolRepeated bad", x, i)
|
||||
}
|
||||
if pbd.RepeatedField[i] == nil { // TODO: more checking?
|
||||
@ -1222,21 +1174,25 @@ func TestBigRepeated(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Verify we give a useful message when decoding to the wrong structure type.
|
||||
func TestTypeMismatch(t *testing.T) {
|
||||
pb1 := initGoTest(true)
|
||||
func TestBadWireTypeUnknown(t *testing.T) {
|
||||
var b []byte
|
||||
fmt.Sscanf("0a01780d00000000080b101612036161611521000000202c220362626225370000002203636363214200000000000000584d5a036464645900000000000056405d63000000", "%x", &b)
|
||||
|
||||
// Marshal
|
||||
o := old()
|
||||
o.Marshal(pb1)
|
||||
m := new(MyMessage)
|
||||
if err := Unmarshal(b, m); err != nil {
|
||||
t.Errorf("unexpected Unmarshal error: %v", err)
|
||||
}
|
||||
|
||||
// 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)
|
||||
var unknown []byte
|
||||
fmt.Sscanf("0a01780d0000000010161521000000202c2537000000214200000000000000584d5a036464645d63000000", "%x", &unknown)
|
||||
if !bytes.Equal(m.XXX_unrecognized, unknown) {
|
||||
t.Errorf("unknown bytes mismatch:\ngot %x\nwant %x", m.XXX_unrecognized, unknown)
|
||||
}
|
||||
DiscardUnknown(m)
|
||||
|
||||
want := &MyMessage{Count: Int32(11), Name: String("aaa"), Pet: []string{"bbb", "ccc"}, Bigfloat: Float64(88)}
|
||||
if !Equal(m, want) {
|
||||
t.Errorf("message mismatch:\ngot %v\nwant %v", m, want)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1331,7 +1287,8 @@ func TestRequiredFieldEnforcement(t *testing.T) {
|
||||
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}") {
|
||||
} else if _, ok := err.(*RequiredNotSetError); !ok || !strings.Contains(err.Error(), "Type") && !strings.Contains(err.Error(), "{Unknown}") {
|
||||
// TODO: remove unknown cases once we commit to the new unmarshaler.
|
||||
t.Errorf("unmarshal: bad error type: %v", err)
|
||||
}
|
||||
}
|
||||
@ -1348,7 +1305,7 @@ func TestRequiredFieldEnforcementGroups(t *testing.T) {
|
||||
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}") {
|
||||
} else if _, ok := err.(*RequiredNotSetError); !ok || !strings.Contains(err.Error(), "Group.Field") && !strings.Contains(err.Error(), "Group.{Unknown}") {
|
||||
t.Errorf("unmarshal: bad error type: %v", err)
|
||||
}
|
||||
}
|
||||
@ -1385,18 +1342,7 @@ 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
|
||||
}
|
||||
type NMMessage struct{}
|
||||
|
||||
func (*NMMessage) Reset() {}
|
||||
func (*NMMessage) String() string { return "" }
|
||||
@ -1595,6 +1541,14 @@ func TestVarintOverflow(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBytesWithInvalidLengthInGroup(t *testing.T) {
|
||||
// Overflowing a 64-bit length should not be allowed.
|
||||
b := []byte{0xbb, 0x30, 0xb2, 0x30, 0xb0, 0xb2, 0x83, 0xf1, 0xb0, 0xb2, 0xef, 0xbf, 0xbd, 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()
|
||||
@ -1668,6 +1622,28 @@ func TestExtensionMarshalOrder(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtensionMapFieldMarshalDeterministic(t *testing.T) {
|
||||
m := &MyMessage{Count: Int(123)}
|
||||
if err := SetExtension(m, E_Ext_More, &Ext{MapField: map[int32]int32{1: 1, 2: 2, 3: 3, 4: 4}}); err != nil {
|
||||
t.Fatalf("SetExtension: %v", err)
|
||||
}
|
||||
marshal := func(m Message) []byte {
|
||||
var b Buffer
|
||||
b.SetDeterministic(true)
|
||||
if err := b.Marshal(m); err != nil {
|
||||
t.Fatalf("Marshal failed: %v", err)
|
||||
}
|
||||
return b.Bytes()
|
||||
}
|
||||
|
||||
want := marshal(m)
|
||||
for i := 0; i < 100; i++ {
|
||||
if got := marshal(m); !bytes.Equal(got, want) {
|
||||
t.Errorf("Marshal produced inconsistent output with determinism enabled (pass %d).\n got %v\nwant %v", i, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Many extensions, because small maps might not iterate differently on each iteration.
|
||||
var exts = []*ExtensionDesc{
|
||||
E_X201,
|
||||
@ -1802,6 +1778,43 @@ func TestUnmarshalMergesMessages(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalMergesGroups(t *testing.T) {
|
||||
// If a nested group occurs twice in the input,
|
||||
// the fields should be merged when decoding.
|
||||
a := &GroupNew{
|
||||
G: &GroupNew_G{
|
||||
X: Int32(7),
|
||||
Y: Int32(8),
|
||||
},
|
||||
}
|
||||
aData, err := Marshal(a)
|
||||
if err != nil {
|
||||
t.Fatalf("Marshal(a): %v", err)
|
||||
}
|
||||
b := &GroupNew{
|
||||
G: &GroupNew_G{
|
||||
X: Int32(9),
|
||||
},
|
||||
}
|
||||
bData, err := Marshal(b)
|
||||
if err != nil {
|
||||
t.Fatalf("Marshal(b): %v", err)
|
||||
}
|
||||
want := &GroupNew{
|
||||
G: &GroupNew_G{
|
||||
X: Int32(9),
|
||||
Y: Int32(8),
|
||||
},
|
||||
}
|
||||
got := new(GroupNew)
|
||||
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
|
||||
@ -1845,7 +1858,9 @@ func TestRequiredNotSetError(t *testing.T) {
|
||||
"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
|
||||
"b8067f" + // field 103, encoding 0, 0x7f zigzag64
|
||||
"c506e0ffffff" + // field 104, encoding 5, -32 fixed32
|
||||
"c906c0ffffffffffffff" // field 105, encoding 1, -64 fixed64
|
||||
|
||||
o := old()
|
||||
bytes, err := Marshal(pb)
|
||||
@ -1854,7 +1869,7 @@ func TestRequiredNotSetError(t *testing.T) {
|
||||
o.DebugPrint("", bytes)
|
||||
t.Fatalf("expected = %s", expected)
|
||||
}
|
||||
if strings.Index(err.Error(), "RequiredField.Label") < 0 {
|
||||
if !strings.Contains(err.Error(), "RequiredField.Label") {
|
||||
t.Errorf("marshal-1 wrong err msg: %v", err)
|
||||
}
|
||||
if !equal(bytes, expected, t) {
|
||||
@ -1870,7 +1885,7 @@ func TestRequiredNotSetError(t *testing.T) {
|
||||
o.DebugPrint("", bytes)
|
||||
t.Fatalf("string = %s", expected)
|
||||
}
|
||||
if strings.Index(err.Error(), "RequiredField.{Unknown}") < 0 {
|
||||
if !strings.Contains(err.Error(), "RequiredField.Label") && !strings.Contains(err.Error(), "RequiredField.{Unknown}") {
|
||||
t.Errorf("unmarshal wrong err msg: %v", err)
|
||||
}
|
||||
bytes, err = Marshal(pbd)
|
||||
@ -1879,7 +1894,7 @@ func TestRequiredNotSetError(t *testing.T) {
|
||||
o.DebugPrint("", bytes)
|
||||
t.Fatalf("string = %s", expected)
|
||||
}
|
||||
if strings.Index(err.Error(), "RequiredField.Label") < 0 {
|
||||
if !strings.Contains(err.Error(), "RequiredField.Label") {
|
||||
t.Errorf("marshal-2 wrong err msg: %v", err)
|
||||
}
|
||||
if !equal(bytes, expected, t) {
|
||||
@ -1888,6 +1903,25 @@ func TestRequiredNotSetError(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequiredNotSetErrorWithBadWireTypes(t *testing.T) {
|
||||
// Required field expects a varint, and properly found a varint.
|
||||
if err := Unmarshal([]byte{0x08, 0x00}, new(GoEnum)); err != nil {
|
||||
t.Errorf("Unmarshal = %v, want nil", err)
|
||||
}
|
||||
// Required field expects a varint, but found a fixed32 instead.
|
||||
if err := Unmarshal([]byte{0x0d, 0x00, 0x00, 0x00, 0x00}, new(GoEnum)); err == nil {
|
||||
t.Errorf("Unmarshal = nil, want RequiredNotSetError")
|
||||
}
|
||||
// Required field expects a varint, and found both a varint and fixed32 (ignored).
|
||||
m := new(GoEnum)
|
||||
if err := Unmarshal([]byte{0x08, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00}, m); err != nil {
|
||||
t.Errorf("Unmarshal = %v, want nil", err)
|
||||
}
|
||||
if !bytes.Equal(m.XXX_unrecognized, []byte{0x0d, 0x00, 0x00, 0x00, 0x00}) {
|
||||
t.Errorf("expected fixed32 to appear as unknown bytes: %x", m.XXX_unrecognized)
|
||||
}
|
||||
}
|
||||
|
||||
func fuzzUnmarshal(t *testing.T, data []byte) {
|
||||
defer func() {
|
||||
if e := recover(); e != nil {
|
||||
@ -1946,6 +1980,32 @@ func TestMapFieldMarshal(t *testing.T) {
|
||||
(new(Buffer)).DebugPrint("Dump of b", b)
|
||||
}
|
||||
|
||||
func TestMapFieldDeterministicMarshal(t *testing.T) {
|
||||
m := &MessageWithMap{
|
||||
NameMapping: map[int32]string{
|
||||
1: "Rob",
|
||||
4: "Ian",
|
||||
8: "Dave",
|
||||
},
|
||||
}
|
||||
|
||||
marshal := func(m Message) []byte {
|
||||
var b Buffer
|
||||
b.SetDeterministic(true)
|
||||
if err := b.Marshal(m); err != nil {
|
||||
t.Fatalf("Marshal failed: %v", err)
|
||||
}
|
||||
return b.Bytes()
|
||||
}
|
||||
|
||||
want := marshal(m)
|
||||
for i := 0; i < 10; i++ {
|
||||
if got := marshal(m); !bytes.Equal(got, want) {
|
||||
t.Errorf("Marshal produced inconsistent output with determinism enabled (pass %d).\n got %v\nwant %v", i, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapFieldRoundTrips(t *testing.T) {
|
||||
m := &MessageWithMap{
|
||||
NameMapping: map[int32]string{
|
||||
@ -1954,7 +2014,7 @@ func TestMapFieldRoundTrips(t *testing.T) {
|
||||
8: "Dave",
|
||||
},
|
||||
MsgMapping: map[int64]*FloatingPoint{
|
||||
0x7001: &FloatingPoint{F: Float64(2.0)},
|
||||
0x7001: {F: Float64(2.0)},
|
||||
},
|
||||
ByteMapping: map[bool][]byte{
|
||||
false: []byte("that's not right!"),
|
||||
@ -1970,14 +2030,8 @@ func TestMapFieldRoundTrips(t *testing.T) {
|
||||
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])
|
||||
}
|
||||
if !Equal(m, m2) {
|
||||
t.Errorf("Map did not survive a round trip.\ninitial: %v\n final: %v", m, m2)
|
||||
}
|
||||
}
|
||||
|
||||
@ -2005,7 +2059,7 @@ func TestMapFieldWithNil(t *testing.T) {
|
||||
func TestMapFieldWithNilBytes(t *testing.T) {
|
||||
m1 := &MessageWithMap{
|
||||
ByteMapping: map[bool][]byte{
|
||||
false: []byte{},
|
||||
false: {},
|
||||
true: nil,
|
||||
},
|
||||
}
|
||||
@ -2119,6 +2173,22 @@ func TestOneof(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestOneofNilBytes(t *testing.T) {
|
||||
// A oneof with nil byte slice should marshal to tag + 0 (size), with no error.
|
||||
m := &Communique{Union: &Communique_Data{Data: nil}}
|
||||
b, err := Marshal(m)
|
||||
if err != nil {
|
||||
t.Fatalf("Marshal failed: %v", err)
|
||||
}
|
||||
want := []byte{
|
||||
7<<3 | 2, // tag 7, wire type 2
|
||||
0, // size
|
||||
}
|
||||
if !bytes.Equal(b, want) {
|
||||
t.Errorf("Wrong result of Marshal: got %x, want %x", b, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInefficientPackedBool(t *testing.T) {
|
||||
// https://github.com/golang/protobuf/issues/76
|
||||
inp := []byte{
|
||||
@ -2132,6 +2202,150 @@ func TestInefficientPackedBool(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure pure-reflect-based implementation handles
|
||||
// []int32-[]enum conversion correctly.
|
||||
func TestRepeatedEnum2(t *testing.T) {
|
||||
pb := &RepeatedEnum{
|
||||
Color: []RepeatedEnum_Color{RepeatedEnum_RED},
|
||||
}
|
||||
b, err := Marshal(pb)
|
||||
if err != nil {
|
||||
t.Fatalf("Marshal failed: %v", err)
|
||||
}
|
||||
x := new(RepeatedEnum)
|
||||
err = Unmarshal(b, x)
|
||||
if err != nil {
|
||||
t.Fatalf("Unmarshal failed: %v", err)
|
||||
}
|
||||
if !Equal(pb, x) {
|
||||
t.Errorf("Incorrect result: want: %v got: %v", pb, x)
|
||||
}
|
||||
}
|
||||
|
||||
// TestConcurrentMarshal makes sure that it is safe to marshal
|
||||
// same message in multiple goroutines concurrently.
|
||||
func TestConcurrentMarshal(t *testing.T) {
|
||||
pb := initGoTest(true)
|
||||
const N = 100
|
||||
b := make([][]byte, N)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < N; i++ {
|
||||
wg.Add(1)
|
||||
go func(i int) {
|
||||
defer wg.Done()
|
||||
var err error
|
||||
b[i], err = Marshal(pb)
|
||||
if err != nil {
|
||||
t.Errorf("marshal error: %v", err)
|
||||
}
|
||||
}(i)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
for i := 1; i < N; i++ {
|
||||
if !bytes.Equal(b[0], b[i]) {
|
||||
t.Errorf("concurrent marshal result not same: b[0] = %v, b[%d] = %v", b[0], i, b[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestInvalidUTF8(t *testing.T) {
|
||||
const invalidUTF8 = "\xde\xad\xbe\xef\x80\x00\xff"
|
||||
tests := []struct {
|
||||
label string
|
||||
proto2 Message
|
||||
proto3 Message
|
||||
want []byte
|
||||
}{{
|
||||
label: "Scalar",
|
||||
proto2: &TestUTF8{Scalar: String(invalidUTF8)},
|
||||
proto3: &pb3.TestUTF8{Scalar: invalidUTF8},
|
||||
want: []byte{0x0a, 0x07, 0xde, 0xad, 0xbe, 0xef, 0x80, 0x00, 0xff},
|
||||
}, {
|
||||
label: "Vector",
|
||||
proto2: &TestUTF8{Vector: []string{invalidUTF8}},
|
||||
proto3: &pb3.TestUTF8{Vector: []string{invalidUTF8}},
|
||||
want: []byte{0x12, 0x07, 0xde, 0xad, 0xbe, 0xef, 0x80, 0x00, 0xff},
|
||||
}, {
|
||||
label: "Oneof",
|
||||
proto2: &TestUTF8{Oneof: &TestUTF8_Field{invalidUTF8}},
|
||||
proto3: &pb3.TestUTF8{Oneof: &pb3.TestUTF8_Field{invalidUTF8}},
|
||||
want: []byte{0x1a, 0x07, 0xde, 0xad, 0xbe, 0xef, 0x80, 0x00, 0xff},
|
||||
}, {
|
||||
label: "MapKey",
|
||||
proto2: &TestUTF8{MapKey: map[string]int64{invalidUTF8: 0}},
|
||||
proto3: &pb3.TestUTF8{MapKey: map[string]int64{invalidUTF8: 0}},
|
||||
want: []byte{0x22, 0x0b, 0x0a, 0x07, 0xde, 0xad, 0xbe, 0xef, 0x80, 0x00, 0xff, 0x10, 0x00},
|
||||
}, {
|
||||
label: "MapValue",
|
||||
proto2: &TestUTF8{MapValue: map[int64]string{0: invalidUTF8}},
|
||||
proto3: &pb3.TestUTF8{MapValue: map[int64]string{0: invalidUTF8}},
|
||||
want: []byte{0x2a, 0x0b, 0x08, 0x00, 0x12, 0x07, 0xde, 0xad, 0xbe, 0xef, 0x80, 0x00, 0xff},
|
||||
}}
|
||||
|
||||
for _, tt := range tests {
|
||||
// Proto2 should not validate UTF-8.
|
||||
b, err := Marshal(tt.proto2)
|
||||
if err != nil {
|
||||
t.Errorf("Marshal(proto2.%s) = %v, want nil", tt.label, err)
|
||||
}
|
||||
if !bytes.Equal(b, tt.want) {
|
||||
t.Errorf("Marshal(proto2.%s) = %x, want %x", tt.label, b, tt.want)
|
||||
}
|
||||
|
||||
m := Clone(tt.proto2)
|
||||
m.Reset()
|
||||
if err = Unmarshal(tt.want, m); err != nil {
|
||||
t.Errorf("Unmarshal(proto2.%s) = %v, want nil", tt.label, err)
|
||||
}
|
||||
if !Equal(m, tt.proto2) {
|
||||
t.Errorf("proto2.%s: output mismatch:\ngot %v\nwant %v", tt.label, m, tt.proto2)
|
||||
}
|
||||
|
||||
// Proto3 should validate UTF-8.
|
||||
b, err = Marshal(tt.proto3)
|
||||
if err == nil {
|
||||
t.Errorf("Marshal(proto3.%s) = %v, want non-nil", tt.label, err)
|
||||
}
|
||||
if !bytes.Equal(b, tt.want) {
|
||||
t.Errorf("Marshal(proto3.%s) = %x, want %x", tt.label, b, tt.want)
|
||||
}
|
||||
|
||||
m = Clone(tt.proto3)
|
||||
m.Reset()
|
||||
err = Unmarshal(tt.want, m)
|
||||
if err == nil {
|
||||
t.Errorf("Unmarshal(proto3.%s) = %v, want non-nil", tt.label, err)
|
||||
}
|
||||
if !Equal(m, tt.proto3) {
|
||||
t.Errorf("proto3.%s: output mismatch:\ngot %v\nwant %v", tt.label, m, tt.proto2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequired(t *testing.T) {
|
||||
// The F_BoolRequired field appears after all of the required fields.
|
||||
// It should still be handled even after multiple required field violations.
|
||||
m := &GoTest{F_BoolRequired: Bool(true)}
|
||||
got, err := Marshal(m)
|
||||
if _, ok := err.(*RequiredNotSetError); !ok {
|
||||
t.Errorf("Marshal() = %v, want RequiredNotSetError error", err)
|
||||
}
|
||||
if want := []byte{0x50, 0x01}; !bytes.Equal(got, want) {
|
||||
t.Errorf("Marshal() = %x, want %x", got, want)
|
||||
}
|
||||
|
||||
m = new(GoTest)
|
||||
err = Unmarshal(got, m)
|
||||
if _, ok := err.(*RequiredNotSetError); !ok {
|
||||
t.Errorf("Marshal() = %v, want RequiredNotSetError error", err)
|
||||
}
|
||||
if !m.GetF_BoolRequired() {
|
||||
t.Error("m.F_BoolRequired = false, want true")
|
||||
}
|
||||
}
|
||||
|
||||
// Benchmarks
|
||||
|
||||
func testMsg() *GoTest {
|
||||
|
18
vendor/github.com/golang/protobuf/proto/any_test.go
generated
vendored
18
vendor/github.com/golang/protobuf/proto/any_test.go
generated
vendored
@ -38,7 +38,7 @@ import (
|
||||
"github.com/golang/protobuf/proto"
|
||||
|
||||
pb "github.com/golang/protobuf/proto/proto3_proto"
|
||||
testpb "github.com/golang/protobuf/proto/testdata"
|
||||
testpb "github.com/golang/protobuf/proto/test_proto"
|
||||
anypb "github.com/golang/protobuf/ptypes/any"
|
||||
)
|
||||
|
||||
@ -166,33 +166,33 @@ anything: <
|
||||
name: "David"
|
||||
result_count: 47
|
||||
anything: <
|
||||
[type.googleapis.com/testdata.MyMessage]: <
|
||||
[type.googleapis.com/test_proto.MyMessage]: <
|
||||
count: 47
|
||||
name: "David"
|
||||
[testdata.Ext.more]: <
|
||||
[test_proto.Ext.more]: <
|
||||
data: "foo"
|
||||
>
|
||||
[testdata.Ext.text]: "bar"
|
||||
[test_proto.Ext.text]: "bar"
|
||||
>
|
||||
>
|
||||
many_things: <
|
||||
[type.googleapis.com/testdata.MyMessage]: <
|
||||
[type.googleapis.com/test_proto.MyMessage]: <
|
||||
count: 42
|
||||
bikeshed: GREEN
|
||||
rep_bytes: "roboto"
|
||||
[testdata.Ext.more]: <
|
||||
[test_proto.Ext.more]: <
|
||||
data: "baz"
|
||||
>
|
||||
>
|
||||
>
|
||||
many_things: <
|
||||
[type.googleapis.com/testdata.MyMessage]: <
|
||||
[type.googleapis.com/test_proto.MyMessage]: <
|
||||
count: 47
|
||||
name: "David"
|
||||
[testdata.Ext.more]: <
|
||||
[test_proto.Ext.more]: <
|
||||
data: "foo"
|
||||
>
|
||||
[testdata.Ext.text]: "bar"
|
||||
[test_proto.Ext.text]: "bar"
|
||||
>
|
||||
>
|
||||
`
|
||||
|
46
vendor/github.com/golang/protobuf/proto/clone.go
generated
vendored
46
vendor/github.com/golang/protobuf/proto/clone.go
generated
vendored
@ -35,22 +35,39 @@
|
||||
package proto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Clone returns a deep copy of a protocol buffer.
|
||||
func Clone(pb Message) Message {
|
||||
in := reflect.ValueOf(pb)
|
||||
func Clone(src Message) Message {
|
||||
in := reflect.ValueOf(src)
|
||||
if in.IsNil() {
|
||||
return pb
|
||||
return src
|
||||
}
|
||||
|
||||
out := reflect.New(in.Type().Elem())
|
||||
// out is empty so a merge is a deep copy.
|
||||
mergeStruct(out.Elem(), in.Elem())
|
||||
return out.Interface().(Message)
|
||||
dst := out.Interface().(Message)
|
||||
Merge(dst, src)
|
||||
return dst
|
||||
}
|
||||
|
||||
// Merger is the interface representing objects that can merge messages of the same type.
|
||||
type Merger interface {
|
||||
// Merge merges src into this message.
|
||||
// Required and optional fields that are set in src will be set to that value in dst.
|
||||
// Elements of repeated fields will be appended.
|
||||
//
|
||||
// Merge may panic if called with a different argument type than the receiver.
|
||||
Merge(src Message)
|
||||
}
|
||||
|
||||
// generatedMerger is the custom merge method that generated protos will have.
|
||||
// We must add this method since a generate Merge method will conflict with
|
||||
// many existing protos that have a Merge data field already defined.
|
||||
type generatedMerger interface {
|
||||
XXX_Merge(src Message)
|
||||
}
|
||||
|
||||
// Merge merges src into dst.
|
||||
@ -58,17 +75,24 @@ func Clone(pb Message) Message {
|
||||
// Elements of repeated fields will be appended.
|
||||
// Merge panics if src and dst are not the same type, or if dst is nil.
|
||||
func Merge(dst, src Message) {
|
||||
if m, ok := dst.(Merger); ok {
|
||||
m.Merge(src)
|
||||
return
|
||||
}
|
||||
|
||||
in := reflect.ValueOf(src)
|
||||
out := reflect.ValueOf(dst)
|
||||
if out.IsNil() {
|
||||
panic("proto: nil destination")
|
||||
}
|
||||
if in.Type() != out.Type() {
|
||||
// Explicit test prior to mergeStruct so that mistyped nils will fail
|
||||
panic("proto: type mismatch")
|
||||
panic(fmt.Sprintf("proto.Merge(%T, %T) type mismatch", dst, src))
|
||||
}
|
||||
if in.IsNil() {
|
||||
// Merging nil into non-nil is a quiet no-op
|
||||
return // Merge from nil src is a noop
|
||||
}
|
||||
if m, ok := dst.(generatedMerger); ok {
|
||||
m.XXX_Merge(src)
|
||||
return
|
||||
}
|
||||
mergeStruct(out.Elem(), in.Elem())
|
||||
@ -84,7 +108,7 @@ func mergeStruct(out, in reflect.Value) {
|
||||
mergeAny(out.Field(i), in.Field(i), false, sprop.Prop[i])
|
||||
}
|
||||
|
||||
if emIn, ok := extendable(in.Addr().Interface()); ok {
|
||||
if emIn, err := extendable(in.Addr().Interface()); err == nil {
|
||||
emOut, _ := extendable(out.Addr().Interface())
|
||||
mIn, muIn := emIn.extensionsRead()
|
||||
if mIn != nil {
|
||||
|
192
vendor/github.com/golang/protobuf/proto/clone_test.go
generated
vendored
192
vendor/github.com/golang/protobuf/proto/clone_test.go
generated
vendored
@ -37,7 +37,7 @@ import (
|
||||
"github.com/golang/protobuf/proto"
|
||||
|
||||
proto3pb "github.com/golang/protobuf/proto/proto3_proto"
|
||||
pb "github.com/golang/protobuf/proto/testdata"
|
||||
pb "github.com/golang/protobuf/proto/test_proto"
|
||||
)
|
||||
|
||||
var cloneTestMessage = &pb.MyMessage{
|
||||
@ -67,34 +67,50 @@ func init() {
|
||||
if err := proto.SetExtension(cloneTestMessage, pb.E_Ext_More, ext); err != nil {
|
||||
panic("SetExtension: " + err.Error())
|
||||
}
|
||||
if err := proto.SetExtension(cloneTestMessage, pb.E_Ext_Text, proto.String("hello")); err != nil {
|
||||
panic("SetExtension: " + err.Error())
|
||||
}
|
||||
if err := proto.SetExtension(cloneTestMessage, pb.E_Greeting, []string{"one", "two"}); 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)
|
||||
// Create a clone using a marshal/unmarshal roundtrip.
|
||||
vanilla := new(pb.MyMessage)
|
||||
b, err := proto.Marshal(cloneTestMessage)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected Marshal error: %v", err)
|
||||
}
|
||||
if err := proto.Unmarshal(b, vanilla); err != nil {
|
||||
t.Errorf("unexpected Unarshal error: %v", err)
|
||||
}
|
||||
|
||||
// Verify it was a deep copy.
|
||||
// Create a clone using Clone and verify that it is equal to the original.
|
||||
m := proto.Clone(cloneTestMessage).(*pb.MyMessage)
|
||||
if !proto.Equal(m, cloneTestMessage) {
|
||||
t.Fatalf("Clone(%v) = %v", cloneTestMessage, m)
|
||||
}
|
||||
|
||||
// Mutate the clone, which should not affect the original.
|
||||
x1, err := proto.GetExtension(m, pb.E_Ext_More)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected GetExtension(%v) error: %v", pb.E_Ext_More.Name, err)
|
||||
}
|
||||
x2, err := proto.GetExtension(m, pb.E_Ext_Text)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected GetExtension(%v) error: %v", pb.E_Ext_Text.Name, err)
|
||||
}
|
||||
x3, err := proto.GetExtension(m, pb.E_Greeting)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected GetExtension(%v) error: %v", pb.E_Greeting.Name, err)
|
||||
}
|
||||
*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")
|
||||
*(x1.(*pb.Ext)).Data = "blah blah"
|
||||
*(x2.(*string)) = "goodbye"
|
||||
x3.([]string)[0] = "zero"
|
||||
if !proto.Equal(cloneTestMessage, vanilla) {
|
||||
t.Fatalf("mutation on original detected:\ngot %v\nwant %v", cloneTestMessage, vanilla)
|
||||
}
|
||||
}
|
||||
|
||||
@ -244,27 +260,45 @@ var mergeTests = []struct {
|
||||
Data: []byte("texas!"),
|
||||
},
|
||||
},
|
||||
// Oneof fields should merge by assignment.
|
||||
{
|
||||
src: &pb.Communique{
|
||||
Union: &pb.Communique_Number{41},
|
||||
},
|
||||
dst: &pb.Communique{
|
||||
Union: &pb.Communique_Name{"Bobby Tables"},
|
||||
},
|
||||
want: &pb.Communique{
|
||||
Union: &pb.Communique_Number{41},
|
||||
},
|
||||
{ // Oneof fields should merge by assignment.
|
||||
src: &pb.Communique{Union: &pb.Communique_Number{41}},
|
||||
dst: &pb.Communique{Union: &pb.Communique_Name{"Bobby Tables"}},
|
||||
want: &pb.Communique{Union: &pb.Communique_Number{41}},
|
||||
},
|
||||
{ // Oneof nil is the same as not set.
|
||||
src: &pb.Communique{},
|
||||
dst: &pb.Communique{Union: &pb.Communique_Name{"Bobby Tables"}},
|
||||
want: &pb.Communique{Union: &pb.Communique_Name{"Bobby Tables"}},
|
||||
},
|
||||
// Oneof nil is the same as not set.
|
||||
{
|
||||
src: &pb.Communique{},
|
||||
dst: &pb.Communique{
|
||||
Union: &pb.Communique_Name{"Bobby Tables"},
|
||||
},
|
||||
want: &pb.Communique{
|
||||
Union: &pb.Communique_Name{"Bobby Tables"},
|
||||
},
|
||||
src: &pb.Communique{Union: &pb.Communique_Number{1337}},
|
||||
dst: &pb.Communique{},
|
||||
want: &pb.Communique{Union: &pb.Communique_Number{1337}},
|
||||
},
|
||||
{
|
||||
src: &pb.Communique{Union: &pb.Communique_Col{pb.MyMessage_RED}},
|
||||
dst: &pb.Communique{},
|
||||
want: &pb.Communique{Union: &pb.Communique_Col{pb.MyMessage_RED}},
|
||||
},
|
||||
{
|
||||
src: &pb.Communique{Union: &pb.Communique_Data{[]byte("hello")}},
|
||||
dst: &pb.Communique{},
|
||||
want: &pb.Communique{Union: &pb.Communique_Data{[]byte("hello")}},
|
||||
},
|
||||
{
|
||||
src: &pb.Communique{Union: &pb.Communique_Msg{&pb.Strings{BytesField: []byte{1, 2, 3}}}},
|
||||
dst: &pb.Communique{},
|
||||
want: &pb.Communique{Union: &pb.Communique_Msg{&pb.Strings{BytesField: []byte{1, 2, 3}}}},
|
||||
},
|
||||
{
|
||||
src: &pb.Communique{Union: &pb.Communique_Msg{}},
|
||||
dst: &pb.Communique{},
|
||||
want: &pb.Communique{Union: &pb.Communique_Msg{}},
|
||||
},
|
||||
{
|
||||
src: &pb.Communique{Union: &pb.Communique_Msg{&pb.Strings{StringField: proto.String("123")}}},
|
||||
dst: &pb.Communique{Union: &pb.Communique_Msg{&pb.Strings{BytesField: []byte{1, 2, 3}}}},
|
||||
want: &pb.Communique{Union: &pb.Communique_Msg{&pb.Strings{StringField: proto.String("123"), BytesField: []byte{1, 2, 3}}}},
|
||||
},
|
||||
{
|
||||
src: &proto3pb.Message{
|
||||
@ -287,14 +321,86 @@ var mergeTests = []struct {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
src: &pb.GoTest{
|
||||
F_BoolRepeated: []bool{},
|
||||
F_Int32Repeated: []int32{},
|
||||
F_Int64Repeated: []int64{},
|
||||
F_Uint32Repeated: []uint32{},
|
||||
F_Uint64Repeated: []uint64{},
|
||||
F_FloatRepeated: []float32{},
|
||||
F_DoubleRepeated: []float64{},
|
||||
F_StringRepeated: []string{},
|
||||
F_BytesRepeated: [][]byte{},
|
||||
},
|
||||
dst: &pb.GoTest{},
|
||||
want: &pb.GoTest{
|
||||
F_BoolRepeated: []bool{},
|
||||
F_Int32Repeated: []int32{},
|
||||
F_Int64Repeated: []int64{},
|
||||
F_Uint32Repeated: []uint32{},
|
||||
F_Uint64Repeated: []uint64{},
|
||||
F_FloatRepeated: []float32{},
|
||||
F_DoubleRepeated: []float64{},
|
||||
F_StringRepeated: []string{},
|
||||
F_BytesRepeated: [][]byte{},
|
||||
},
|
||||
},
|
||||
{
|
||||
src: &pb.GoTest{},
|
||||
dst: &pb.GoTest{
|
||||
F_BoolRepeated: []bool{},
|
||||
F_Int32Repeated: []int32{},
|
||||
F_Int64Repeated: []int64{},
|
||||
F_Uint32Repeated: []uint32{},
|
||||
F_Uint64Repeated: []uint64{},
|
||||
F_FloatRepeated: []float32{},
|
||||
F_DoubleRepeated: []float64{},
|
||||
F_StringRepeated: []string{},
|
||||
F_BytesRepeated: [][]byte{},
|
||||
},
|
||||
want: &pb.GoTest{
|
||||
F_BoolRepeated: []bool{},
|
||||
F_Int32Repeated: []int32{},
|
||||
F_Int64Repeated: []int64{},
|
||||
F_Uint32Repeated: []uint32{},
|
||||
F_Uint64Repeated: []uint64{},
|
||||
F_FloatRepeated: []float32{},
|
||||
F_DoubleRepeated: []float64{},
|
||||
F_StringRepeated: []string{},
|
||||
F_BytesRepeated: [][]byte{},
|
||||
},
|
||||
},
|
||||
{
|
||||
src: &pb.GoTest{
|
||||
F_BytesRepeated: [][]byte{nil, []byte{}, []byte{0}},
|
||||
},
|
||||
dst: &pb.GoTest{},
|
||||
want: &pb.GoTest{
|
||||
F_BytesRepeated: [][]byte{nil, []byte{}, []byte{0}},
|
||||
},
|
||||
},
|
||||
{
|
||||
src: &pb.MyMessage{
|
||||
Others: []*pb.OtherMessage{},
|
||||
},
|
||||
dst: &pb.MyMessage{},
|
||||
want: &pb.MyMessage{
|
||||
Others: []*pb.OtherMessage{},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestMerge(t *testing.T) {
|
||||
for _, m := range mergeTests {
|
||||
got := proto.Clone(m.dst)
|
||||
if !proto.Equal(got, m.dst) {
|
||||
t.Errorf("Clone()\ngot %v\nwant %v", got, m.dst)
|
||||
continue
|
||||
}
|
||||
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)
|
||||
t.Errorf("Merge(%v, %v)\ngot %v\nwant %v", m.dst, m.src, got, m.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
669
vendor/github.com/golang/protobuf/proto/decode.go
generated
vendored
669
vendor/github.com/golang/protobuf/proto/decode.go
generated
vendored
@ -39,8 +39,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// errOverflow is returned when an integer is too large to be represented.
|
||||
@ -50,10 +48,6 @@ var errOverflow = errors.New("proto: integer overflow")
|
||||
// wire type is encountered. It does not get returned to user code.
|
||||
var ErrInternalBadWireType = errors.New("proto: internal error: bad wiretype for oneof")
|
||||
|
||||
// The fundamental decoders that interpret bytes on the wire.
|
||||
// Those that take integer types all return uint64 and are
|
||||
// therefore of type valueDecoder.
|
||||
|
||||
// DecodeVarint reads a varint-encoded integer from the slice.
|
||||
// It returns the integer and the number of bytes consumed, or
|
||||
// zero if there is not enough.
|
||||
@ -192,7 +186,6 @@ func (p *Buffer) DecodeVarint() (x uint64, err error) {
|
||||
if b&0x80 == 0 {
|
||||
goto done
|
||||
}
|
||||
// x -= 0x80 << 63 // Always zero.
|
||||
|
||||
return 0, errOverflow
|
||||
|
||||
@ -267,9 +260,6 @@ func (p *Buffer) DecodeZigzag32() (x uint64, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// These are not ValueDecoders: they produce an array of bytes or a string.
|
||||
// bytes, embedded messages
|
||||
|
||||
// DecodeRawBytes reads a count-delimited byte buffer from the Buffer.
|
||||
// This is the format used for the bytes protocol buffer
|
||||
// type and for embedded messages.
|
||||
@ -311,81 +301,29 @@ func (p *Buffer) DecodeStringBytes() (s string, err error) {
|
||||
return string(buf), nil
|
||||
}
|
||||
|
||||
// Skip the next item in the buffer. Its wire type is decoded and presented as an argument.
|
||||
// If the protocol buffer has extensions, and the field matches, add it as an extension.
|
||||
// Otherwise, if the XXX_unrecognized field exists, append the skipped data there.
|
||||
func (o *Buffer) skipAndSave(t reflect.Type, tag, wire int, base structPointer, unrecField field) error {
|
||||
oi := o.index
|
||||
|
||||
err := o.skip(t, tag, wire)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !unrecField.IsValid() {
|
||||
return nil
|
||||
}
|
||||
|
||||
ptr := structPointer_Bytes(base, unrecField)
|
||||
|
||||
// Add the skipped field to struct field
|
||||
obuf := o.buf
|
||||
|
||||
o.buf = *ptr
|
||||
o.EncodeVarint(uint64(tag<<3 | wire))
|
||||
*ptr = append(o.buf, obuf[oi:o.index]...)
|
||||
|
||||
o.buf = obuf
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Skip the next item in the buffer. Its wire type is decoded and presented as an argument.
|
||||
func (o *Buffer) skip(t reflect.Type, tag, wire int) error {
|
||||
|
||||
var u uint64
|
||||
var err error
|
||||
|
||||
switch wire {
|
||||
case WireVarint:
|
||||
_, err = o.DecodeVarint()
|
||||
case WireFixed64:
|
||||
_, err = o.DecodeFixed64()
|
||||
case WireBytes:
|
||||
_, err = o.DecodeRawBytes(false)
|
||||
case WireFixed32:
|
||||
_, err = o.DecodeFixed32()
|
||||
case WireStartGroup:
|
||||
for {
|
||||
u, err = o.DecodeVarint()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
fwire := int(u & 0x7)
|
||||
if fwire == WireEndGroup {
|
||||
break
|
||||
}
|
||||
ftag := int(u >> 3)
|
||||
err = o.skip(t, ftag, fwire)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
default:
|
||||
err = fmt.Errorf("proto: can't skip unknown wire type %d for %s", wire, t)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// Unmarshaler is the interface representing objects that can
|
||||
// unmarshal themselves. The method should reset the receiver before
|
||||
// decoding starts. The argument points to data that may be
|
||||
// unmarshal themselves. The argument points to data that may be
|
||||
// overwritten, so implementations should not keep references to the
|
||||
// buffer.
|
||||
// Unmarshal implementations should not clear the receiver.
|
||||
// Any unmarshaled data should be merged into the receiver.
|
||||
// Callers of Unmarshal that do not want to retain existing data
|
||||
// should Reset the receiver before calling Unmarshal.
|
||||
type Unmarshaler interface {
|
||||
Unmarshal([]byte) error
|
||||
}
|
||||
|
||||
// newUnmarshaler is the interface representing objects that can
|
||||
// unmarshal themselves. The semantics are identical to Unmarshaler.
|
||||
//
|
||||
// This exists to support protoc-gen-go generated messages.
|
||||
// The proto package will stop type-asserting to this interface in the future.
|
||||
//
|
||||
// DO NOT DEPEND ON THIS.
|
||||
type newUnmarshaler interface {
|
||||
XXX_Unmarshal([]byte) error
|
||||
}
|
||||
|
||||
// Unmarshal parses the protocol buffer representation in buf and places the
|
||||
// decoded result in pb. If the struct underlying pb does not match
|
||||
// the data in buf, the results can be unpredictable.
|
||||
@ -395,7 +333,13 @@ type Unmarshaler interface {
|
||||
// to preserve and append to existing data.
|
||||
func Unmarshal(buf []byte, pb Message) error {
|
||||
pb.Reset()
|
||||
return UnmarshalMerge(buf, pb)
|
||||
if u, ok := pb.(newUnmarshaler); ok {
|
||||
return u.XXX_Unmarshal(buf)
|
||||
}
|
||||
if u, ok := pb.(Unmarshaler); ok {
|
||||
return u.Unmarshal(buf)
|
||||
}
|
||||
return NewBuffer(buf).Unmarshal(pb)
|
||||
}
|
||||
|
||||
// UnmarshalMerge parses the protocol buffer representation in buf and
|
||||
@ -405,8 +349,16 @@ func Unmarshal(buf []byte, pb Message) error {
|
||||
// UnmarshalMerge merges into existing data in pb.
|
||||
// Most code should use Unmarshal instead.
|
||||
func UnmarshalMerge(buf []byte, pb Message) error {
|
||||
// If the object can unmarshal itself, let it.
|
||||
if u, ok := pb.(newUnmarshaler); ok {
|
||||
return u.XXX_Unmarshal(buf)
|
||||
}
|
||||
if u, ok := pb.(Unmarshaler); ok {
|
||||
// NOTE: The history of proto have unfortunately been inconsistent
|
||||
// whether Unmarshaler should or should not implicitly clear itself.
|
||||
// Some implementations do, most do not.
|
||||
// Thus, calling this here may or may not do what people want.
|
||||
//
|
||||
// See https://github.com/golang/protobuf/issues/424
|
||||
return u.Unmarshal(buf)
|
||||
}
|
||||
return NewBuffer(buf).Unmarshal(pb)
|
||||
@ -422,12 +374,17 @@ func (p *Buffer) DecodeMessage(pb Message) error {
|
||||
}
|
||||
|
||||
// DecodeGroup reads a tag-delimited group from the Buffer.
|
||||
// StartGroup tag is already consumed. This function consumes
|
||||
// EndGroup tag.
|
||||
func (p *Buffer) DecodeGroup(pb Message) error {
|
||||
typ, base, err := getbase(pb)
|
||||
if err != nil {
|
||||
return err
|
||||
b := p.buf[p.index:]
|
||||
x, y := findEndGroup(b)
|
||||
if x < 0 {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return p.unmarshalType(typ.Elem(), GetProperties(typ.Elem()), true, base)
|
||||
err := Unmarshal(b[:x], pb)
|
||||
p.index += y
|
||||
return err
|
||||
}
|
||||
|
||||
// Unmarshal parses the protocol buffer representation in the
|
||||
@ -438,533 +395,33 @@ func (p *Buffer) DecodeGroup(pb Message) error {
|
||||
// Unlike proto.Unmarshal, this does not reset pb before starting to unmarshal.
|
||||
func (p *Buffer) Unmarshal(pb Message) error {
|
||||
// If the object can unmarshal itself, let it.
|
||||
if u, ok := pb.(newUnmarshaler); ok {
|
||||
err := u.XXX_Unmarshal(p.buf[p.index:])
|
||||
p.index = len(p.buf)
|
||||
return err
|
||||
}
|
||||
if u, ok := pb.(Unmarshaler); ok {
|
||||
// NOTE: The history of proto have unfortunately been inconsistent
|
||||
// whether Unmarshaler should or should not implicitly clear itself.
|
||||
// Some implementations do, most do not.
|
||||
// Thus, calling this here may or may not do what people want.
|
||||
//
|
||||
// See https://github.com/golang/protobuf/issues/424
|
||||
err := u.Unmarshal(p.buf[p.index:])
|
||||
p.index = len(p.buf)
|
||||
return err
|
||||
}
|
||||
|
||||
typ, base, err := getbase(pb)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = p.unmarshalType(typ.Elem(), GetProperties(typ.Elem()), false, base)
|
||||
|
||||
if collectStats {
|
||||
stats.Decode++
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// unmarshalType does the work of unmarshaling a structure.
|
||||
func (o *Buffer) unmarshalType(st reflect.Type, prop *StructProperties, is_group bool, base structPointer) error {
|
||||
var state errorState
|
||||
required, reqFields := prop.reqCount, uint64(0)
|
||||
|
||||
var err error
|
||||
for err == nil && o.index < len(o.buf) {
|
||||
oi := o.index
|
||||
var u uint64
|
||||
u, err = o.DecodeVarint()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
wire := int(u & 0x7)
|
||||
if wire == WireEndGroup {
|
||||
if is_group {
|
||||
if required > 0 {
|
||||
// Not enough information to determine the exact field.
|
||||
// (See below.)
|
||||
return &RequiredNotSetError{"{Unknown}"}
|
||||
}
|
||||
return nil // input is satisfied
|
||||
}
|
||||
return fmt.Errorf("proto: %s: wiretype end group for non-group", st)
|
||||
}
|
||||
tag := int(u >> 3)
|
||||
if tag <= 0 {
|
||||
return fmt.Errorf("proto: %s: illegal tag %d (wire type %d)", st, tag, wire)
|
||||
}
|
||||
fieldnum, ok := prop.decoderTags.get(tag)
|
||||
if !ok {
|
||||
// Maybe it's an extension?
|
||||
if prop.extendable {
|
||||
if e, _ := extendable(structPointer_Interface(base, st)); isExtensionField(e, int32(tag)) {
|
||||
if err = o.skip(st, tag, wire); err == nil {
|
||||
extmap := e.extensionsWrite()
|
||||
ext := extmap[int32(tag)] // may be missing
|
||||
ext.enc = append(ext.enc, o.buf[oi:o.index]...)
|
||||
extmap[int32(tag)] = ext
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
// Maybe it's a oneof?
|
||||
if prop.oneofUnmarshaler != nil {
|
||||
m := structPointer_Interface(base, st).(Message)
|
||||
// First return value indicates whether tag is a oneof field.
|
||||
ok, err = prop.oneofUnmarshaler(m, tag, wire, o)
|
||||
if err == ErrInternalBadWireType {
|
||||
// Map the error to something more descriptive.
|
||||
// Do the formatting here to save generated code space.
|
||||
err = fmt.Errorf("bad wiretype for oneof field in %T", m)
|
||||
}
|
||||
if ok {
|
||||
continue
|
||||
}
|
||||
}
|
||||
err = o.skipAndSave(st, tag, wire, base, prop.unrecField)
|
||||
continue
|
||||
}
|
||||
p := prop.Prop[fieldnum]
|
||||
|
||||
if p.dec == nil {
|
||||
fmt.Fprintf(os.Stderr, "proto: no protobuf decoder for %s.%s\n", st, st.Field(fieldnum).Name)
|
||||
continue
|
||||
}
|
||||
dec := p.dec
|
||||
if wire != WireStartGroup && wire != p.WireType {
|
||||
if wire == WireBytes && p.packedDec != nil {
|
||||
// a packable field
|
||||
dec = p.packedDec
|
||||
} else {
|
||||
err = fmt.Errorf("proto: bad wiretype for field %s.%s: got wiretype %d, want %d", st, st.Field(fieldnum).Name, wire, p.WireType)
|
||||
continue
|
||||
}
|
||||
}
|
||||
decErr := dec(o, p, base)
|
||||
if decErr != nil && !state.shouldContinue(decErr, p) {
|
||||
err = decErr
|
||||
}
|
||||
if err == nil && p.Required {
|
||||
// Successfully decoded a required field.
|
||||
if tag <= 64 {
|
||||
// use bitmap for fields 1-64 to catch field reuse.
|
||||
var mask uint64 = 1 << uint64(tag-1)
|
||||
if reqFields&mask == 0 {
|
||||
// new required field
|
||||
reqFields |= mask
|
||||
required--
|
||||
}
|
||||
} else {
|
||||
// This is imprecise. It can be fooled by a required field
|
||||
// with a tag > 64 that is encoded twice; that's very rare.
|
||||
// A fully correct implementation would require allocating
|
||||
// a data structure, which we would like to avoid.
|
||||
required--
|
||||
}
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
if is_group {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
if state.err != nil {
|
||||
return state.err
|
||||
}
|
||||
if required > 0 {
|
||||
// Not enough information to determine the exact field. If we use extra
|
||||
// CPU, we could determine the field only if the missing required field
|
||||
// has a tag <= 64 and we check reqFields.
|
||||
return &RequiredNotSetError{"{Unknown}"}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// Individual type decoders
|
||||
// For each,
|
||||
// u is the decoded value,
|
||||
// v is a pointer to the field (pointer) in the struct
|
||||
|
||||
// Sizes of the pools to allocate inside the Buffer.
|
||||
// The goal is modest amortization and allocation
|
||||
// on at least 16-byte boundaries.
|
||||
const (
|
||||
boolPoolSize = 16
|
||||
uint32PoolSize = 8
|
||||
uint64PoolSize = 4
|
||||
)
|
||||
|
||||
// Decode a bool.
|
||||
func (o *Buffer) dec_bool(p *Properties, base structPointer) error {
|
||||
u, err := p.valDec(o)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(o.bools) == 0 {
|
||||
o.bools = make([]bool, boolPoolSize)
|
||||
}
|
||||
o.bools[0] = u != 0
|
||||
*structPointer_Bool(base, p.field) = &o.bools[0]
|
||||
o.bools = o.bools[1:]
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Buffer) dec_proto3_bool(p *Properties, base structPointer) error {
|
||||
u, err := p.valDec(o)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*structPointer_BoolVal(base, p.field) = u != 0
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode an int32.
|
||||
func (o *Buffer) dec_int32(p *Properties, base structPointer) error {
|
||||
u, err := p.valDec(o)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
word32_Set(structPointer_Word32(base, p.field), o, uint32(u))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Buffer) dec_proto3_int32(p *Properties, base structPointer) error {
|
||||
u, err := p.valDec(o)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
word32Val_Set(structPointer_Word32Val(base, p.field), uint32(u))
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode an int64.
|
||||
func (o *Buffer) dec_int64(p *Properties, base structPointer) error {
|
||||
u, err := p.valDec(o)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
word64_Set(structPointer_Word64(base, p.field), o, u)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Buffer) dec_proto3_int64(p *Properties, base structPointer) error {
|
||||
u, err := p.valDec(o)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
word64Val_Set(structPointer_Word64Val(base, p.field), o, u)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode a string.
|
||||
func (o *Buffer) dec_string(p *Properties, base structPointer) error {
|
||||
s, err := o.DecodeStringBytes()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*structPointer_String(base, p.field) = &s
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Buffer) dec_proto3_string(p *Properties, base structPointer) error {
|
||||
s, err := o.DecodeStringBytes()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*structPointer_StringVal(base, p.field) = s
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode a slice of bytes ([]byte).
|
||||
func (o *Buffer) dec_slice_byte(p *Properties, base structPointer) error {
|
||||
b, err := o.DecodeRawBytes(true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*structPointer_Bytes(base, p.field) = b
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode a slice of bools ([]bool).
|
||||
func (o *Buffer) dec_slice_bool(p *Properties, base structPointer) error {
|
||||
u, err := p.valDec(o)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v := structPointer_BoolSlice(base, p.field)
|
||||
*v = append(*v, u != 0)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode a slice of bools ([]bool) in packed format.
|
||||
func (o *Buffer) dec_slice_packed_bool(p *Properties, base structPointer) error {
|
||||
v := structPointer_BoolSlice(base, p.field)
|
||||
|
||||
nn, err := o.DecodeVarint()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
nb := int(nn) // number of bytes of encoded bools
|
||||
fin := o.index + nb
|
||||
if fin < o.index {
|
||||
return errOverflow
|
||||
}
|
||||
|
||||
y := *v
|
||||
for o.index < fin {
|
||||
u, err := p.valDec(o)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
y = append(y, u != 0)
|
||||
}
|
||||
|
||||
*v = y
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode a slice of int32s ([]int32).
|
||||
func (o *Buffer) dec_slice_int32(p *Properties, base structPointer) error {
|
||||
u, err := p.valDec(o)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
structPointer_Word32Slice(base, p.field).Append(uint32(u))
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode a slice of int32s ([]int32) in packed format.
|
||||
func (o *Buffer) dec_slice_packed_int32(p *Properties, base structPointer) error {
|
||||
v := structPointer_Word32Slice(base, p.field)
|
||||
|
||||
nn, err := o.DecodeVarint()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
nb := int(nn) // number of bytes of encoded int32s
|
||||
|
||||
fin := o.index + nb
|
||||
if fin < o.index {
|
||||
return errOverflow
|
||||
}
|
||||
for o.index < fin {
|
||||
u, err := p.valDec(o)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v.Append(uint32(u))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode a slice of int64s ([]int64).
|
||||
func (o *Buffer) dec_slice_int64(p *Properties, base structPointer) error {
|
||||
u, err := p.valDec(o)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
structPointer_Word64Slice(base, p.field).Append(u)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode a slice of int64s ([]int64) in packed format.
|
||||
func (o *Buffer) dec_slice_packed_int64(p *Properties, base structPointer) error {
|
||||
v := structPointer_Word64Slice(base, p.field)
|
||||
|
||||
nn, err := o.DecodeVarint()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
nb := int(nn) // number of bytes of encoded int64s
|
||||
|
||||
fin := o.index + nb
|
||||
if fin < o.index {
|
||||
return errOverflow
|
||||
}
|
||||
for o.index < fin {
|
||||
u, err := p.valDec(o)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v.Append(u)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode a slice of strings ([]string).
|
||||
func (o *Buffer) dec_slice_string(p *Properties, base structPointer) error {
|
||||
s, err := o.DecodeStringBytes()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v := structPointer_StringSlice(base, p.field)
|
||||
*v = append(*v, s)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode a slice of slice of bytes ([][]byte).
|
||||
func (o *Buffer) dec_slice_slice_byte(p *Properties, base structPointer) error {
|
||||
b, err := o.DecodeRawBytes(true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v := structPointer_BytesSlice(base, p.field)
|
||||
*v = append(*v, b)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode a map field.
|
||||
func (o *Buffer) dec_new_map(p *Properties, base structPointer) error {
|
||||
raw, err := o.DecodeRawBytes(false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
oi := o.index // index at the end of this map entry
|
||||
o.index -= len(raw) // move buffer back to start of map entry
|
||||
|
||||
mptr := structPointer_NewAt(base, p.field, p.mtype) // *map[K]V
|
||||
if mptr.Elem().IsNil() {
|
||||
mptr.Elem().Set(reflect.MakeMap(mptr.Type().Elem()))
|
||||
}
|
||||
v := mptr.Elem() // map[K]V
|
||||
|
||||
// Prepare addressable doubly-indirect placeholders for the key and value types.
|
||||
// See enc_new_map for why.
|
||||
keyptr := reflect.New(reflect.PtrTo(p.mtype.Key())).Elem() // addressable *K
|
||||
keybase := toStructPointer(keyptr.Addr()) // **K
|
||||
|
||||
var valbase structPointer
|
||||
var valptr reflect.Value
|
||||
switch p.mtype.Elem().Kind() {
|
||||
case reflect.Slice:
|
||||
// []byte
|
||||
var dummy []byte
|
||||
valptr = reflect.ValueOf(&dummy) // *[]byte
|
||||
valbase = toStructPointer(valptr) // *[]byte
|
||||
case reflect.Ptr:
|
||||
// message; valptr is **Msg; need to allocate the intermediate pointer
|
||||
valptr = reflect.New(reflect.PtrTo(p.mtype.Elem())).Elem() // addressable *V
|
||||
valptr.Set(reflect.New(valptr.Type().Elem()))
|
||||
valbase = toStructPointer(valptr)
|
||||
default:
|
||||
// everything else
|
||||
valptr = reflect.New(reflect.PtrTo(p.mtype.Elem())).Elem() // addressable *V
|
||||
valbase = toStructPointer(valptr.Addr()) // **V
|
||||
}
|
||||
|
||||
// Decode.
|
||||
// This parses a restricted wire format, namely the encoding of a message
|
||||
// with two fields. See enc_new_map for the format.
|
||||
for o.index < oi {
|
||||
// tagcode for key and value properties are always a single byte
|
||||
// because they have tags 1 and 2.
|
||||
tagcode := o.buf[o.index]
|
||||
o.index++
|
||||
switch tagcode {
|
||||
case p.mkeyprop.tagcode[0]:
|
||||
if err := p.mkeyprop.dec(o, p.mkeyprop, keybase); err != nil {
|
||||
return err
|
||||
}
|
||||
case p.mvalprop.tagcode[0]:
|
||||
if err := p.mvalprop.dec(o, p.mvalprop, valbase); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
// TODO: Should we silently skip this instead?
|
||||
return fmt.Errorf("proto: bad map data tag %d", raw[0])
|
||||
}
|
||||
}
|
||||
keyelem, valelem := keyptr.Elem(), valptr.Elem()
|
||||
if !keyelem.IsValid() {
|
||||
keyelem = reflect.Zero(p.mtype.Key())
|
||||
}
|
||||
if !valelem.IsValid() {
|
||||
valelem = reflect.Zero(p.mtype.Elem())
|
||||
}
|
||||
|
||||
v.SetMapIndex(keyelem, valelem)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Decode a group.
|
||||
func (o *Buffer) dec_struct_group(p *Properties, base structPointer) error {
|
||||
bas := structPointer_GetStructPointer(base, p.field)
|
||||
if structPointer_IsNil(bas) {
|
||||
// allocate new nested message
|
||||
bas = toStructPointer(reflect.New(p.stype))
|
||||
structPointer_SetStructPointer(base, p.field, bas)
|
||||
}
|
||||
return o.unmarshalType(p.stype, p.sprop, true, bas)
|
||||
}
|
||||
|
||||
// Decode an embedded message.
|
||||
func (o *Buffer) dec_struct_message(p *Properties, base structPointer) (err error) {
|
||||
raw, e := o.DecodeRawBytes(false)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
|
||||
bas := structPointer_GetStructPointer(base, p.field)
|
||||
if structPointer_IsNil(bas) {
|
||||
// allocate new nested message
|
||||
bas = toStructPointer(reflect.New(p.stype))
|
||||
structPointer_SetStructPointer(base, p.field, bas)
|
||||
}
|
||||
|
||||
// If the object can unmarshal itself, let it.
|
||||
if p.isUnmarshaler {
|
||||
iv := structPointer_Interface(bas, p.stype)
|
||||
return iv.(Unmarshaler).Unmarshal(raw)
|
||||
}
|
||||
|
||||
obuf := o.buf
|
||||
oi := o.index
|
||||
o.buf = raw
|
||||
o.index = 0
|
||||
|
||||
err = o.unmarshalType(p.stype, p.sprop, false, bas)
|
||||
o.buf = obuf
|
||||
o.index = oi
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Decode a slice of embedded messages.
|
||||
func (o *Buffer) dec_slice_struct_message(p *Properties, base structPointer) error {
|
||||
return o.dec_slice_struct(p, false, base)
|
||||
}
|
||||
|
||||
// Decode a slice of embedded groups.
|
||||
func (o *Buffer) dec_slice_struct_group(p *Properties, base structPointer) error {
|
||||
return o.dec_slice_struct(p, true, base)
|
||||
}
|
||||
|
||||
// Decode a slice of structs ([]*struct).
|
||||
func (o *Buffer) dec_slice_struct(p *Properties, is_group bool, base structPointer) error {
|
||||
v := reflect.New(p.stype)
|
||||
bas := toStructPointer(v)
|
||||
structPointer_StructPointerSlice(base, p.field).Append(bas)
|
||||
|
||||
if is_group {
|
||||
err := o.unmarshalType(p.stype, p.sprop, is_group, bas)
|
||||
return err
|
||||
}
|
||||
|
||||
raw, err := o.DecodeRawBytes(false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// If the object can unmarshal itself, let it.
|
||||
if p.isUnmarshaler {
|
||||
iv := v.Interface()
|
||||
return iv.(Unmarshaler).Unmarshal(raw)
|
||||
}
|
||||
|
||||
obuf := o.buf
|
||||
oi := o.index
|
||||
o.buf = raw
|
||||
o.index = 0
|
||||
|
||||
err = o.unmarshalType(p.stype, p.sprop, is_group, bas)
|
||||
|
||||
o.buf = obuf
|
||||
o.index = oi
|
||||
|
||||
// Slow workaround for messages that aren't Unmarshalers.
|
||||
// This includes some hand-coded .pb.go files and
|
||||
// bootstrap protos.
|
||||
// TODO: fix all of those and then add Unmarshal to
|
||||
// the Message interface. Then:
|
||||
// The cast above and code below can be deleted.
|
||||
// The old unmarshaler can be deleted.
|
||||
// Clients can call Unmarshal directly (can already do that, actually).
|
||||
var info InternalMessageInfo
|
||||
err := info.Unmarshal(pb, p.buf[p.index:])
|
||||
p.index = len(p.buf)
|
||||
return err
|
||||
}
|
||||
|
5
vendor/github.com/golang/protobuf/proto/decode_test.go
generated
vendored
5
vendor/github.com/golang/protobuf/proto/decode_test.go
generated
vendored
@ -41,10 +41,7 @@ import (
|
||||
tpb "github.com/golang/protobuf/proto/proto3_proto"
|
||||
)
|
||||
|
||||
var (
|
||||
bytesBlackhole []byte
|
||||
msgBlackhole = new(tpb.Message)
|
||||
)
|
||||
var msgBlackhole = new(tpb.Message)
|
||||
|
||||
// BenchmarkVarint32ArraySmall shows the performance on an array of small int32 fields (1 and
|
||||
// 2 bytes long).
|
||||
|
63
vendor/github.com/golang/protobuf/proto/deprecated.go
generated
vendored
Normal file
63
vendor/github.com/golang/protobuf/proto/deprecated.go
generated
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
// Go support for Protocol Buffers - Google's data interchange format
|
||||
//
|
||||
// Copyright 2018 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 "errors"
|
||||
|
||||
// Deprecated: do not use.
|
||||
type Stats struct{ Emalloc, Dmalloc, Encode, Decode, Chit, Cmiss, Size uint64 }
|
||||
|
||||
// Deprecated: do not use.
|
||||
func GetStats() Stats { return Stats{} }
|
||||
|
||||
// Deprecated: do not use.
|
||||
func MarshalMessageSet(interface{}) ([]byte, error) {
|
||||
return nil, errors.New("proto: not implemented")
|
||||
}
|
||||
|
||||
// Deprecated: do not use.
|
||||
func UnmarshalMessageSet([]byte, interface{}) error {
|
||||
return errors.New("proto: not implemented")
|
||||
}
|
||||
|
||||
// Deprecated: do not use.
|
||||
func MarshalMessageSetJSON(interface{}) ([]byte, error) {
|
||||
return nil, errors.New("proto: not implemented")
|
||||
}
|
||||
|
||||
// Deprecated: do not use.
|
||||
func UnmarshalMessageSetJSON([]byte, interface{}) error {
|
||||
return errors.New("proto: not implemented")
|
||||
}
|
||||
|
||||
// Deprecated: do not use.
|
||||
func RegisterMessageSetType(Message, int32, string) {}
|
350
vendor/github.com/golang/protobuf/proto/discard.go
generated
vendored
Normal file
350
vendor/github.com/golang/protobuf/proto/discard.go
generated
vendored
Normal file
@ -0,0 +1,350 @@
|
||||
// Go support for Protocol Buffers - Google's data interchange format
|
||||
//
|
||||
// Copyright 2017 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 (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
type generatedDiscarder interface {
|
||||
XXX_DiscardUnknown()
|
||||
}
|
||||
|
||||
// DiscardUnknown recursively discards all unknown fields from this message
|
||||
// and all embedded messages.
|
||||
//
|
||||
// When unmarshaling a message with unrecognized fields, the tags and values
|
||||
// of such fields are preserved in the Message. This allows a later call to
|
||||
// marshal to be able to produce a message that continues to have those
|
||||
// unrecognized fields. To avoid this, DiscardUnknown is used to
|
||||
// explicitly clear the unknown fields after unmarshaling.
|
||||
//
|
||||
// For proto2 messages, the unknown fields of message extensions are only
|
||||
// discarded from messages that have been accessed via GetExtension.
|
||||
func DiscardUnknown(m Message) {
|
||||
if m, ok := m.(generatedDiscarder); ok {
|
||||
m.XXX_DiscardUnknown()
|
||||
return
|
||||
}
|
||||
// TODO: Dynamically populate a InternalMessageInfo for legacy messages,
|
||||
// but the master branch has no implementation for InternalMessageInfo,
|
||||
// so it would be more work to replicate that approach.
|
||||
discardLegacy(m)
|
||||
}
|
||||
|
||||
// DiscardUnknown recursively discards all unknown fields.
|
||||
func (a *InternalMessageInfo) DiscardUnknown(m Message) {
|
||||
di := atomicLoadDiscardInfo(&a.discard)
|
||||
if di == nil {
|
||||
di = getDiscardInfo(reflect.TypeOf(m).Elem())
|
||||
atomicStoreDiscardInfo(&a.discard, di)
|
||||
}
|
||||
di.discard(toPointer(&m))
|
||||
}
|
||||
|
||||
type discardInfo struct {
|
||||
typ reflect.Type
|
||||
|
||||
initialized int32 // 0: only typ is valid, 1: everything is valid
|
||||
lock sync.Mutex
|
||||
|
||||
fields []discardFieldInfo
|
||||
unrecognized field
|
||||
}
|
||||
|
||||
type discardFieldInfo struct {
|
||||
field field // Offset of field, guaranteed to be valid
|
||||
discard func(src pointer)
|
||||
}
|
||||
|
||||
var (
|
||||
discardInfoMap = map[reflect.Type]*discardInfo{}
|
||||
discardInfoLock sync.Mutex
|
||||
)
|
||||
|
||||
func getDiscardInfo(t reflect.Type) *discardInfo {
|
||||
discardInfoLock.Lock()
|
||||
defer discardInfoLock.Unlock()
|
||||
di := discardInfoMap[t]
|
||||
if di == nil {
|
||||
di = &discardInfo{typ: t}
|
||||
discardInfoMap[t] = di
|
||||
}
|
||||
return di
|
||||
}
|
||||
|
||||
func (di *discardInfo) discard(src pointer) {
|
||||
if src.isNil() {
|
||||
return // Nothing to do.
|
||||
}
|
||||
|
||||
if atomic.LoadInt32(&di.initialized) == 0 {
|
||||
di.computeDiscardInfo()
|
||||
}
|
||||
|
||||
for _, fi := range di.fields {
|
||||
sfp := src.offset(fi.field)
|
||||
fi.discard(sfp)
|
||||
}
|
||||
|
||||
// For proto2 messages, only discard unknown fields in message extensions
|
||||
// that have been accessed via GetExtension.
|
||||
if em, err := extendable(src.asPointerTo(di.typ).Interface()); err == nil {
|
||||
// Ignore lock since DiscardUnknown is not concurrency safe.
|
||||
emm, _ := em.extensionsRead()
|
||||
for _, mx := range emm {
|
||||
if m, ok := mx.value.(Message); ok {
|
||||
DiscardUnknown(m)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if di.unrecognized.IsValid() {
|
||||
*src.offset(di.unrecognized).toBytes() = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (di *discardInfo) computeDiscardInfo() {
|
||||
di.lock.Lock()
|
||||
defer di.lock.Unlock()
|
||||
if di.initialized != 0 {
|
||||
return
|
||||
}
|
||||
t := di.typ
|
||||
n := t.NumField()
|
||||
|
||||
for i := 0; i < n; i++ {
|
||||
f := t.Field(i)
|
||||
if strings.HasPrefix(f.Name, "XXX_") {
|
||||
continue
|
||||
}
|
||||
|
||||
dfi := discardFieldInfo{field: toField(&f)}
|
||||
tf := f.Type
|
||||
|
||||
// Unwrap tf to get its most basic type.
|
||||
var isPointer, isSlice bool
|
||||
if tf.Kind() == reflect.Slice && tf.Elem().Kind() != reflect.Uint8 {
|
||||
isSlice = true
|
||||
tf = tf.Elem()
|
||||
}
|
||||
if tf.Kind() == reflect.Ptr {
|
||||
isPointer = true
|
||||
tf = tf.Elem()
|
||||
}
|
||||
if isPointer && isSlice && tf.Kind() != reflect.Struct {
|
||||
panic(fmt.Sprintf("%v.%s cannot be a slice of pointers to primitive types", t, f.Name))
|
||||
}
|
||||
|
||||
switch tf.Kind() {
|
||||
case reflect.Struct:
|
||||
switch {
|
||||
case !isPointer:
|
||||
panic(fmt.Sprintf("%v.%s cannot be a direct struct value", t, f.Name))
|
||||
case isSlice: // E.g., []*pb.T
|
||||
di := getDiscardInfo(tf)
|
||||
dfi.discard = func(src pointer) {
|
||||
sps := src.getPointerSlice()
|
||||
for _, sp := range sps {
|
||||
if !sp.isNil() {
|
||||
di.discard(sp)
|
||||
}
|
||||
}
|
||||
}
|
||||
default: // E.g., *pb.T
|
||||
di := getDiscardInfo(tf)
|
||||
dfi.discard = func(src pointer) {
|
||||
sp := src.getPointer()
|
||||
if !sp.isNil() {
|
||||
di.discard(sp)
|
||||
}
|
||||
}
|
||||
}
|
||||
case reflect.Map:
|
||||
switch {
|
||||
case isPointer || isSlice:
|
||||
panic(fmt.Sprintf("%v.%s cannot be a pointer to a map or a slice of map values", t, f.Name))
|
||||
default: // E.g., map[K]V
|
||||
if tf.Elem().Kind() == reflect.Ptr { // Proto struct (e.g., *T)
|
||||
dfi.discard = func(src pointer) {
|
||||
sm := src.asPointerTo(tf).Elem()
|
||||
if sm.Len() == 0 {
|
||||
return
|
||||
}
|
||||
for _, key := range sm.MapKeys() {
|
||||
val := sm.MapIndex(key)
|
||||
DiscardUnknown(val.Interface().(Message))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dfi.discard = func(pointer) {} // Noop
|
||||
}
|
||||
}
|
||||
case reflect.Interface:
|
||||
// Must be oneof field.
|
||||
switch {
|
||||
case isPointer || isSlice:
|
||||
panic(fmt.Sprintf("%v.%s cannot be a pointer to a interface or a slice of interface values", t, f.Name))
|
||||
default: // E.g., interface{}
|
||||
// TODO: Make this faster?
|
||||
dfi.discard = func(src pointer) {
|
||||
su := src.asPointerTo(tf).Elem()
|
||||
if !su.IsNil() {
|
||||
sv := su.Elem().Elem().Field(0)
|
||||
if sv.Kind() == reflect.Ptr && sv.IsNil() {
|
||||
return
|
||||
}
|
||||
switch sv.Type().Kind() {
|
||||
case reflect.Ptr: // Proto struct (e.g., *T)
|
||||
DiscardUnknown(sv.Interface().(Message))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
continue
|
||||
}
|
||||
di.fields = append(di.fields, dfi)
|
||||
}
|
||||
|
||||
di.unrecognized = invalidField
|
||||
if f, ok := t.FieldByName("XXX_unrecognized"); ok {
|
||||
if f.Type != reflect.TypeOf([]byte{}) {
|
||||
panic("expected XXX_unrecognized to be of type []byte")
|
||||
}
|
||||
di.unrecognized = toField(&f)
|
||||
}
|
||||
|
||||
atomic.StoreInt32(&di.initialized, 1)
|
||||
}
|
||||
|
||||
func discardLegacy(m Message) {
|
||||
v := reflect.ValueOf(m)
|
||||
if v.Kind() != reflect.Ptr || v.IsNil() {
|
||||
return
|
||||
}
|
||||
v = v.Elem()
|
||||
if v.Kind() != reflect.Struct {
|
||||
return
|
||||
}
|
||||
t := v.Type()
|
||||
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
f := t.Field(i)
|
||||
if strings.HasPrefix(f.Name, "XXX_") {
|
||||
continue
|
||||
}
|
||||
vf := v.Field(i)
|
||||
tf := f.Type
|
||||
|
||||
// Unwrap tf to get its most basic type.
|
||||
var isPointer, isSlice bool
|
||||
if tf.Kind() == reflect.Slice && tf.Elem().Kind() != reflect.Uint8 {
|
||||
isSlice = true
|
||||
tf = tf.Elem()
|
||||
}
|
||||
if tf.Kind() == reflect.Ptr {
|
||||
isPointer = true
|
||||
tf = tf.Elem()
|
||||
}
|
||||
if isPointer && isSlice && tf.Kind() != reflect.Struct {
|
||||
panic(fmt.Sprintf("%T.%s cannot be a slice of pointers to primitive types", m, f.Name))
|
||||
}
|
||||
|
||||
switch tf.Kind() {
|
||||
case reflect.Struct:
|
||||
switch {
|
||||
case !isPointer:
|
||||
panic(fmt.Sprintf("%T.%s cannot be a direct struct value", m, f.Name))
|
||||
case isSlice: // E.g., []*pb.T
|
||||
for j := 0; j < vf.Len(); j++ {
|
||||
discardLegacy(vf.Index(j).Interface().(Message))
|
||||
}
|
||||
default: // E.g., *pb.T
|
||||
discardLegacy(vf.Interface().(Message))
|
||||
}
|
||||
case reflect.Map:
|
||||
switch {
|
||||
case isPointer || isSlice:
|
||||
panic(fmt.Sprintf("%T.%s cannot be a pointer to a map or a slice of map values", m, f.Name))
|
||||
default: // E.g., map[K]V
|
||||
tv := vf.Type().Elem()
|
||||
if tv.Kind() == reflect.Ptr && tv.Implements(protoMessageType) { // Proto struct (e.g., *T)
|
||||
for _, key := range vf.MapKeys() {
|
||||
val := vf.MapIndex(key)
|
||||
discardLegacy(val.Interface().(Message))
|
||||
}
|
||||
}
|
||||
}
|
||||
case reflect.Interface:
|
||||
// Must be oneof field.
|
||||
switch {
|
||||
case isPointer || isSlice:
|
||||
panic(fmt.Sprintf("%T.%s cannot be a pointer to a interface or a slice of interface values", m, f.Name))
|
||||
default: // E.g., test_proto.isCommunique_Union interface
|
||||
if !vf.IsNil() && f.Tag.Get("protobuf_oneof") != "" {
|
||||
vf = vf.Elem() // E.g., *test_proto.Communique_Msg
|
||||
if !vf.IsNil() {
|
||||
vf = vf.Elem() // E.g., test_proto.Communique_Msg
|
||||
vf = vf.Field(0) // E.g., Proto struct (e.g., *T) or primitive value
|
||||
if vf.Kind() == reflect.Ptr {
|
||||
discardLegacy(vf.Interface().(Message))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if vf := v.FieldByName("XXX_unrecognized"); vf.IsValid() {
|
||||
if vf.Type() != reflect.TypeOf([]byte{}) {
|
||||
panic("expected XXX_unrecognized to be of type []byte")
|
||||
}
|
||||
vf.Set(reflect.ValueOf([]byte(nil)))
|
||||
}
|
||||
|
||||
// For proto2 messages, only discard unknown fields in message extensions
|
||||
// that have been accessed via GetExtension.
|
||||
if em, err := extendable(m); err == nil {
|
||||
// Ignore lock since discardLegacy is not concurrency safe.
|
||||
emm, _ := em.extensionsRead()
|
||||
for _, mx := range emm {
|
||||
if m, ok := mx.value.(Message); ok {
|
||||
discardLegacy(m)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
170
vendor/github.com/golang/protobuf/proto/discard_test.go
generated
vendored
Normal file
170
vendor/github.com/golang/protobuf/proto/discard_test.go
generated
vendored
Normal file
@ -0,0 +1,170 @@
|
||||
// Go support for Protocol Buffers - Google's data interchange format
|
||||
//
|
||||
// Copyright 2017 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/golang/protobuf/proto"
|
||||
|
||||
proto3pb "github.com/golang/protobuf/proto/proto3_proto"
|
||||
pb "github.com/golang/protobuf/proto/test_proto"
|
||||
)
|
||||
|
||||
func TestDiscardUnknown(t *testing.T) {
|
||||
tests := []struct {
|
||||
desc string
|
||||
in, want proto.Message
|
||||
}{{
|
||||
desc: "Nil",
|
||||
in: nil, want: nil, // Should not panic
|
||||
}, {
|
||||
desc: "NilPtr",
|
||||
in: (*proto3pb.Message)(nil), want: (*proto3pb.Message)(nil), // Should not panic
|
||||
}, {
|
||||
desc: "Nested",
|
||||
in: &proto3pb.Message{
|
||||
Name: "Aaron",
|
||||
Nested: &proto3pb.Nested{Cute: true, XXX_unrecognized: []byte("blah")},
|
||||
XXX_unrecognized: []byte("blah"),
|
||||
},
|
||||
want: &proto3pb.Message{
|
||||
Name: "Aaron",
|
||||
Nested: &proto3pb.Nested{Cute: true},
|
||||
},
|
||||
}, {
|
||||
desc: "Slice",
|
||||
in: &proto3pb.Message{
|
||||
Name: "Aaron",
|
||||
Children: []*proto3pb.Message{
|
||||
{Name: "Sarah", XXX_unrecognized: []byte("blah")},
|
||||
{Name: "Abraham", XXX_unrecognized: []byte("blah")},
|
||||
},
|
||||
XXX_unrecognized: []byte("blah"),
|
||||
},
|
||||
want: &proto3pb.Message{
|
||||
Name: "Aaron",
|
||||
Children: []*proto3pb.Message{
|
||||
{Name: "Sarah"},
|
||||
{Name: "Abraham"},
|
||||
},
|
||||
},
|
||||
}, {
|
||||
desc: "OneOf",
|
||||
in: &pb.Communique{
|
||||
Union: &pb.Communique_Msg{&pb.Strings{
|
||||
StringField: proto.String("123"),
|
||||
XXX_unrecognized: []byte("blah"),
|
||||
}},
|
||||
XXX_unrecognized: []byte("blah"),
|
||||
},
|
||||
want: &pb.Communique{
|
||||
Union: &pb.Communique_Msg{&pb.Strings{StringField: proto.String("123")}},
|
||||
},
|
||||
}, {
|
||||
desc: "Map",
|
||||
in: &pb.MessageWithMap{MsgMapping: map[int64]*pb.FloatingPoint{
|
||||
0x4002: &pb.FloatingPoint{
|
||||
Exact: proto.Bool(true),
|
||||
XXX_unrecognized: []byte("blah"),
|
||||
},
|
||||
}},
|
||||
want: &pb.MessageWithMap{MsgMapping: map[int64]*pb.FloatingPoint{
|
||||
0x4002: &pb.FloatingPoint{Exact: proto.Bool(true)},
|
||||
}},
|
||||
}, {
|
||||
desc: "Extension",
|
||||
in: func() proto.Message {
|
||||
m := &pb.MyMessage{
|
||||
Count: proto.Int32(42),
|
||||
Somegroup: &pb.MyMessage_SomeGroup{
|
||||
GroupField: proto.Int32(6),
|
||||
XXX_unrecognized: []byte("blah"),
|
||||
},
|
||||
XXX_unrecognized: []byte("blah"),
|
||||
}
|
||||
proto.SetExtension(m, pb.E_Ext_More, &pb.Ext{
|
||||
Data: proto.String("extension"),
|
||||
XXX_unrecognized: []byte("blah"),
|
||||
})
|
||||
return m
|
||||
}(),
|
||||
want: func() proto.Message {
|
||||
m := &pb.MyMessage{
|
||||
Count: proto.Int32(42),
|
||||
Somegroup: &pb.MyMessage_SomeGroup{GroupField: proto.Int32(6)},
|
||||
}
|
||||
proto.SetExtension(m, pb.E_Ext_More, &pb.Ext{Data: proto.String("extension")})
|
||||
return m
|
||||
}(),
|
||||
}}
|
||||
|
||||
// Test the legacy code path.
|
||||
for _, tt := range tests {
|
||||
// Clone the input so that we don't alter the original.
|
||||
in := tt.in
|
||||
if in != nil {
|
||||
in = proto.Clone(tt.in)
|
||||
}
|
||||
|
||||
var m LegacyMessage
|
||||
m.Message, _ = in.(*proto3pb.Message)
|
||||
m.Communique, _ = in.(*pb.Communique)
|
||||
m.MessageWithMap, _ = in.(*pb.MessageWithMap)
|
||||
m.MyMessage, _ = in.(*pb.MyMessage)
|
||||
proto.DiscardUnknown(&m)
|
||||
if !proto.Equal(in, tt.want) {
|
||||
t.Errorf("test %s/Legacy, expected unknown fields to be discarded\ngot %v\nwant %v", tt.desc, in, tt.want)
|
||||
}
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
proto.DiscardUnknown(tt.in)
|
||||
if !proto.Equal(tt.in, tt.want) {
|
||||
t.Errorf("test %s, expected unknown fields to be discarded\ngot %v\nwant %v", tt.desc, tt.in, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// LegacyMessage is a proto.Message that has several nested messages.
|
||||
// This does not have the XXX_DiscardUnknown method and so forces DiscardUnknown
|
||||
// to use the legacy fallback logic.
|
||||
type LegacyMessage struct {
|
||||
Message *proto3pb.Message
|
||||
Communique *pb.Communique
|
||||
MessageWithMap *pb.MessageWithMap
|
||||
MyMessage *pb.MyMessage
|
||||
}
|
||||
|
||||
func (m *LegacyMessage) Reset() { *m = LegacyMessage{} }
|
||||
func (m *LegacyMessage) String() string { return proto.CompactTextString(m) }
|
||||
func (*LegacyMessage) ProtoMessage() {}
|
1207
vendor/github.com/golang/protobuf/proto/encode.go
generated
vendored
1207
vendor/github.com/golang/protobuf/proto/encode.go
generated
vendored
File diff suppressed because it is too large
Load Diff
33
vendor/github.com/golang/protobuf/proto/equal.go
generated
vendored
33
vendor/github.com/golang/protobuf/proto/equal.go
generated
vendored
@ -109,15 +109,6 @@ func equalStruct(v1, v2 reflect.Value) bool {
|
||||
// set/unset mismatch
|
||||
return false
|
||||
}
|
||||
b1, ok := f1.Interface().(raw)
|
||||
if ok {
|
||||
b2 := f2.Interface().(raw)
|
||||
// RawMessage
|
||||
if !bytes.Equal(b1.Bytes(), b2.Bytes()) {
|
||||
return false
|
||||
}
|
||||
continue
|
||||
}
|
||||
f1, f2 = f1.Elem(), f2.Elem()
|
||||
}
|
||||
if !equalAny(f1, f2, sprop.Prop[i]) {
|
||||
@ -146,11 +137,7 @@ func equalStruct(v1, v2 reflect.Value) bool {
|
||||
|
||||
u1 := uf.Bytes()
|
||||
u2 := v2.FieldByName("XXX_unrecognized").Bytes()
|
||||
if !bytes.Equal(u1, u2) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
return bytes.Equal(u1, u2)
|
||||
}
|
||||
|
||||
// v1 and v2 are known to have the same type.
|
||||
@ -259,7 +246,17 @@ func equalExtMap(base reflect.Type, em1, em2 map[int32]Extension) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
m1, m2 := e1.value, e2.value
|
||||
m1 := extensionAsLegacyType(e1.value)
|
||||
m2 := extensionAsLegacyType(e2.value)
|
||||
|
||||
if m1 == nil && m2 == nil {
|
||||
// Both have only encoded form.
|
||||
if bytes.Equal(e1.enc, e2.enc) {
|
||||
continue
|
||||
}
|
||||
// The bytes are different, but the extensions might still be
|
||||
// equal. We need to decode them to compare.
|
||||
}
|
||||
|
||||
if m1 != nil && m2 != nil {
|
||||
// Both are unencoded.
|
||||
@ -276,8 +273,12 @@ func equalExtMap(base reflect.Type, em1, em2 map[int32]Extension) bool {
|
||||
desc = m[extNum]
|
||||
}
|
||||
if desc == nil {
|
||||
// If both have only encoded form and the bytes are the same,
|
||||
// it is handled above. We get here when the bytes are different.
|
||||
// We don't know how to decode it, so just compare them as byte
|
||||
// slices.
|
||||
log.Printf("proto: don't know how to compare extension %d of %v", extNum, base)
|
||||
continue
|
||||
return false
|
||||
}
|
||||
var err error
|
||||
if m1 == nil {
|
||||
|
22
vendor/github.com/golang/protobuf/proto/equal_test.go
generated
vendored
22
vendor/github.com/golang/protobuf/proto/equal_test.go
generated
vendored
@ -36,7 +36,7 @@ import (
|
||||
|
||||
. "github.com/golang/protobuf/proto"
|
||||
proto3pb "github.com/golang/protobuf/proto/proto3_proto"
|
||||
pb "github.com/golang/protobuf/proto/testdata"
|
||||
pb "github.com/golang/protobuf/proto/test_proto"
|
||||
)
|
||||
|
||||
// Four identical base messages.
|
||||
@ -45,6 +45,9 @@ var messageWithoutExtension = &pb.MyMessage{Count: Int32(7)}
|
||||
var messageWithExtension1a = &pb.MyMessage{Count: Int32(7)}
|
||||
var messageWithExtension1b = &pb.MyMessage{Count: Int32(7)}
|
||||
var messageWithExtension2 = &pb.MyMessage{Count: Int32(7)}
|
||||
var messageWithExtension3a = &pb.MyMessage{Count: Int32(7)}
|
||||
var messageWithExtension3b = &pb.MyMessage{Count: Int32(7)}
|
||||
var messageWithExtension3c = &pb.MyMessage{Count: Int32(7)}
|
||||
|
||||
// Two messages with non-message extensions.
|
||||
var messageWithInt32Extension1 = &pb.MyMessage{Count: Int32(8)}
|
||||
@ -83,6 +86,20 @@ func init() {
|
||||
if err := SetExtension(messageWithInt32Extension1, pb.E_Ext_Number, Int32(24)); err != nil {
|
||||
panic("SetExtension on Int32-2 failed: " + err.Error())
|
||||
}
|
||||
|
||||
// messageWithExtension3{a,b,c} has unregistered extension.
|
||||
if RegisteredExtensions(messageWithExtension3a)[200] != nil {
|
||||
panic("expect extension 200 unregistered")
|
||||
}
|
||||
bytes := []byte{
|
||||
0xc0, 0x0c, 0x01, // id=200, wiretype=0 (varint), data=1
|
||||
}
|
||||
bytes2 := []byte{
|
||||
0xc0, 0x0c, 0x02, // id=200, wiretype=0 (varint), data=2
|
||||
}
|
||||
SetRawExtension(messageWithExtension3a, 200, bytes)
|
||||
SetRawExtension(messageWithExtension3b, 200, bytes)
|
||||
SetRawExtension(messageWithExtension3c, 200, bytes2)
|
||||
}
|
||||
|
||||
var EqualTests = []struct {
|
||||
@ -142,6 +159,9 @@ var EqualTests = []struct {
|
||||
{"int32 extension vs. itself", messageWithInt32Extension1, messageWithInt32Extension1, true},
|
||||
{"int32 extension vs. a different int32", messageWithInt32Extension1, messageWithInt32Extension2, false},
|
||||
|
||||
{"unregistered extension same", messageWithExtension3a, messageWithExtension3b, true},
|
||||
{"unregistered extension different", messageWithExtension3a, messageWithExtension3c, false},
|
||||
|
||||
{
|
||||
"message with group",
|
||||
&pb.MyMessage{
|
||||
|
286
vendor/github.com/golang/protobuf/proto/extensions.go
generated
vendored
286
vendor/github.com/golang/protobuf/proto/extensions.go
generated
vendored
@ -38,6 +38,7 @@ package proto
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"sync"
|
||||
@ -91,14 +92,29 @@ func (n notLocker) Unlock() {}
|
||||
// extendable returns the extendableProto interface for the given generated proto message.
|
||||
// If the proto message has the old extension format, it returns a wrapper that implements
|
||||
// the extendableProto interface.
|
||||
func extendable(p interface{}) (extendableProto, bool) {
|
||||
if ep, ok := p.(extendableProto); ok {
|
||||
return ep, ok
|
||||
func extendable(p interface{}) (extendableProto, error) {
|
||||
switch p := p.(type) {
|
||||
case extendableProto:
|
||||
if isNilPtr(p) {
|
||||
return nil, fmt.Errorf("proto: nil %T is not extendable", p)
|
||||
}
|
||||
return p, nil
|
||||
case extendableProtoV1:
|
||||
if isNilPtr(p) {
|
||||
return nil, fmt.Errorf("proto: nil %T is not extendable", p)
|
||||
}
|
||||
return extensionAdapter{p}, nil
|
||||
}
|
||||
if ep, ok := p.(extendableProtoV1); ok {
|
||||
return extensionAdapter{ep}, ok
|
||||
}
|
||||
return nil, false
|
||||
// Don't allocate a specific error containing %T:
|
||||
// this is the hot path for Clone and MarshalText.
|
||||
return nil, errNotExtendable
|
||||
}
|
||||
|
||||
var errNotExtendable = errors.New("proto: not an extendable proto.Message")
|
||||
|
||||
func isNilPtr(x interface{}) bool {
|
||||
v := reflect.ValueOf(x)
|
||||
return v.Kind() == reflect.Ptr && v.IsNil()
|
||||
}
|
||||
|
||||
// XXX_InternalExtensions is an internal representation of proto extensions.
|
||||
@ -143,9 +159,6 @@ func (e *XXX_InternalExtensions) extensionsRead() (map[int32]Extension, sync.Loc
|
||||
return e.p.extensionMap, &e.p.mu
|
||||
}
|
||||
|
||||
var extendableProtoType = reflect.TypeOf((*extendableProto)(nil)).Elem()
|
||||
var extendableProtoV1Type = reflect.TypeOf((*extendableProtoV1)(nil)).Elem()
|
||||
|
||||
// ExtensionDesc represents an extension specification.
|
||||
// Used in generated code from the protocol compiler.
|
||||
type ExtensionDesc struct {
|
||||
@ -172,15 +185,31 @@ type Extension struct {
|
||||
// extension will have only enc set. When such an extension is
|
||||
// accessed using GetExtension (or GetExtensions) desc and value
|
||||
// will be set.
|
||||
desc *ExtensionDesc
|
||||
desc *ExtensionDesc
|
||||
|
||||
// value is a concrete value for the extension field. Let the type of
|
||||
// desc.ExtensionType be the "API type" and the type of Extension.value
|
||||
// be the "storage type". The API type and storage type are the same except:
|
||||
// * For scalars (except []byte), the API type uses *T,
|
||||
// while the storage type uses T.
|
||||
// * For repeated fields, the API type uses []T, while the storage type
|
||||
// uses *[]T.
|
||||
//
|
||||
// The reason for the divergence is so that the storage type more naturally
|
||||
// matches what is expected of when retrieving the values through the
|
||||
// protobuf reflection APIs.
|
||||
//
|
||||
// The value may only be populated if desc is also populated.
|
||||
value interface{}
|
||||
enc []byte
|
||||
|
||||
// enc is the raw bytes for the extension field.
|
||||
enc []byte
|
||||
}
|
||||
|
||||
// SetRawExtension is for testing only.
|
||||
func SetRawExtension(base Message, id int32, b []byte) {
|
||||
epb, ok := extendable(base)
|
||||
if !ok {
|
||||
epb, err := extendable(base)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
extmap := epb.extensionsWrite()
|
||||
@ -205,7 +234,7 @@ func checkExtensionTypes(pb extendableProto, extension *ExtensionDesc) error {
|
||||
pbi = ea.extendableProtoV1
|
||||
}
|
||||
if a, b := reflect.TypeOf(pbi), reflect.TypeOf(extension.ExtendedType); a != b {
|
||||
return errors.New("proto: bad extended type; " + b.String() + " does not extend " + a.String())
|
||||
return fmt.Errorf("proto: bad extended type; %v does not extend %v", b, a)
|
||||
}
|
||||
// Check the range.
|
||||
if !isExtensionField(pb, extension.Field) {
|
||||
@ -250,85 +279,11 @@ func extensionProperties(ed *ExtensionDesc) *Properties {
|
||||
return prop
|
||||
}
|
||||
|
||||
// encode encodes any unmarshaled (unencoded) extensions in e.
|
||||
func encodeExtensions(e *XXX_InternalExtensions) error {
|
||||
m, mu := e.extensionsRead()
|
||||
if m == nil {
|
||||
return nil // fast path
|
||||
}
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
return encodeExtensionsMap(m)
|
||||
}
|
||||
|
||||
// encode encodes any unmarshaled (unencoded) extensions in e.
|
||||
func encodeExtensionsMap(m map[int32]Extension) error {
|
||||
for k, e := range m {
|
||||
if e.value == nil || e.desc == nil {
|
||||
// Extension is only in its encoded form.
|
||||
continue
|
||||
}
|
||||
|
||||
// We don't skip extensions that have an encoded form set,
|
||||
// because the extension value may have been mutated after
|
||||
// the last time this function was called.
|
||||
|
||||
et := reflect.TypeOf(e.desc.ExtensionType)
|
||||
props := extensionProperties(e.desc)
|
||||
|
||||
p := NewBuffer(nil)
|
||||
// If e.value has type T, the encoder expects a *struct{ X T }.
|
||||
// Pass a *T with a zero field and hope it all works out.
|
||||
x := reflect.New(et)
|
||||
x.Elem().Set(reflect.ValueOf(e.value))
|
||||
if err := props.enc(p, props, toStructPointer(x)); err != nil {
|
||||
return err
|
||||
}
|
||||
e.enc = p.buf
|
||||
m[k] = e
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func extensionsSize(e *XXX_InternalExtensions) (n int) {
|
||||
m, mu := e.extensionsRead()
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
return extensionsMapSize(m)
|
||||
}
|
||||
|
||||
func extensionsMapSize(m map[int32]Extension) (n int) {
|
||||
for _, e := range m {
|
||||
if e.value == nil || e.desc == nil {
|
||||
// Extension is only in its encoded form.
|
||||
n += len(e.enc)
|
||||
continue
|
||||
}
|
||||
|
||||
// We don't skip extensions that have an encoded form set,
|
||||
// because the extension value may have been mutated after
|
||||
// the last time this function was called.
|
||||
|
||||
et := reflect.TypeOf(e.desc.ExtensionType)
|
||||
props := extensionProperties(e.desc)
|
||||
|
||||
// If e.value has type T, the encoder expects a *struct{ X T }.
|
||||
// Pass a *T with a zero field and hope it all works out.
|
||||
x := reflect.New(et)
|
||||
x.Elem().Set(reflect.ValueOf(e.value))
|
||||
n += props.size(props, toStructPointer(x))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// HasExtension returns whether the given extension is present in pb.
|
||||
func HasExtension(pb Message, extension *ExtensionDesc) bool {
|
||||
// TODO: Check types, field numbers, etc.?
|
||||
epb, ok := extendable(pb)
|
||||
if !ok {
|
||||
epb, err := extendable(pb)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
extmap, mu := epb.extensionsRead()
|
||||
@ -336,15 +291,15 @@ func HasExtension(pb Message, extension *ExtensionDesc) bool {
|
||||
return false
|
||||
}
|
||||
mu.Lock()
|
||||
_, ok = extmap[extension.Field]
|
||||
_, ok := extmap[extension.Field]
|
||||
mu.Unlock()
|
||||
return ok
|
||||
}
|
||||
|
||||
// ClearExtension removes the given extension from pb.
|
||||
func ClearExtension(pb Message, extension *ExtensionDesc) {
|
||||
epb, ok := extendable(pb)
|
||||
if !ok {
|
||||
epb, err := extendable(pb)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// TODO: Check types, field numbers, etc.?
|
||||
@ -352,16 +307,26 @@ func ClearExtension(pb Message, extension *ExtensionDesc) {
|
||||
delete(extmap, extension.Field)
|
||||
}
|
||||
|
||||
// GetExtension parses and returns the given extension of pb.
|
||||
// If the extension is not present and has no default value it returns ErrMissingExtension.
|
||||
// GetExtension retrieves a proto2 extended field from pb.
|
||||
//
|
||||
// If the descriptor is type complete (i.e., ExtensionDesc.ExtensionType is non-nil),
|
||||
// then GetExtension parses the encoded field and returns a Go value of the specified type.
|
||||
// If the field is not present, then the default value is returned (if one is specified),
|
||||
// otherwise ErrMissingExtension is reported.
|
||||
//
|
||||
// If the descriptor is not type complete (i.e., ExtensionDesc.ExtensionType is nil),
|
||||
// then GetExtension returns the raw encoded bytes of the field extension.
|
||||
func GetExtension(pb Message, extension *ExtensionDesc) (interface{}, error) {
|
||||
epb, ok := extendable(pb)
|
||||
if !ok {
|
||||
return nil, errors.New("proto: not an extendable proto")
|
||||
epb, err := extendable(pb)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := checkExtensionTypes(epb, extension); err != nil {
|
||||
return nil, err
|
||||
if extension.ExtendedType != nil {
|
||||
// can only check type if this is a complete descriptor
|
||||
if err := checkExtensionTypes(epb, extension); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
emap, mu := epb.extensionsRead()
|
||||
@ -385,7 +350,12 @@ func GetExtension(pb Message, extension *ExtensionDesc) (interface{}, error) {
|
||||
// descriptors with the same field number.
|
||||
return nil, errors.New("proto: descriptor conflict")
|
||||
}
|
||||
return e.value, nil
|
||||
return extensionAsLegacyType(e.value), nil
|
||||
}
|
||||
|
||||
if extension.ExtensionType == nil {
|
||||
// incomplete descriptor
|
||||
return e.enc, nil
|
||||
}
|
||||
|
||||
v, err := decodeExtension(e.enc, extension)
|
||||
@ -395,16 +365,21 @@ func GetExtension(pb Message, extension *ExtensionDesc) (interface{}, error) {
|
||||
|
||||
// Remember the decoded version and drop the encoded version.
|
||||
// That way it is safe to mutate what we return.
|
||||
e.value = v
|
||||
e.value = extensionAsStorageType(v)
|
||||
e.desc = extension
|
||||
e.enc = nil
|
||||
emap[extension.Field] = e
|
||||
return e.value, nil
|
||||
return extensionAsLegacyType(e.value), nil
|
||||
}
|
||||
|
||||
// defaultExtensionValue returns the default value for extension.
|
||||
// If no default for an extension is defined ErrMissingExtension is returned.
|
||||
func defaultExtensionValue(extension *ExtensionDesc) (interface{}, error) {
|
||||
if extension.ExtensionType == nil {
|
||||
// incomplete descriptor, so no default
|
||||
return nil, ErrMissingExtension
|
||||
}
|
||||
|
||||
t := reflect.TypeOf(extension.ExtensionType)
|
||||
props := extensionProperties(extension)
|
||||
|
||||
@ -439,31 +414,28 @@ func defaultExtensionValue(extension *ExtensionDesc) (interface{}, error) {
|
||||
|
||||
// decodeExtension decodes an extension encoded in b.
|
||||
func decodeExtension(b []byte, extension *ExtensionDesc) (interface{}, error) {
|
||||
o := NewBuffer(b)
|
||||
|
||||
t := reflect.TypeOf(extension.ExtensionType)
|
||||
|
||||
props := extensionProperties(extension)
|
||||
unmarshal := typeUnmarshaler(t, extension.Tag)
|
||||
|
||||
// t is a pointer to a struct, pointer to basic type or a slice.
|
||||
// Allocate a "field" to store the pointer/slice itself; the
|
||||
// pointer/slice will be stored here. We pass
|
||||
// the address of this field to props.dec.
|
||||
// This passes a zero field and a *t and lets props.dec
|
||||
// interpret it as a *struct{ x t }.
|
||||
// Allocate space to store the pointer/slice.
|
||||
value := reflect.New(t).Elem()
|
||||
|
||||
var err error
|
||||
for {
|
||||
// Discard wire type and field number varint. It isn't needed.
|
||||
if _, err := o.DecodeVarint(); err != nil {
|
||||
x, n := decodeVarint(b)
|
||||
if n == 0 {
|
||||
return nil, io.ErrUnexpectedEOF
|
||||
}
|
||||
b = b[n:]
|
||||
wire := int(x) & 7
|
||||
|
||||
b, err = unmarshal(b, valToPointer(value.Addr()), wire)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := props.dec(o, props, toStructPointer(value.Addr())); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if o.index >= len(o.buf) {
|
||||
if len(b) == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -473,9 +445,9 @@ func decodeExtension(b []byte, extension *ExtensionDesc) (interface{}, error) {
|
||||
// GetExtensions returns a slice of the extensions present in pb that are also listed in es.
|
||||
// The returned slice has the same length as es; missing extensions will appear as nil elements.
|
||||
func GetExtensions(pb Message, es []*ExtensionDesc) (extensions []interface{}, err error) {
|
||||
epb, ok := extendable(pb)
|
||||
if !ok {
|
||||
return nil, errors.New("proto: not an extendable proto")
|
||||
epb, err := extendable(pb)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
extensions = make([]interface{}, len(es))
|
||||
for i, e := range es {
|
||||
@ -494,9 +466,9 @@ func GetExtensions(pb Message, es []*ExtensionDesc) (extensions []interface{}, e
|
||||
// For non-registered extensions, ExtensionDescs returns an incomplete descriptor containing
|
||||
// just the Field field, which defines the extension's field number.
|
||||
func ExtensionDescs(pb Message) ([]*ExtensionDesc, error) {
|
||||
epb, ok := extendable(pb)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("proto: %T is not an extendable proto.Message", pb)
|
||||
epb, err := extendable(pb)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
registeredExtensions := RegisteredExtensions(pb)
|
||||
|
||||
@ -523,16 +495,16 @@ func ExtensionDescs(pb Message) ([]*ExtensionDesc, error) {
|
||||
|
||||
// SetExtension sets the specified extension of pb to the specified value.
|
||||
func SetExtension(pb Message, extension *ExtensionDesc, value interface{}) error {
|
||||
epb, ok := extendable(pb)
|
||||
if !ok {
|
||||
return errors.New("proto: not an extendable proto")
|
||||
epb, err := extendable(pb)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := checkExtensionTypes(epb, extension); err != nil {
|
||||
return err
|
||||
}
|
||||
typ := reflect.TypeOf(extension.ExtensionType)
|
||||
if typ != reflect.TypeOf(value) {
|
||||
return errors.New("proto: bad extension value type")
|
||||
return fmt.Errorf("proto: bad extension value type. got: %T, want: %T", value, extension.ExtensionType)
|
||||
}
|
||||
// nil extension values need to be caught early, because the
|
||||
// encoder can't distinguish an ErrNil due to a nil extension
|
||||
@ -544,14 +516,14 @@ func SetExtension(pb Message, extension *ExtensionDesc, value interface{}) error
|
||||
}
|
||||
|
||||
extmap := epb.extensionsWrite()
|
||||
extmap[extension.Field] = Extension{desc: extension, value: value}
|
||||
extmap[extension.Field] = Extension{desc: extension, value: extensionAsStorageType(value)}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearAllExtensions clears all extensions from pb.
|
||||
func ClearAllExtensions(pb Message) {
|
||||
epb, ok := extendable(pb)
|
||||
if !ok {
|
||||
epb, err := extendable(pb)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
m := epb.extensionsWrite()
|
||||
@ -585,3 +557,51 @@ func RegisterExtension(desc *ExtensionDesc) {
|
||||
func RegisteredExtensions(pb Message) map[int32]*ExtensionDesc {
|
||||
return extensionMaps[reflect.TypeOf(pb).Elem()]
|
||||
}
|
||||
|
||||
// extensionAsLegacyType converts an value in the storage type as the API type.
|
||||
// See Extension.value.
|
||||
func extensionAsLegacyType(v interface{}) interface{} {
|
||||
switch rv := reflect.ValueOf(v); rv.Kind() {
|
||||
case reflect.Bool, reflect.Int32, reflect.Int64, reflect.Uint32, reflect.Uint64, reflect.Float32, reflect.Float64, reflect.String:
|
||||
// Represent primitive types as a pointer to the value.
|
||||
rv2 := reflect.New(rv.Type())
|
||||
rv2.Elem().Set(rv)
|
||||
v = rv2.Interface()
|
||||
case reflect.Ptr:
|
||||
// Represent slice types as the value itself.
|
||||
switch rv.Type().Elem().Kind() {
|
||||
case reflect.Slice:
|
||||
if rv.IsNil() {
|
||||
v = reflect.Zero(rv.Type().Elem()).Interface()
|
||||
} else {
|
||||
v = rv.Elem().Interface()
|
||||
}
|
||||
}
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// extensionAsStorageType converts an value in the API type as the storage type.
|
||||
// See Extension.value.
|
||||
func extensionAsStorageType(v interface{}) interface{} {
|
||||
switch rv := reflect.ValueOf(v); rv.Kind() {
|
||||
case reflect.Ptr:
|
||||
// Represent slice types as the value itself.
|
||||
switch rv.Type().Elem().Kind() {
|
||||
case reflect.Bool, reflect.Int32, reflect.Int64, reflect.Uint32, reflect.Uint64, reflect.Float32, reflect.Float64, reflect.String:
|
||||
if rv.IsNil() {
|
||||
v = reflect.Zero(rv.Type().Elem()).Interface()
|
||||
} else {
|
||||
v = rv.Elem().Interface()
|
||||
}
|
||||
}
|
||||
case reflect.Slice:
|
||||
// Represent slice types as a pointer to the value.
|
||||
if rv.Type().Elem().Kind() != reflect.Uint8 {
|
||||
rv2 := reflect.New(rv.Type())
|
||||
rv2.Elem().Set(rv)
|
||||
v = rv2.Interface()
|
||||
}
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
192
vendor/github.com/golang/protobuf/proto/extensions_test.go
generated
vendored
192
vendor/github.com/golang/protobuf/proto/extensions_test.go
generated
vendored
@ -34,12 +34,14 @@ package proto_test
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
pb "github.com/golang/protobuf/proto/testdata"
|
||||
pb "github.com/golang/protobuf/proto/test_proto"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
@ -64,7 +66,107 @@ func TestGetExtensionsWithMissingExtensions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtensionDescsWithMissingExtensions(t *testing.T) {
|
||||
func TestGetExtensionWithEmptyBuffer(t *testing.T) {
|
||||
// Make sure that GetExtension returns an error if its
|
||||
// undecoded buffer is empty.
|
||||
msg := &pb.MyMessage{}
|
||||
proto.SetRawExtension(msg, pb.E_Ext_More.Field, []byte{})
|
||||
_, err := proto.GetExtension(msg, pb.E_Ext_More)
|
||||
if want := io.ErrUnexpectedEOF; err != want {
|
||||
t.Errorf("unexpected error in GetExtension from empty buffer: got %v, want %v", err, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetExtensionForIncompleteDesc(t *testing.T) {
|
||||
msg := &pb.MyMessage{Count: proto.Int32(0)}
|
||||
extdesc1 := &proto.ExtensionDesc{
|
||||
ExtendedType: (*pb.MyMessage)(nil),
|
||||
ExtensionType: (*bool)(nil),
|
||||
Field: 123456789,
|
||||
Name: "a.b",
|
||||
Tag: "varint,123456789,opt",
|
||||
}
|
||||
ext1 := proto.Bool(true)
|
||||
if err := proto.SetExtension(msg, extdesc1, ext1); err != nil {
|
||||
t.Fatalf("Could not set ext1: %s", err)
|
||||
}
|
||||
extdesc2 := &proto.ExtensionDesc{
|
||||
ExtendedType: (*pb.MyMessage)(nil),
|
||||
ExtensionType: ([]byte)(nil),
|
||||
Field: 123456790,
|
||||
Name: "a.c",
|
||||
Tag: "bytes,123456790,opt",
|
||||
}
|
||||
ext2 := []byte{0, 1, 2, 3, 4, 5, 6, 7}
|
||||
if err := proto.SetExtension(msg, extdesc2, ext2); err != nil {
|
||||
t.Fatalf("Could not set ext2: %s", err)
|
||||
}
|
||||
extdesc3 := &proto.ExtensionDesc{
|
||||
ExtendedType: (*pb.MyMessage)(nil),
|
||||
ExtensionType: (*pb.Ext)(nil),
|
||||
Field: 123456791,
|
||||
Name: "a.d",
|
||||
Tag: "bytes,123456791,opt",
|
||||
}
|
||||
ext3 := &pb.Ext{Data: proto.String("foo")}
|
||||
if err := proto.SetExtension(msg, extdesc3, ext3); err != nil {
|
||||
t.Fatalf("Could not set ext3: %s", err)
|
||||
}
|
||||
|
||||
b, err := proto.Marshal(msg)
|
||||
if err != nil {
|
||||
t.Fatalf("Could not marshal msg: %v", err)
|
||||
}
|
||||
if err := proto.Unmarshal(b, msg); err != nil {
|
||||
t.Fatalf("Could not unmarshal into msg: %v", err)
|
||||
}
|
||||
|
||||
var expected proto.Buffer
|
||||
if err := expected.EncodeVarint(uint64((extdesc1.Field << 3) | proto.WireVarint)); err != nil {
|
||||
t.Fatalf("failed to compute expected prefix for ext1: %s", err)
|
||||
}
|
||||
if err := expected.EncodeVarint(1 /* bool true */); err != nil {
|
||||
t.Fatalf("failed to compute expected value for ext1: %s", err)
|
||||
}
|
||||
|
||||
if b, err := proto.GetExtension(msg, &proto.ExtensionDesc{Field: extdesc1.Field}); err != nil {
|
||||
t.Fatalf("Failed to get raw value for ext1: %s", err)
|
||||
} else if !reflect.DeepEqual(b, expected.Bytes()) {
|
||||
t.Fatalf("Raw value for ext1: got %v, want %v", b, expected.Bytes())
|
||||
}
|
||||
|
||||
expected = proto.Buffer{} // reset
|
||||
if err := expected.EncodeVarint(uint64((extdesc2.Field << 3) | proto.WireBytes)); err != nil {
|
||||
t.Fatalf("failed to compute expected prefix for ext2: %s", err)
|
||||
}
|
||||
if err := expected.EncodeRawBytes(ext2); err != nil {
|
||||
t.Fatalf("failed to compute expected value for ext2: %s", err)
|
||||
}
|
||||
|
||||
if b, err := proto.GetExtension(msg, &proto.ExtensionDesc{Field: extdesc2.Field}); err != nil {
|
||||
t.Fatalf("Failed to get raw value for ext2: %s", err)
|
||||
} else if !reflect.DeepEqual(b, expected.Bytes()) {
|
||||
t.Fatalf("Raw value for ext2: got %v, want %v", b, expected.Bytes())
|
||||
}
|
||||
|
||||
expected = proto.Buffer{} // reset
|
||||
if err := expected.EncodeVarint(uint64((extdesc3.Field << 3) | proto.WireBytes)); err != nil {
|
||||
t.Fatalf("failed to compute expected prefix for ext3: %s", err)
|
||||
}
|
||||
if b, err := proto.Marshal(ext3); err != nil {
|
||||
t.Fatalf("failed to compute expected value for ext3: %s", err)
|
||||
} else if err := expected.EncodeRawBytes(b); err != nil {
|
||||
t.Fatalf("failed to compute expected value for ext3: %s", err)
|
||||
}
|
||||
|
||||
if b, err := proto.GetExtension(msg, &proto.ExtensionDesc{Field: extdesc3.Field}); err != nil {
|
||||
t.Fatalf("Failed to get raw value for ext3: %s", err)
|
||||
} else if !reflect.DeepEqual(b, expected.Bytes()) {
|
||||
t.Fatalf("Raw value for ext3: got %v, want %v", b, expected.Bytes())
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtensionDescsWithUnregisteredExtensions(t *testing.T) {
|
||||
msg := &pb.MyMessage{Count: proto.Int32(0)}
|
||||
extdesc1 := pb.E_Ext_More
|
||||
if descs, err := proto.ExtensionDescs(msg); len(descs) != 0 || err != nil {
|
||||
@ -100,7 +202,7 @@ func TestExtensionDescsWithMissingExtensions(t *testing.T) {
|
||||
t.Fatalf("proto.ExtensionDescs: got error %v", err)
|
||||
}
|
||||
sortExtDescs(descs)
|
||||
wantDescs := []*proto.ExtensionDesc{extdesc1, &proto.ExtensionDesc{Field: extdesc2.Field}}
|
||||
wantDescs := []*proto.ExtensionDesc{extdesc1, {Field: extdesc2.Field}}
|
||||
if !reflect.DeepEqual(descs, wantDescs) {
|
||||
t.Errorf("proto.ExtensionDescs(msg) sorted extension ids: got %+v, want %+v", descs, wantDescs)
|
||||
}
|
||||
@ -200,7 +302,7 @@ func TestGetExtensionDefaults(t *testing.T) {
|
||||
{pb.E_DefaultSfixed64, setInt64, int64(51)},
|
||||
{pb.E_DefaultBool, setBool, true},
|
||||
{pb.E_DefaultBool, setBool2, true},
|
||||
{pb.E_DefaultString, setString, "Hello, string"},
|
||||
{pb.E_DefaultString, setString, "Hello, string,def=foo"},
|
||||
{pb.E_DefaultBytes, setBytes, []byte("Hello, bytes")},
|
||||
{pb.E_DefaultEnum, setEnum, pb.DefaultsMessage_ONE},
|
||||
}
|
||||
@ -287,6 +389,44 @@ func TestGetExtensionDefaults(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNilMessage(t *testing.T) {
|
||||
name := "nil interface"
|
||||
if got, err := proto.GetExtension(nil, pb.E_Ext_More); err == nil {
|
||||
t.Errorf("%s: got %T %v, expected to fail", name, got, got)
|
||||
} else if !strings.Contains(err.Error(), "extendable") {
|
||||
t.Errorf("%s: got error %v, expected not-extendable error", name, err)
|
||||
}
|
||||
|
||||
// Regression tests: all functions of the Extension API
|
||||
// used to panic when passed (*M)(nil), where M is a concrete message
|
||||
// type. Now they handle this gracefully as a no-op or reported error.
|
||||
var nilMsg *pb.MyMessage
|
||||
desc := pb.E_Ext_More
|
||||
|
||||
isNotExtendable := func(err error) bool {
|
||||
return strings.Contains(fmt.Sprint(err), "not extendable")
|
||||
}
|
||||
|
||||
if proto.HasExtension(nilMsg, desc) {
|
||||
t.Error("HasExtension(nil) = true")
|
||||
}
|
||||
|
||||
if _, err := proto.GetExtensions(nilMsg, []*proto.ExtensionDesc{desc}); !isNotExtendable(err) {
|
||||
t.Errorf("GetExtensions(nil) = %q (wrong error)", err)
|
||||
}
|
||||
|
||||
if _, err := proto.ExtensionDescs(nilMsg); !isNotExtendable(err) {
|
||||
t.Errorf("ExtensionDescs(nil) = %q (wrong error)", err)
|
||||
}
|
||||
|
||||
if err := proto.SetExtension(nilMsg, desc, nil); !isNotExtendable(err) {
|
||||
t.Errorf("SetExtension(nil) = %q (wrong error)", err)
|
||||
}
|
||||
|
||||
proto.ClearExtension(nilMsg, desc) // no-op
|
||||
proto.ClearAllExtensions(nilMsg) // no-op
|
||||
}
|
||||
|
||||
func TestExtensionsRoundTrip(t *testing.T) {
|
||||
msg := &pb.MyMessage{}
|
||||
ext1 := &pb.Ext{
|
||||
@ -311,7 +451,7 @@ func TestExtensionsRoundTrip(t *testing.T) {
|
||||
}
|
||||
x, ok := e.(*pb.Ext)
|
||||
if !ok {
|
||||
t.Errorf("e has type %T, expected testdata.Ext", e)
|
||||
t.Errorf("e has type %T, expected test_proto.Ext", e)
|
||||
} else if *x.Data != "there" {
|
||||
t.Errorf("SetExtension failed to overwrite, got %+v, not 'there'", x)
|
||||
}
|
||||
@ -339,7 +479,7 @@ func TestNilExtension(t *testing.T) {
|
||||
}
|
||||
if err := proto.SetExtension(msg, pb.E_Ext_More, (*pb.Ext)(nil)); err == nil {
|
||||
t.Error("expected SetExtension to fail due to a nil extension")
|
||||
} else if want := "proto: SetExtension called with nil value of type *testdata.Ext"; err.Error() != want {
|
||||
} else if want := fmt.Sprintf("proto: SetExtension called with nil value of type %T", new(pb.Ext)); err.Error() != want {
|
||||
t.Errorf("expected error %v, got %v", want, err)
|
||||
}
|
||||
// Note: if the behavior of Marshal is ever changed to ignore nil extensions, update
|
||||
@ -402,8 +542,13 @@ func TestMarshalUnmarshalRepeatedExtension(t *testing.T) {
|
||||
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)
|
||||
if len(ext) != len(test.ext) {
|
||||
t.Errorf("[%s] Wrong length of ComplexExtension: got: %v want: %v\n", test.name, len(ext), len(test.ext))
|
||||
}
|
||||
for i := range test.ext {
|
||||
if !proto.Equal(ext[i], test.ext[i]) {
|
||||
t.Errorf("[%s] Wrong value for ComplexExtension[%d]: got: %v want: %v\n", test.name, i, ext[i], test.ext[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -477,8 +622,8 @@ func TestUnmarshalRepeatingNonRepeatedExtension(t *testing.T) {
|
||||
if ext == nil {
|
||||
t.Fatalf("[%s] Invalid extension", test.name)
|
||||
}
|
||||
if !reflect.DeepEqual(*ext, want) {
|
||||
t.Errorf("[%s] Wrong value for ComplexExtension: got: %s want: %s\n", test.name, ext, want)
|
||||
if !proto.Equal(ext, &want) {
|
||||
t.Errorf("[%s] Wrong value for ComplexExtension: got: %s want: %s\n", test.name, ext, &want)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -509,19 +654,22 @@ func TestClearAllExtensions(t *testing.T) {
|
||||
}
|
||||
|
||||
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",
|
||||
ext := &pb.Ext{}
|
||||
m := &pb.MyMessage{Count: proto.Int32(4)}
|
||||
if err := proto.SetExtension(m, pb.E_Ext_More, ext); err != nil {
|
||||
t.Fatalf("proto.SetExtension(m, desc, true): got error %q, want nil", err)
|
||||
}
|
||||
|
||||
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)
|
||||
b, err := proto.Marshal(m)
|
||||
if err != nil {
|
||||
t.Fatalf("Could not marshal message: %v", err)
|
||||
}
|
||||
if err := proto.Unmarshal(b, m); err != nil {
|
||||
t.Fatalf("Could not unmarshal message: %v", err)
|
||||
}
|
||||
// after Unmarshal, the extension is in undecoded form.
|
||||
// GetExtension will decode it lazily. Make sure this does
|
||||
// not race against Marshal.
|
||||
|
||||
var g errgroup.Group
|
||||
for n := 3; n > 0; n-- {
|
||||
@ -529,6 +677,10 @@ func TestMarshalRace(t *testing.T) {
|
||||
_, err := proto.Marshal(m)
|
||||
return err
|
||||
})
|
||||
g.Go(func() error {
|
||||
_, err := proto.GetExtension(m, pb.E_Ext_More)
|
||||
return err
|
||||
})
|
||||
}
|
||||
if err := g.Wait(); err != nil {
|
||||
t.Fatal(err)
|
||||
|
148
vendor/github.com/golang/protobuf/proto/lib.go
generated
vendored
148
vendor/github.com/golang/protobuf/proto/lib.go
generated
vendored
@ -273,6 +273,67 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// RequiredNotSetError is an error type returned by either Marshal or Unmarshal.
|
||||
// Marshal reports this when a required field is not initialized.
|
||||
// Unmarshal reports this when a required field is missing from the wire data.
|
||||
type RequiredNotSetError struct{ field string }
|
||||
|
||||
func (e *RequiredNotSetError) Error() string {
|
||||
if e.field == "" {
|
||||
return fmt.Sprintf("proto: required field not set")
|
||||
}
|
||||
return fmt.Sprintf("proto: required field %q not set", e.field)
|
||||
}
|
||||
func (e *RequiredNotSetError) RequiredNotSet() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
type invalidUTF8Error struct{ field string }
|
||||
|
||||
func (e *invalidUTF8Error) Error() string {
|
||||
if e.field == "" {
|
||||
return "proto: invalid UTF-8 detected"
|
||||
}
|
||||
return fmt.Sprintf("proto: field %q contains invalid UTF-8", e.field)
|
||||
}
|
||||
func (e *invalidUTF8Error) InvalidUTF8() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// errInvalidUTF8 is a sentinel error to identify fields with invalid UTF-8.
|
||||
// This error should not be exposed to the external API as such errors should
|
||||
// be recreated with the field information.
|
||||
var errInvalidUTF8 = &invalidUTF8Error{}
|
||||
|
||||
// isNonFatal reports whether the error is either a RequiredNotSet error
|
||||
// or a InvalidUTF8 error.
|
||||
func isNonFatal(err error) bool {
|
||||
if re, ok := err.(interface{ RequiredNotSet() bool }); ok && re.RequiredNotSet() {
|
||||
return true
|
||||
}
|
||||
if re, ok := err.(interface{ InvalidUTF8() bool }); ok && re.InvalidUTF8() {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type nonFatal struct{ E error }
|
||||
|
||||
// Merge merges err into nf and reports whether it was successful.
|
||||
// Otherwise it returns false for any fatal non-nil errors.
|
||||
func (nf *nonFatal) Merge(err error) (ok bool) {
|
||||
if err == nil {
|
||||
return true // not an error
|
||||
}
|
||||
if !isNonFatal(err) {
|
||||
return false // fatal error
|
||||
}
|
||||
if nf.E == nil {
|
||||
nf.E = err // store first instance of non-fatal error
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Message is implemented by generated protocol buffer messages.
|
||||
type Message interface {
|
||||
Reset()
|
||||
@ -280,26 +341,6 @@ type Message interface {
|
||||
ProtoMessage()
|
||||
}
|
||||
|
||||
// Stats records allocation details about the protocol buffer encoders
|
||||
// and decoders. Useful for tuning the library itself.
|
||||
type Stats struct {
|
||||
Emalloc uint64 // mallocs in encode
|
||||
Dmalloc uint64 // mallocs in decode
|
||||
Encode uint64 // number of encodes
|
||||
Decode uint64 // number of decodes
|
||||
Chit uint64 // number of cache hits
|
||||
Cmiss uint64 // number of cache misses
|
||||
Size uint64 // number of sizes
|
||||
}
|
||||
|
||||
// Set to true to enable stats collection.
|
||||
const collectStats = false
|
||||
|
||||
var stats Stats
|
||||
|
||||
// GetStats returns a copy of the global Stats structure.
|
||||
func GetStats() Stats { return stats }
|
||||
|
||||
// A Buffer is a buffer manager for marshaling and unmarshaling
|
||||
// protocol buffers. It may be reused between invocations to
|
||||
// reduce memory usage. It is not necessary to use a Buffer;
|
||||
@ -309,16 +350,7 @@ type Buffer struct {
|
||||
buf []byte // encode/decode byte stream
|
||||
index int // read point
|
||||
|
||||
// pools of basic types to amortize allocation.
|
||||
bools []bool
|
||||
uint32s []uint32
|
||||
uint64s []uint64
|
||||
|
||||
// extra pools, only used with pointer_reflect.go
|
||||
int32s []int32
|
||||
int64s []int64
|
||||
float32s []float32
|
||||
float64s []float64
|
||||
deterministic bool
|
||||
}
|
||||
|
||||
// NewBuffer allocates a new Buffer and initializes its internal data to
|
||||
@ -343,6 +375,30 @@ func (p *Buffer) SetBuf(s []byte) {
|
||||
// Bytes returns the contents of the Buffer.
|
||||
func (p *Buffer) Bytes() []byte { return p.buf }
|
||||
|
||||
// SetDeterministic sets whether to use deterministic serialization.
|
||||
//
|
||||
// Deterministic serialization guarantees that for a given binary, equal
|
||||
// messages will always be serialized to the same bytes. This implies:
|
||||
//
|
||||
// - Repeated serialization of a message will return the same bytes.
|
||||
// - Different processes of the same binary (which may be executing on
|
||||
// different machines) will serialize equal messages to the same bytes.
|
||||
//
|
||||
// Note that the deterministic serialization is NOT canonical across
|
||||
// languages. It is not guaranteed to remain stable over time. It is unstable
|
||||
// across different builds with schema changes due to unknown fields.
|
||||
// Users who need canonical serialization (e.g., persistent storage in a
|
||||
// canonical form, fingerprinting, etc.) should define their own
|
||||
// canonicalization specification and implement their own serializer rather
|
||||
// than relying on this API.
|
||||
//
|
||||
// If deterministic serialization is requested, map entries will be sorted
|
||||
// by keys in lexographical order. This is an implementation detail and
|
||||
// subject to change.
|
||||
func (p *Buffer) SetDeterministic(deterministic bool) {
|
||||
p.deterministic = deterministic
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper routines for simplifying the creation of optional fields of basic type.
|
||||
*/
|
||||
@ -831,22 +887,12 @@ func fieldDefault(ft reflect.Type, prop *Properties) (sf *scalarField, nestedMes
|
||||
return sf, false, nil
|
||||
}
|
||||
|
||||
// mapKeys returns a sort.Interface to be used for sorting the map keys.
|
||||
// Map fields may have key types of non-float scalars, strings and enums.
|
||||
// The easiest way to sort them in some deterministic order is to use fmt.
|
||||
// If this turns out to be inefficient we can always consider other options,
|
||||
// such as doing a Schwartzian transform.
|
||||
|
||||
func mapKeys(vs []reflect.Value) sort.Interface {
|
||||
s := mapKeySorter{
|
||||
vs: vs,
|
||||
// default Less function: textual comparison
|
||||
less: func(a, b reflect.Value) bool {
|
||||
return fmt.Sprint(a.Interface()) < fmt.Sprint(b.Interface())
|
||||
},
|
||||
}
|
||||
s := mapKeySorter{vs: vs}
|
||||
|
||||
// Type specialization per https://developers.google.com/protocol-buffers/docs/proto#maps;
|
||||
// numeric keys are sorted numerically.
|
||||
// Type specialization per https://developers.google.com/protocol-buffers/docs/proto#maps.
|
||||
if len(vs) == 0 {
|
||||
return s
|
||||
}
|
||||
@ -855,6 +901,12 @@ func mapKeys(vs []reflect.Value) sort.Interface {
|
||||
s.less = func(a, b reflect.Value) bool { return a.Int() < b.Int() }
|
||||
case reflect.Uint32, reflect.Uint64:
|
||||
s.less = func(a, b reflect.Value) bool { return a.Uint() < b.Uint() }
|
||||
case reflect.Bool:
|
||||
s.less = func(a, b reflect.Value) bool { return !a.Bool() && b.Bool() } // false < true
|
||||
case reflect.String:
|
||||
s.less = func(a, b reflect.Value) bool { return a.String() < b.String() }
|
||||
default:
|
||||
panic(fmt.Sprintf("unsupported map key type: %v", vs[0].Kind()))
|
||||
}
|
||||
|
||||
return s
|
||||
@ -895,3 +947,13 @@ const ProtoPackageIsVersion2 = true
|
||||
// ProtoPackageIsVersion1 is referenced from generated protocol buffer files
|
||||
// to assert that that code is compatible with this version of the proto package.
|
||||
const ProtoPackageIsVersion1 = true
|
||||
|
||||
// InternalMessageInfo is a type used internally by generated .pb.go files.
|
||||
// This type is not intended to be used by non-generated code.
|
||||
// This type is not subject to any compatibility guarantee.
|
||||
type InternalMessageInfo struct {
|
||||
marshal *marshalInfo
|
||||
unmarshal *unmarshalInfo
|
||||
merge *mergeInfo
|
||||
discard *discardInfo
|
||||
}
|
||||
|
24
vendor/github.com/golang/protobuf/proto/map_test.go
generated
vendored
24
vendor/github.com/golang/protobuf/proto/map_test.go
generated
vendored
@ -2,12 +2,36 @@ package proto_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
ppb "github.com/golang/protobuf/proto/proto3_proto"
|
||||
)
|
||||
|
||||
func TestMap(t *testing.T) {
|
||||
var b []byte
|
||||
fmt.Sscanf("a2010c0a044b657931120456616c31a201130a044b657932120556616c3261120456616c32a201240a044b6579330d05000000120556616c33621a0556616c3361120456616c331505000000a20100a201260a044b657934130a07536f6d6555524c1209536f6d655469746c651a08536e69707065743114", "%x", &b)
|
||||
|
||||
var m ppb.Message
|
||||
if err := proto.Unmarshal(b, &m); err != nil {
|
||||
t.Fatalf("proto.Unmarshal error: %v", err)
|
||||
}
|
||||
|
||||
got := m.StringMap
|
||||
want := map[string]string{
|
||||
"": "",
|
||||
"Key1": "Val1",
|
||||
"Key2": "Val2",
|
||||
"Key3": "Val3",
|
||||
"Key4": "",
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("maps differ:\ngot %#v\nwant %#v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func marshalled() []byte {
|
||||
m := &ppb.IntMaps{}
|
||||
for i := 0; i < 1000; i++ {
|
||||
|
138
vendor/github.com/golang/protobuf/proto/message_set.go
generated
vendored
138
vendor/github.com/golang/protobuf/proto/message_set.go
generated
vendored
@ -36,12 +36,7 @@ package proto
|
||||
*/
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// errNoMessageTypeID occurs when a protocol buffer does not have a message type ID.
|
||||
@ -94,10 +89,7 @@ func (ms *messageSet) find(pb Message) *_MessageSet_Item {
|
||||
}
|
||||
|
||||
func (ms *messageSet) Has(pb Message) bool {
|
||||
if ms.find(pb) != nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return ms.find(pb) != nil
|
||||
}
|
||||
|
||||
func (ms *messageSet) Unmarshal(pb Message) error {
|
||||
@ -147,50 +139,9 @@ func skipVarint(buf []byte) []byte {
|
||||
return buf[i+1:]
|
||||
}
|
||||
|
||||
// MarshalMessageSet encodes the extension map represented by m in the message set wire format.
|
||||
// It is called by generated Marshal methods on protocol buffer messages with the message_set_wire_format option.
|
||||
func MarshalMessageSet(exts interface{}) ([]byte, error) {
|
||||
var m map[int32]Extension
|
||||
switch exts := exts.(type) {
|
||||
case *XXX_InternalExtensions:
|
||||
if err := encodeExtensions(exts); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m, _ = exts.extensionsRead()
|
||||
case map[int32]Extension:
|
||||
if err := encodeExtensionsMap(exts); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m = exts
|
||||
default:
|
||||
return nil, errors.New("proto: not an extension map")
|
||||
}
|
||||
|
||||
// Sort extension IDs to provide a deterministic encoding.
|
||||
// See also enc_map in encode.go.
|
||||
ids := make([]int, 0, len(m))
|
||||
for id := range m {
|
||||
ids = append(ids, int(id))
|
||||
}
|
||||
sort.Ints(ids)
|
||||
|
||||
ms := &messageSet{Item: make([]*_MessageSet_Item, 0, len(m))}
|
||||
for _, id := range ids {
|
||||
e := m[int32(id)]
|
||||
// Remove the wire type and field number varint, as well as the length varint.
|
||||
msg := skipVarint(skipVarint(e.enc))
|
||||
|
||||
ms.Item = append(ms.Item, &_MessageSet_Item{
|
||||
TypeId: Int32(int32(id)),
|
||||
Message: msg,
|
||||
})
|
||||
}
|
||||
return Marshal(ms)
|
||||
}
|
||||
|
||||
// UnmarshalMessageSet decodes the extension map encoded in buf in the message set wire format.
|
||||
// It is called by generated Unmarshal methods on protocol buffer messages with the message_set_wire_format option.
|
||||
func UnmarshalMessageSet(buf []byte, exts interface{}) error {
|
||||
// unmarshalMessageSet decodes the extension map encoded in buf in the message set wire format.
|
||||
// It is called by Unmarshal methods on protocol buffer messages with the message_set_wire_format option.
|
||||
func unmarshalMessageSet(buf []byte, exts interface{}) error {
|
||||
var m map[int32]Extension
|
||||
switch exts := exts.(type) {
|
||||
case *XXX_InternalExtensions:
|
||||
@ -228,84 +179,3 @@ func UnmarshalMessageSet(buf []byte, exts interface{}) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalMessageSetJSON encodes the extension map represented by m in JSON format.
|
||||
// It is called by generated MarshalJSON methods on protocol buffer messages with the message_set_wire_format option.
|
||||
func MarshalMessageSetJSON(exts interface{}) ([]byte, error) {
|
||||
var m map[int32]Extension
|
||||
switch exts := exts.(type) {
|
||||
case *XXX_InternalExtensions:
|
||||
m, _ = exts.extensionsRead()
|
||||
case map[int32]Extension:
|
||||
m = exts
|
||||
default:
|
||||
return nil, errors.New("proto: not an extension map")
|
||||
}
|
||||
var b bytes.Buffer
|
||||
b.WriteByte('{')
|
||||
|
||||
// Process the map in key order for deterministic output.
|
||||
ids := make([]int32, 0, len(m))
|
||||
for id := range m {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
sort.Sort(int32Slice(ids)) // int32Slice defined in text.go
|
||||
|
||||
for i, id := range ids {
|
||||
ext := m[id]
|
||||
if i > 0 {
|
||||
b.WriteByte(',')
|
||||
}
|
||||
|
||||
msd, ok := messageSetMap[id]
|
||||
if !ok {
|
||||
// Unknown type; we can't render it, so skip it.
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(&b, `"[%s]":`, msd.name)
|
||||
|
||||
x := ext.value
|
||||
if x == nil {
|
||||
x = reflect.New(msd.t.Elem()).Interface()
|
||||
if err := Unmarshal(ext.enc, x.(Message)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
d, err := json.Marshal(x)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b.Write(d)
|
||||
}
|
||||
b.WriteByte('}')
|
||||
return b.Bytes(), nil
|
||||
}
|
||||
|
||||
// UnmarshalMessageSetJSON decodes the extension map encoded in buf in JSON format.
|
||||
// It is called by generated UnmarshalJSON methods on protocol buffer messages with the message_set_wire_format option.
|
||||
func UnmarshalMessageSetJSON(buf []byte, exts interface{}) error {
|
||||
// Common-case fast path.
|
||||
if len(buf) == 0 || bytes.Equal(buf, []byte("{}")) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// This is fairly tricky, and it's not clear that it is needed.
|
||||
return errors.New("TODO: UnmarshalMessageSetJSON not yet implemented")
|
||||
}
|
||||
|
||||
// A global registry of types that can be used in a MessageSet.
|
||||
|
||||
var messageSetMap = make(map[int32]messageSetDesc)
|
||||
|
||||
type messageSetDesc struct {
|
||||
t reflect.Type // pointer to struct
|
||||
name string
|
||||
}
|
||||
|
||||
// RegisterMessageSetType is called from the generated code.
|
||||
func RegisterMessageSetType(m Message, fieldNum int32, name string) {
|
||||
messageSetMap[fieldNum] = messageSetDesc{
|
||||
t: reflect.TypeOf(m),
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
68
vendor/github.com/golang/protobuf/proto/message_set_test.go
generated
vendored
68
vendor/github.com/golang/protobuf/proto/message_set_test.go
generated
vendored
@ -29,38 +29,60 @@
|
||||
// (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
|
||||
package proto_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
. "github.com/golang/protobuf/proto/test_proto"
|
||||
)
|
||||
|
||||
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)
|
||||
/*
|
||||
Message{
|
||||
Tag{1, StartGroup},
|
||||
Message{
|
||||
Tag{2, Varint}, Uvarint(12345),
|
||||
Tag{3, Bytes}, Bytes("hoo"),
|
||||
},
|
||||
Tag{1, EndGroup},
|
||||
Tag{1, StartGroup},
|
||||
Message{
|
||||
Tag{2, Varint}, Uvarint(12345),
|
||||
Tag{3, Bytes}, Bytes("hah"),
|
||||
},
|
||||
Tag{1, EndGroup},
|
||||
}
|
||||
*/
|
||||
var in []byte
|
||||
fmt.Sscanf("0b10b9601a03686f6f0c0b10b9601a036861680c", "%x", &in)
|
||||
|
||||
var extensions XXX_InternalExtensions
|
||||
if err := UnmarshalMessageSet(b, &extensions); err != nil {
|
||||
t.Fatalf("UnmarshalMessageSet: %v", err)
|
||||
/*
|
||||
Message{
|
||||
Tag{1, StartGroup},
|
||||
Message{
|
||||
Tag{2, Varint}, Uvarint(12345),
|
||||
Tag{3, Bytes}, Bytes("hoohah"),
|
||||
},
|
||||
Tag{1, EndGroup},
|
||||
}
|
||||
*/
|
||||
var want []byte
|
||||
fmt.Sscanf("0b10b9601a06686f6f6861680c", "%x", &want)
|
||||
|
||||
var m MyMessageSet
|
||||
if err := proto.Unmarshal(in, &m); err != nil {
|
||||
t.Fatalf("unexpected Unmarshal error: %v", err)
|
||||
}
|
||||
ext, ok := extensions.p.extensionMap[12345]
|
||||
if !ok {
|
||||
t.Fatalf("Didn't retrieve extension 12345; map is %v", extensions.p.extensionMap)
|
||||
got, err := proto.Marshal(&m)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected Marshal error: %v", err)
|
||||
}
|
||||
// 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)
|
||||
|
||||
if !bytes.Equal(got, want) {
|
||||
t.Errorf("output mismatch:\ngot %x\nwant %x", got, want)
|
||||
}
|
||||
}
|
||||
|
648
vendor/github.com/golang/protobuf/proto/pointer_reflect.go
generated
vendored
648
vendor/github.com/golang/protobuf/proto/pointer_reflect.go
generated
vendored
@ -29,7 +29,7 @@
|
||||
// (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 appengine js
|
||||
// +build purego appengine js
|
||||
|
||||
// This file contains an implementation of proto field accesses using package reflect.
|
||||
// It is slower than the code in pointer_unsafe.go but it avoids package unsafe and can
|
||||
@ -38,32 +38,13 @@
|
||||
package proto
|
||||
|
||||
import (
|
||||
"math"
|
||||
"reflect"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// A structPointer is a pointer to a struct.
|
||||
type structPointer struct {
|
||||
v reflect.Value
|
||||
}
|
||||
const unsafeAllowed = false
|
||||
|
||||
// toStructPointer returns a structPointer equivalent to the given reflect value.
|
||||
// The reflect value must itself be a pointer to a struct.
|
||||
func toStructPointer(v reflect.Value) structPointer {
|
||||
return structPointer{v}
|
||||
}
|
||||
|
||||
// IsNil reports whether p is nil.
|
||||
func structPointer_IsNil(p structPointer) bool {
|
||||
return p.v.IsNil()
|
||||
}
|
||||
|
||||
// Interface returns the struct pointer as an interface value.
|
||||
func structPointer_Interface(p structPointer, _ reflect.Type) interface{} {
|
||||
return p.v.Interface()
|
||||
}
|
||||
|
||||
// A field identifies a field in a struct, accessible from a structPointer.
|
||||
// A field identifies a field in a struct, accessible from a pointer.
|
||||
// In this implementation, a field is identified by the sequence of field indices
|
||||
// passed to reflect's FieldByIndex.
|
||||
type field []int
|
||||
@ -76,409 +57,304 @@ func toField(f *reflect.StructField) field {
|
||||
// invalidField is an invalid field identifier.
|
||||
var invalidField = field(nil)
|
||||
|
||||
// zeroField is a noop when calling pointer.offset.
|
||||
var zeroField = field([]int{})
|
||||
|
||||
// IsValid reports whether the field identifier is valid.
|
||||
func (f field) IsValid() bool { return f != nil }
|
||||
|
||||
// field returns the given field in the struct as a reflect value.
|
||||
func structPointer_field(p structPointer, f field) reflect.Value {
|
||||
// Special case: an extension map entry with a value of type T
|
||||
// passes a *T to the struct-handling code with a zero field,
|
||||
// expecting that it will be treated as equivalent to *struct{ X T },
|
||||
// which has the same memory layout. We have to handle that case
|
||||
// specially, because reflect will panic if we call FieldByIndex on a
|
||||
// non-struct.
|
||||
if f == nil {
|
||||
return p.v.Elem()
|
||||
// The pointer type is for the table-driven decoder.
|
||||
// The implementation here uses a reflect.Value of pointer type to
|
||||
// create a generic pointer. In pointer_unsafe.go we use unsafe
|
||||
// instead of reflect to implement the same (but faster) interface.
|
||||
type pointer struct {
|
||||
v reflect.Value
|
||||
}
|
||||
|
||||
// toPointer converts an interface of pointer type to a pointer
|
||||
// that points to the same target.
|
||||
func toPointer(i *Message) pointer {
|
||||
return pointer{v: reflect.ValueOf(*i)}
|
||||
}
|
||||
|
||||
// toAddrPointer converts an interface to a pointer that points to
|
||||
// the interface data.
|
||||
func toAddrPointer(i *interface{}, isptr, deref bool) pointer {
|
||||
v := reflect.ValueOf(*i)
|
||||
u := reflect.New(v.Type())
|
||||
u.Elem().Set(v)
|
||||
if deref {
|
||||
u = u.Elem()
|
||||
}
|
||||
|
||||
return p.v.Elem().FieldByIndex(f)
|
||||
return pointer{v: u}
|
||||
}
|
||||
|
||||
// ifield returns the given field in the struct as an interface value.
|
||||
func structPointer_ifield(p structPointer, f field) interface{} {
|
||||
return structPointer_field(p, f).Addr().Interface()
|
||||
// valToPointer converts v to a pointer. v must be of pointer type.
|
||||
func valToPointer(v reflect.Value) pointer {
|
||||
return pointer{v: v}
|
||||
}
|
||||
|
||||
// Bytes returns the address of a []byte field in the struct.
|
||||
func structPointer_Bytes(p structPointer, f field) *[]byte {
|
||||
return structPointer_ifield(p, f).(*[]byte)
|
||||
// offset converts from a pointer to a structure to a pointer to
|
||||
// one of its fields.
|
||||
func (p pointer) offset(f field) pointer {
|
||||
return pointer{v: p.v.Elem().FieldByIndex(f).Addr()}
|
||||
}
|
||||
|
||||
// BytesSlice returns the address of a [][]byte field in the struct.
|
||||
func structPointer_BytesSlice(p structPointer, f field) *[][]byte {
|
||||
return structPointer_ifield(p, f).(*[][]byte)
|
||||
}
|
||||
|
||||
// Bool returns the address of a *bool field in the struct.
|
||||
func structPointer_Bool(p structPointer, f field) **bool {
|
||||
return structPointer_ifield(p, f).(**bool)
|
||||
}
|
||||
|
||||
// BoolVal returns the address of a bool field in the struct.
|
||||
func structPointer_BoolVal(p structPointer, f field) *bool {
|
||||
return structPointer_ifield(p, f).(*bool)
|
||||
}
|
||||
|
||||
// BoolSlice returns the address of a []bool field in the struct.
|
||||
func structPointer_BoolSlice(p structPointer, f field) *[]bool {
|
||||
return structPointer_ifield(p, f).(*[]bool)
|
||||
}
|
||||
|
||||
// String returns the address of a *string field in the struct.
|
||||
func structPointer_String(p structPointer, f field) **string {
|
||||
return structPointer_ifield(p, f).(**string)
|
||||
}
|
||||
|
||||
// StringVal returns the address of a string field in the struct.
|
||||
func structPointer_StringVal(p structPointer, f field) *string {
|
||||
return structPointer_ifield(p, f).(*string)
|
||||
}
|
||||
|
||||
// StringSlice returns the address of a []string field in the struct.
|
||||
func structPointer_StringSlice(p structPointer, f field) *[]string {
|
||||
return structPointer_ifield(p, f).(*[]string)
|
||||
}
|
||||
|
||||
// Extensions returns the address of an extension map field in the struct.
|
||||
func structPointer_Extensions(p structPointer, f field) *XXX_InternalExtensions {
|
||||
return structPointer_ifield(p, f).(*XXX_InternalExtensions)
|
||||
}
|
||||
|
||||
// ExtMap returns the address of an extension map field in the struct.
|
||||
func structPointer_ExtMap(p structPointer, f field) *map[int32]Extension {
|
||||
return structPointer_ifield(p, f).(*map[int32]Extension)
|
||||
}
|
||||
|
||||
// NewAt returns the reflect.Value for a pointer to a field in the struct.
|
||||
func structPointer_NewAt(p structPointer, f field, typ reflect.Type) reflect.Value {
|
||||
return structPointer_field(p, f).Addr()
|
||||
}
|
||||
|
||||
// SetStructPointer writes a *struct field in the struct.
|
||||
func structPointer_SetStructPointer(p structPointer, f field, q structPointer) {
|
||||
structPointer_field(p, f).Set(q.v)
|
||||
}
|
||||
|
||||
// GetStructPointer reads a *struct field in the struct.
|
||||
func structPointer_GetStructPointer(p structPointer, f field) structPointer {
|
||||
return structPointer{structPointer_field(p, f)}
|
||||
}
|
||||
|
||||
// StructPointerSlice the address of a []*struct field in the struct.
|
||||
func structPointer_StructPointerSlice(p structPointer, f field) structPointerSlice {
|
||||
return structPointerSlice{structPointer_field(p, f)}
|
||||
}
|
||||
|
||||
// A structPointerSlice represents the address of a slice of pointers to structs
|
||||
// (themselves messages or groups). That is, v.Type() is *[]*struct{...}.
|
||||
type structPointerSlice struct {
|
||||
v reflect.Value
|
||||
}
|
||||
|
||||
func (p structPointerSlice) Len() int { return p.v.Len() }
|
||||
func (p structPointerSlice) Index(i int) structPointer { return structPointer{p.v.Index(i)} }
|
||||
func (p structPointerSlice) Append(q structPointer) {
|
||||
p.v.Set(reflect.Append(p.v, q.v))
|
||||
}
|
||||
|
||||
var (
|
||||
int32Type = reflect.TypeOf(int32(0))
|
||||
uint32Type = reflect.TypeOf(uint32(0))
|
||||
float32Type = reflect.TypeOf(float32(0))
|
||||
int64Type = reflect.TypeOf(int64(0))
|
||||
uint64Type = reflect.TypeOf(uint64(0))
|
||||
float64Type = reflect.TypeOf(float64(0))
|
||||
)
|
||||
|
||||
// A word32 represents a field of type *int32, *uint32, *float32, or *enum.
|
||||
// That is, v.Type() is *int32, *uint32, *float32, or *enum and v is assignable.
|
||||
type word32 struct {
|
||||
v reflect.Value
|
||||
}
|
||||
|
||||
// IsNil reports whether p is nil.
|
||||
func word32_IsNil(p word32) bool {
|
||||
func (p pointer) isNil() bool {
|
||||
return p.v.IsNil()
|
||||
}
|
||||
|
||||
// Set sets p to point at a newly allocated word with bits set to x.
|
||||
func word32_Set(p word32, o *Buffer, x uint32) {
|
||||
t := p.v.Type().Elem()
|
||||
switch t {
|
||||
case int32Type:
|
||||
if len(o.int32s) == 0 {
|
||||
o.int32s = make([]int32, uint32PoolSize)
|
||||
}
|
||||
o.int32s[0] = int32(x)
|
||||
p.v.Set(reflect.ValueOf(&o.int32s[0]))
|
||||
o.int32s = o.int32s[1:]
|
||||
return
|
||||
case uint32Type:
|
||||
if len(o.uint32s) == 0 {
|
||||
o.uint32s = make([]uint32, uint32PoolSize)
|
||||
}
|
||||
o.uint32s[0] = x
|
||||
p.v.Set(reflect.ValueOf(&o.uint32s[0]))
|
||||
o.uint32s = o.uint32s[1:]
|
||||
return
|
||||
case float32Type:
|
||||
if len(o.float32s) == 0 {
|
||||
o.float32s = make([]float32, uint32PoolSize)
|
||||
}
|
||||
o.float32s[0] = math.Float32frombits(x)
|
||||
p.v.Set(reflect.ValueOf(&o.float32s[0]))
|
||||
o.float32s = o.float32s[1:]
|
||||
return
|
||||
}
|
||||
|
||||
// must be enum
|
||||
p.v.Set(reflect.New(t))
|
||||
p.v.Elem().SetInt(int64(int32(x)))
|
||||
}
|
||||
|
||||
// Get gets the bits pointed at by p, as a uint32.
|
||||
func word32_Get(p word32) uint32 {
|
||||
elem := p.v.Elem()
|
||||
switch elem.Kind() {
|
||||
case reflect.Int32:
|
||||
return uint32(elem.Int())
|
||||
case reflect.Uint32:
|
||||
return uint32(elem.Uint())
|
||||
case reflect.Float32:
|
||||
return math.Float32bits(float32(elem.Float()))
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
// Word32 returns a reference to a *int32, *uint32, *float32, or *enum field in the struct.
|
||||
func structPointer_Word32(p structPointer, f field) word32 {
|
||||
return word32{structPointer_field(p, f)}
|
||||
}
|
||||
|
||||
// A word32Val represents a field of type int32, uint32, float32, or enum.
|
||||
// That is, v.Type() is int32, uint32, float32, or enum and v is assignable.
|
||||
type word32Val struct {
|
||||
v reflect.Value
|
||||
}
|
||||
|
||||
// Set sets *p to x.
|
||||
func word32Val_Set(p word32Val, x uint32) {
|
||||
switch p.v.Type() {
|
||||
case int32Type:
|
||||
p.v.SetInt(int64(x))
|
||||
return
|
||||
case uint32Type:
|
||||
p.v.SetUint(uint64(x))
|
||||
return
|
||||
case float32Type:
|
||||
p.v.SetFloat(float64(math.Float32frombits(x)))
|
||||
return
|
||||
}
|
||||
|
||||
// must be enum
|
||||
p.v.SetInt(int64(int32(x)))
|
||||
}
|
||||
|
||||
// Get gets the bits pointed at by p, as a uint32.
|
||||
func word32Val_Get(p word32Val) uint32 {
|
||||
elem := p.v
|
||||
switch elem.Kind() {
|
||||
case reflect.Int32:
|
||||
return uint32(elem.Int())
|
||||
case reflect.Uint32:
|
||||
return uint32(elem.Uint())
|
||||
case reflect.Float32:
|
||||
return math.Float32bits(float32(elem.Float()))
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
// Word32Val returns a reference to a int32, uint32, float32, or enum field in the struct.
|
||||
func structPointer_Word32Val(p structPointer, f field) word32Val {
|
||||
return word32Val{structPointer_field(p, f)}
|
||||
}
|
||||
|
||||
// A word32Slice is a slice of 32-bit values.
|
||||
// That is, v.Type() is []int32, []uint32, []float32, or []enum.
|
||||
type word32Slice struct {
|
||||
v reflect.Value
|
||||
}
|
||||
|
||||
func (p word32Slice) Append(x uint32) {
|
||||
n, m := p.v.Len(), p.v.Cap()
|
||||
// grow updates the slice s in place to make it one element longer.
|
||||
// s must be addressable.
|
||||
// Returns the (addressable) new element.
|
||||
func grow(s reflect.Value) reflect.Value {
|
||||
n, m := s.Len(), s.Cap()
|
||||
if n < m {
|
||||
p.v.SetLen(n + 1)
|
||||
s.SetLen(n + 1)
|
||||
} else {
|
||||
t := p.v.Type().Elem()
|
||||
p.v.Set(reflect.Append(p.v, reflect.Zero(t)))
|
||||
s.Set(reflect.Append(s, reflect.Zero(s.Type().Elem())))
|
||||
}
|
||||
elem := p.v.Index(n)
|
||||
switch elem.Kind() {
|
||||
case reflect.Int32:
|
||||
elem.SetInt(int64(int32(x)))
|
||||
case reflect.Uint32:
|
||||
elem.SetUint(uint64(x))
|
||||
case reflect.Float32:
|
||||
elem.SetFloat(float64(math.Float32frombits(x)))
|
||||
return s.Index(n)
|
||||
}
|
||||
|
||||
func (p pointer) toInt64() *int64 {
|
||||
return p.v.Interface().(*int64)
|
||||
}
|
||||
func (p pointer) toInt64Ptr() **int64 {
|
||||
return p.v.Interface().(**int64)
|
||||
}
|
||||
func (p pointer) toInt64Slice() *[]int64 {
|
||||
return p.v.Interface().(*[]int64)
|
||||
}
|
||||
|
||||
var int32ptr = reflect.TypeOf((*int32)(nil))
|
||||
|
||||
func (p pointer) toInt32() *int32 {
|
||||
return p.v.Convert(int32ptr).Interface().(*int32)
|
||||
}
|
||||
|
||||
// The toInt32Ptr/Slice methods don't work because of enums.
|
||||
// Instead, we must use set/get methods for the int32ptr/slice case.
|
||||
/*
|
||||
func (p pointer) toInt32Ptr() **int32 {
|
||||
return p.v.Interface().(**int32)
|
||||
}
|
||||
func (p pointer) toInt32Slice() *[]int32 {
|
||||
return p.v.Interface().(*[]int32)
|
||||
}
|
||||
*/
|
||||
func (p pointer) getInt32Ptr() *int32 {
|
||||
if p.v.Type().Elem().Elem() == reflect.TypeOf(int32(0)) {
|
||||
// raw int32 type
|
||||
return p.v.Elem().Interface().(*int32)
|
||||
}
|
||||
// an enum
|
||||
return p.v.Elem().Convert(int32PtrType).Interface().(*int32)
|
||||
}
|
||||
func (p pointer) setInt32Ptr(v int32) {
|
||||
// Allocate value in a *int32. Possibly convert that to a *enum.
|
||||
// Then assign it to a **int32 or **enum.
|
||||
// Note: we can convert *int32 to *enum, but we can't convert
|
||||
// **int32 to **enum!
|
||||
p.v.Elem().Set(reflect.ValueOf(&v).Convert(p.v.Type().Elem()))
|
||||
}
|
||||
|
||||
func (p word32Slice) Len() int {
|
||||
return p.v.Len()
|
||||
}
|
||||
|
||||
func (p word32Slice) Index(i int) uint32 {
|
||||
elem := p.v.Index(i)
|
||||
switch elem.Kind() {
|
||||
case reflect.Int32:
|
||||
return uint32(elem.Int())
|
||||
case reflect.Uint32:
|
||||
return uint32(elem.Uint())
|
||||
case reflect.Float32:
|
||||
return math.Float32bits(float32(elem.Float()))
|
||||
// getInt32Slice copies []int32 from p as a new slice.
|
||||
// This behavior differs from the implementation in pointer_unsafe.go.
|
||||
func (p pointer) getInt32Slice() []int32 {
|
||||
if p.v.Type().Elem().Elem() == reflect.TypeOf(int32(0)) {
|
||||
// raw int32 type
|
||||
return p.v.Elem().Interface().([]int32)
|
||||
}
|
||||
panic("unreachable")
|
||||
// an enum
|
||||
// Allocate a []int32, then assign []enum's values into it.
|
||||
// Note: we can't convert []enum to []int32.
|
||||
slice := p.v.Elem()
|
||||
s := make([]int32, slice.Len())
|
||||
for i := 0; i < slice.Len(); i++ {
|
||||
s[i] = int32(slice.Index(i).Int())
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// Word32Slice returns a reference to a []int32, []uint32, []float32, or []enum field in the struct.
|
||||
func structPointer_Word32Slice(p structPointer, f field) word32Slice {
|
||||
return word32Slice{structPointer_field(p, f)}
|
||||
}
|
||||
|
||||
// word64 is like word32 but for 64-bit values.
|
||||
type word64 struct {
|
||||
v reflect.Value
|
||||
}
|
||||
|
||||
func word64_Set(p word64, o *Buffer, x uint64) {
|
||||
t := p.v.Type().Elem()
|
||||
switch t {
|
||||
case int64Type:
|
||||
if len(o.int64s) == 0 {
|
||||
o.int64s = make([]int64, uint64PoolSize)
|
||||
}
|
||||
o.int64s[0] = int64(x)
|
||||
p.v.Set(reflect.ValueOf(&o.int64s[0]))
|
||||
o.int64s = o.int64s[1:]
|
||||
return
|
||||
case uint64Type:
|
||||
if len(o.uint64s) == 0 {
|
||||
o.uint64s = make([]uint64, uint64PoolSize)
|
||||
}
|
||||
o.uint64s[0] = x
|
||||
p.v.Set(reflect.ValueOf(&o.uint64s[0]))
|
||||
o.uint64s = o.uint64s[1:]
|
||||
return
|
||||
case float64Type:
|
||||
if len(o.float64s) == 0 {
|
||||
o.float64s = make([]float64, uint64PoolSize)
|
||||
}
|
||||
o.float64s[0] = math.Float64frombits(x)
|
||||
p.v.Set(reflect.ValueOf(&o.float64s[0]))
|
||||
o.float64s = o.float64s[1:]
|
||||
// setInt32Slice copies []int32 into p as a new slice.
|
||||
// This behavior differs from the implementation in pointer_unsafe.go.
|
||||
func (p pointer) setInt32Slice(v []int32) {
|
||||
if p.v.Type().Elem().Elem() == reflect.TypeOf(int32(0)) {
|
||||
// raw int32 type
|
||||
p.v.Elem().Set(reflect.ValueOf(v))
|
||||
return
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
func word64_IsNil(p word64) bool {
|
||||
return p.v.IsNil()
|
||||
}
|
||||
|
||||
func word64_Get(p word64) uint64 {
|
||||
elem := p.v.Elem()
|
||||
switch elem.Kind() {
|
||||
case reflect.Int64:
|
||||
return uint64(elem.Int())
|
||||
case reflect.Uint64:
|
||||
return elem.Uint()
|
||||
case reflect.Float64:
|
||||
return math.Float64bits(elem.Float())
|
||||
// an enum
|
||||
// Allocate a []enum, then assign []int32's values into it.
|
||||
// Note: we can't convert []enum to []int32.
|
||||
slice := reflect.MakeSlice(p.v.Type().Elem(), len(v), cap(v))
|
||||
for i, x := range v {
|
||||
slice.Index(i).SetInt(int64(x))
|
||||
}
|
||||
panic("unreachable")
|
||||
p.v.Elem().Set(slice)
|
||||
}
|
||||
func (p pointer) appendInt32Slice(v int32) {
|
||||
grow(p.v.Elem()).SetInt(int64(v))
|
||||
}
|
||||
|
||||
func structPointer_Word64(p structPointer, f field) word64 {
|
||||
return word64{structPointer_field(p, f)}
|
||||
func (p pointer) toUint64() *uint64 {
|
||||
return p.v.Interface().(*uint64)
|
||||
}
|
||||
func (p pointer) toUint64Ptr() **uint64 {
|
||||
return p.v.Interface().(**uint64)
|
||||
}
|
||||
func (p pointer) toUint64Slice() *[]uint64 {
|
||||
return p.v.Interface().(*[]uint64)
|
||||
}
|
||||
func (p pointer) toUint32() *uint32 {
|
||||
return p.v.Interface().(*uint32)
|
||||
}
|
||||
func (p pointer) toUint32Ptr() **uint32 {
|
||||
return p.v.Interface().(**uint32)
|
||||
}
|
||||
func (p pointer) toUint32Slice() *[]uint32 {
|
||||
return p.v.Interface().(*[]uint32)
|
||||
}
|
||||
func (p pointer) toBool() *bool {
|
||||
return p.v.Interface().(*bool)
|
||||
}
|
||||
func (p pointer) toBoolPtr() **bool {
|
||||
return p.v.Interface().(**bool)
|
||||
}
|
||||
func (p pointer) toBoolSlice() *[]bool {
|
||||
return p.v.Interface().(*[]bool)
|
||||
}
|
||||
func (p pointer) toFloat64() *float64 {
|
||||
return p.v.Interface().(*float64)
|
||||
}
|
||||
func (p pointer) toFloat64Ptr() **float64 {
|
||||
return p.v.Interface().(**float64)
|
||||
}
|
||||
func (p pointer) toFloat64Slice() *[]float64 {
|
||||
return p.v.Interface().(*[]float64)
|
||||
}
|
||||
func (p pointer) toFloat32() *float32 {
|
||||
return p.v.Interface().(*float32)
|
||||
}
|
||||
func (p pointer) toFloat32Ptr() **float32 {
|
||||
return p.v.Interface().(**float32)
|
||||
}
|
||||
func (p pointer) toFloat32Slice() *[]float32 {
|
||||
return p.v.Interface().(*[]float32)
|
||||
}
|
||||
func (p pointer) toString() *string {
|
||||
return p.v.Interface().(*string)
|
||||
}
|
||||
func (p pointer) toStringPtr() **string {
|
||||
return p.v.Interface().(**string)
|
||||
}
|
||||
func (p pointer) toStringSlice() *[]string {
|
||||
return p.v.Interface().(*[]string)
|
||||
}
|
||||
func (p pointer) toBytes() *[]byte {
|
||||
return p.v.Interface().(*[]byte)
|
||||
}
|
||||
func (p pointer) toBytesSlice() *[][]byte {
|
||||
return p.v.Interface().(*[][]byte)
|
||||
}
|
||||
func (p pointer) toExtensions() *XXX_InternalExtensions {
|
||||
return p.v.Interface().(*XXX_InternalExtensions)
|
||||
}
|
||||
func (p pointer) toOldExtensions() *map[int32]Extension {
|
||||
return p.v.Interface().(*map[int32]Extension)
|
||||
}
|
||||
func (p pointer) getPointer() pointer {
|
||||
return pointer{v: p.v.Elem()}
|
||||
}
|
||||
func (p pointer) setPointer(q pointer) {
|
||||
p.v.Elem().Set(q.v)
|
||||
}
|
||||
func (p pointer) appendPointer(q pointer) {
|
||||
grow(p.v.Elem()).Set(q.v)
|
||||
}
|
||||
|
||||
// word64Val is like word32Val but for 64-bit values.
|
||||
type word64Val struct {
|
||||
v reflect.Value
|
||||
// getPointerSlice copies []*T from p as a new []pointer.
|
||||
// This behavior differs from the implementation in pointer_unsafe.go.
|
||||
func (p pointer) getPointerSlice() []pointer {
|
||||
if p.v.IsNil() {
|
||||
return nil
|
||||
}
|
||||
n := p.v.Elem().Len()
|
||||
s := make([]pointer, n)
|
||||
for i := 0; i < n; i++ {
|
||||
s[i] = pointer{v: p.v.Elem().Index(i)}
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func word64Val_Set(p word64Val, o *Buffer, x uint64) {
|
||||
switch p.v.Type() {
|
||||
case int64Type:
|
||||
p.v.SetInt(int64(x))
|
||||
return
|
||||
case uint64Type:
|
||||
p.v.SetUint(x)
|
||||
return
|
||||
case float64Type:
|
||||
p.v.SetFloat(math.Float64frombits(x))
|
||||
// setPointerSlice copies []pointer into p as a new []*T.
|
||||
// This behavior differs from the implementation in pointer_unsafe.go.
|
||||
func (p pointer) setPointerSlice(v []pointer) {
|
||||
if v == nil {
|
||||
p.v.Elem().Set(reflect.New(p.v.Elem().Type()).Elem())
|
||||
return
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
func word64Val_Get(p word64Val) uint64 {
|
||||
elem := p.v
|
||||
switch elem.Kind() {
|
||||
case reflect.Int64:
|
||||
return uint64(elem.Int())
|
||||
case reflect.Uint64:
|
||||
return elem.Uint()
|
||||
case reflect.Float64:
|
||||
return math.Float64bits(elem.Float())
|
||||
s := reflect.MakeSlice(p.v.Elem().Type(), 0, len(v))
|
||||
for _, p := range v {
|
||||
s = reflect.Append(s, p.v)
|
||||
}
|
||||
panic("unreachable")
|
||||
p.v.Elem().Set(s)
|
||||
}
|
||||
|
||||
func structPointer_Word64Val(p structPointer, f field) word64Val {
|
||||
return word64Val{structPointer_field(p, f)}
|
||||
}
|
||||
|
||||
type word64Slice struct {
|
||||
v reflect.Value
|
||||
}
|
||||
|
||||
func (p word64Slice) Append(x uint64) {
|
||||
n, m := p.v.Len(), p.v.Cap()
|
||||
if n < m {
|
||||
p.v.SetLen(n + 1)
|
||||
} else {
|
||||
t := p.v.Type().Elem()
|
||||
p.v.Set(reflect.Append(p.v, reflect.Zero(t)))
|
||||
}
|
||||
elem := p.v.Index(n)
|
||||
switch elem.Kind() {
|
||||
case reflect.Int64:
|
||||
elem.SetInt(int64(int64(x)))
|
||||
case reflect.Uint64:
|
||||
elem.SetUint(uint64(x))
|
||||
case reflect.Float64:
|
||||
elem.SetFloat(float64(math.Float64frombits(x)))
|
||||
// getInterfacePointer returns a pointer that points to the
|
||||
// interface data of the interface pointed by p.
|
||||
func (p pointer) getInterfacePointer() pointer {
|
||||
if p.v.Elem().IsNil() {
|
||||
return pointer{v: p.v.Elem()}
|
||||
}
|
||||
return pointer{v: p.v.Elem().Elem().Elem().Field(0).Addr()} // *interface -> interface -> *struct -> struct
|
||||
}
|
||||
|
||||
func (p word64Slice) Len() int {
|
||||
return p.v.Len()
|
||||
func (p pointer) asPointerTo(t reflect.Type) reflect.Value {
|
||||
// TODO: check that p.v.Type().Elem() == t?
|
||||
return p.v
|
||||
}
|
||||
|
||||
func (p word64Slice) Index(i int) uint64 {
|
||||
elem := p.v.Index(i)
|
||||
switch elem.Kind() {
|
||||
case reflect.Int64:
|
||||
return uint64(elem.Int())
|
||||
case reflect.Uint64:
|
||||
return uint64(elem.Uint())
|
||||
case reflect.Float64:
|
||||
return math.Float64bits(float64(elem.Float()))
|
||||
}
|
||||
panic("unreachable")
|
||||
func atomicLoadUnmarshalInfo(p **unmarshalInfo) *unmarshalInfo {
|
||||
atomicLock.Lock()
|
||||
defer atomicLock.Unlock()
|
||||
return *p
|
||||
}
|
||||
func atomicStoreUnmarshalInfo(p **unmarshalInfo, v *unmarshalInfo) {
|
||||
atomicLock.Lock()
|
||||
defer atomicLock.Unlock()
|
||||
*p = v
|
||||
}
|
||||
func atomicLoadMarshalInfo(p **marshalInfo) *marshalInfo {
|
||||
atomicLock.Lock()
|
||||
defer atomicLock.Unlock()
|
||||
return *p
|
||||
}
|
||||
func atomicStoreMarshalInfo(p **marshalInfo, v *marshalInfo) {
|
||||
atomicLock.Lock()
|
||||
defer atomicLock.Unlock()
|
||||
*p = v
|
||||
}
|
||||
func atomicLoadMergeInfo(p **mergeInfo) *mergeInfo {
|
||||
atomicLock.Lock()
|
||||
defer atomicLock.Unlock()
|
||||
return *p
|
||||
}
|
||||
func atomicStoreMergeInfo(p **mergeInfo, v *mergeInfo) {
|
||||
atomicLock.Lock()
|
||||
defer atomicLock.Unlock()
|
||||
*p = v
|
||||
}
|
||||
func atomicLoadDiscardInfo(p **discardInfo) *discardInfo {
|
||||
atomicLock.Lock()
|
||||
defer atomicLock.Unlock()
|
||||
return *p
|
||||
}
|
||||
func atomicStoreDiscardInfo(p **discardInfo, v *discardInfo) {
|
||||
atomicLock.Lock()
|
||||
defer atomicLock.Unlock()
|
||||
*p = v
|
||||
}
|
||||
|
||||
func structPointer_Word64Slice(p structPointer, f field) word64Slice {
|
||||
return word64Slice{structPointer_field(p, f)}
|
||||
}
|
||||
var atomicLock sync.Mutex
|
||||
|
427
vendor/github.com/golang/protobuf/proto/pointer_unsafe.go
generated
vendored
427
vendor/github.com/golang/protobuf/proto/pointer_unsafe.go
generated
vendored
@ -29,7 +29,7 @@
|
||||
// (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 !appengine,!js
|
||||
// +build !purego,!appengine,!js
|
||||
|
||||
// This file contains the implementation of the proto field accesses using package unsafe.
|
||||
|
||||
@ -37,38 +37,13 @@ package proto
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sync/atomic"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// NOTE: These type_Foo functions would more idiomatically be methods,
|
||||
// but Go does not allow methods on pointer types, and we must preserve
|
||||
// some pointer type for the garbage collector. We use these
|
||||
// funcs with clunky names as our poor approximation to methods.
|
||||
//
|
||||
// An alternative would be
|
||||
// type structPointer struct { p unsafe.Pointer }
|
||||
// but that does not registerize as well.
|
||||
const unsafeAllowed = true
|
||||
|
||||
// A structPointer is a pointer to a struct.
|
||||
type structPointer unsafe.Pointer
|
||||
|
||||
// toStructPointer returns a structPointer equivalent to the given reflect value.
|
||||
func toStructPointer(v reflect.Value) structPointer {
|
||||
return structPointer(unsafe.Pointer(v.Pointer()))
|
||||
}
|
||||
|
||||
// IsNil reports whether p is nil.
|
||||
func structPointer_IsNil(p structPointer) bool {
|
||||
return p == nil
|
||||
}
|
||||
|
||||
// Interface returns the struct pointer, assumed to have element type t,
|
||||
// as an interface value.
|
||||
func structPointer_Interface(p structPointer, t reflect.Type) interface{} {
|
||||
return reflect.NewAt(t, unsafe.Pointer(p)).Interface()
|
||||
}
|
||||
|
||||
// A field identifies a field in a struct, accessible from a structPointer.
|
||||
// A field identifies a field in a struct, accessible from a pointer.
|
||||
// In this implementation, a field is identified by its byte offset from the start of the struct.
|
||||
type field uintptr
|
||||
|
||||
@ -80,191 +55,259 @@ func toField(f *reflect.StructField) field {
|
||||
// invalidField is an invalid field identifier.
|
||||
const invalidField = ^field(0)
|
||||
|
||||
// zeroField is a noop when calling pointer.offset.
|
||||
const zeroField = field(0)
|
||||
|
||||
// IsValid reports whether the field identifier is valid.
|
||||
func (f field) IsValid() bool {
|
||||
return f != ^field(0)
|
||||
return f != invalidField
|
||||
}
|
||||
|
||||
// Bytes returns the address of a []byte field in the struct.
|
||||
func structPointer_Bytes(p structPointer, f field) *[]byte {
|
||||
return (*[]byte)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
||||
// The pointer type below is for the new table-driven encoder/decoder.
|
||||
// The implementation here uses unsafe.Pointer to create a generic pointer.
|
||||
// In pointer_reflect.go we use reflect instead of unsafe to implement
|
||||
// the same (but slower) interface.
|
||||
type pointer struct {
|
||||
p unsafe.Pointer
|
||||
}
|
||||
|
||||
// BytesSlice returns the address of a [][]byte field in the struct.
|
||||
func structPointer_BytesSlice(p structPointer, f field) *[][]byte {
|
||||
return (*[][]byte)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
||||
// size of pointer
|
||||
var ptrSize = unsafe.Sizeof(uintptr(0))
|
||||
|
||||
// toPointer converts an interface of pointer type to a pointer
|
||||
// that points to the same target.
|
||||
func toPointer(i *Message) pointer {
|
||||
// Super-tricky - read pointer out of data word of interface value.
|
||||
// Saves ~25ns over the equivalent:
|
||||
// return valToPointer(reflect.ValueOf(*i))
|
||||
return pointer{p: (*[2]unsafe.Pointer)(unsafe.Pointer(i))[1]}
|
||||
}
|
||||
|
||||
// Bool returns the address of a *bool field in the struct.
|
||||
func structPointer_Bool(p structPointer, f field) **bool {
|
||||
return (**bool)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
||||
}
|
||||
|
||||
// BoolVal returns the address of a bool field in the struct.
|
||||
func structPointer_BoolVal(p structPointer, f field) *bool {
|
||||
return (*bool)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
||||
}
|
||||
|
||||
// BoolSlice returns the address of a []bool field in the struct.
|
||||
func structPointer_BoolSlice(p structPointer, f field) *[]bool {
|
||||
return (*[]bool)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
||||
}
|
||||
|
||||
// String returns the address of a *string field in the struct.
|
||||
func structPointer_String(p structPointer, f field) **string {
|
||||
return (**string)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
||||
}
|
||||
|
||||
// StringVal returns the address of a string field in the struct.
|
||||
func structPointer_StringVal(p structPointer, f field) *string {
|
||||
return (*string)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
||||
}
|
||||
|
||||
// StringSlice returns the address of a []string field in the struct.
|
||||
func structPointer_StringSlice(p structPointer, f field) *[]string {
|
||||
return (*[]string)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
||||
}
|
||||
|
||||
// ExtMap returns the address of an extension map field in the struct.
|
||||
func structPointer_Extensions(p structPointer, f field) *XXX_InternalExtensions {
|
||||
return (*XXX_InternalExtensions)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
||||
}
|
||||
|
||||
func structPointer_ExtMap(p structPointer, f field) *map[int32]Extension {
|
||||
return (*map[int32]Extension)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
||||
}
|
||||
|
||||
// NewAt returns the reflect.Value for a pointer to a field in the struct.
|
||||
func structPointer_NewAt(p structPointer, f field, typ reflect.Type) reflect.Value {
|
||||
return reflect.NewAt(typ, unsafe.Pointer(uintptr(p)+uintptr(f)))
|
||||
}
|
||||
|
||||
// SetStructPointer writes a *struct field in the struct.
|
||||
func structPointer_SetStructPointer(p structPointer, f field, q structPointer) {
|
||||
*(*structPointer)(unsafe.Pointer(uintptr(p) + uintptr(f))) = q
|
||||
}
|
||||
|
||||
// GetStructPointer reads a *struct field in the struct.
|
||||
func structPointer_GetStructPointer(p structPointer, f field) structPointer {
|
||||
return *(*structPointer)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
||||
}
|
||||
|
||||
// StructPointerSlice the address of a []*struct field in the struct.
|
||||
func structPointer_StructPointerSlice(p structPointer, f field) *structPointerSlice {
|
||||
return (*structPointerSlice)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
||||
}
|
||||
|
||||
// A structPointerSlice represents a slice of pointers to structs (themselves submessages or groups).
|
||||
type structPointerSlice []structPointer
|
||||
|
||||
func (v *structPointerSlice) Len() int { return len(*v) }
|
||||
func (v *structPointerSlice) Index(i int) structPointer { return (*v)[i] }
|
||||
func (v *structPointerSlice) Append(p structPointer) { *v = append(*v, p) }
|
||||
|
||||
// A word32 is the address of a "pointer to 32-bit value" field.
|
||||
type word32 **uint32
|
||||
|
||||
// IsNil reports whether *v is nil.
|
||||
func word32_IsNil(p word32) bool {
|
||||
return *p == nil
|
||||
}
|
||||
|
||||
// Set sets *v to point at a newly allocated word set to x.
|
||||
func word32_Set(p word32, o *Buffer, x uint32) {
|
||||
if len(o.uint32s) == 0 {
|
||||
o.uint32s = make([]uint32, uint32PoolSize)
|
||||
// toAddrPointer converts an interface to a pointer that points to
|
||||
// the interface data.
|
||||
func toAddrPointer(i *interface{}, isptr, deref bool) (p pointer) {
|
||||
// Super-tricky - read or get the address of data word of interface value.
|
||||
if isptr {
|
||||
// The interface is of pointer type, thus it is a direct interface.
|
||||
// The data word is the pointer data itself. We take its address.
|
||||
p = pointer{p: unsafe.Pointer(uintptr(unsafe.Pointer(i)) + ptrSize)}
|
||||
} else {
|
||||
// The interface is not of pointer type. The data word is the pointer
|
||||
// to the data.
|
||||
p = pointer{p: (*[2]unsafe.Pointer)(unsafe.Pointer(i))[1]}
|
||||
}
|
||||
o.uint32s[0] = x
|
||||
*p = &o.uint32s[0]
|
||||
o.uint32s = o.uint32s[1:]
|
||||
}
|
||||
|
||||
// Get gets the value pointed at by *v.
|
||||
func word32_Get(p word32) uint32 {
|
||||
return **p
|
||||
}
|
||||
|
||||
// Word32 returns the address of a *int32, *uint32, *float32, or *enum field in the struct.
|
||||
func structPointer_Word32(p structPointer, f field) word32 {
|
||||
return word32((**uint32)(unsafe.Pointer(uintptr(p) + uintptr(f))))
|
||||
}
|
||||
|
||||
// A word32Val is the address of a 32-bit value field.
|
||||
type word32Val *uint32
|
||||
|
||||
// Set sets *p to x.
|
||||
func word32Val_Set(p word32Val, x uint32) {
|
||||
*p = x
|
||||
}
|
||||
|
||||
// Get gets the value pointed at by p.
|
||||
func word32Val_Get(p word32Val) uint32 {
|
||||
return *p
|
||||
}
|
||||
|
||||
// Word32Val returns the address of a *int32, *uint32, *float32, or *enum field in the struct.
|
||||
func structPointer_Word32Val(p structPointer, f field) word32Val {
|
||||
return word32Val((*uint32)(unsafe.Pointer(uintptr(p) + uintptr(f))))
|
||||
}
|
||||
|
||||
// A word32Slice is a slice of 32-bit values.
|
||||
type word32Slice []uint32
|
||||
|
||||
func (v *word32Slice) Append(x uint32) { *v = append(*v, x) }
|
||||
func (v *word32Slice) Len() int { return len(*v) }
|
||||
func (v *word32Slice) Index(i int) uint32 { return (*v)[i] }
|
||||
|
||||
// Word32Slice returns the address of a []int32, []uint32, []float32, or []enum field in the struct.
|
||||
func structPointer_Word32Slice(p structPointer, f field) *word32Slice {
|
||||
return (*word32Slice)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
||||
}
|
||||
|
||||
// word64 is like word32 but for 64-bit values.
|
||||
type word64 **uint64
|
||||
|
||||
func word64_Set(p word64, o *Buffer, x uint64) {
|
||||
if len(o.uint64s) == 0 {
|
||||
o.uint64s = make([]uint64, uint64PoolSize)
|
||||
if deref {
|
||||
p.p = *(*unsafe.Pointer)(p.p)
|
||||
}
|
||||
o.uint64s[0] = x
|
||||
*p = &o.uint64s[0]
|
||||
o.uint64s = o.uint64s[1:]
|
||||
return p
|
||||
}
|
||||
|
||||
func word64_IsNil(p word64) bool {
|
||||
return *p == nil
|
||||
// valToPointer converts v to a pointer. v must be of pointer type.
|
||||
func valToPointer(v reflect.Value) pointer {
|
||||
return pointer{p: unsafe.Pointer(v.Pointer())}
|
||||
}
|
||||
|
||||
func word64_Get(p word64) uint64 {
|
||||
return **p
|
||||
// offset converts from a pointer to a structure to a pointer to
|
||||
// one of its fields.
|
||||
func (p pointer) offset(f field) pointer {
|
||||
// For safety, we should panic if !f.IsValid, however calling panic causes
|
||||
// this to no longer be inlineable, which is a serious performance cost.
|
||||
/*
|
||||
if !f.IsValid() {
|
||||
panic("invalid field")
|
||||
}
|
||||
*/
|
||||
return pointer{p: unsafe.Pointer(uintptr(p.p) + uintptr(f))}
|
||||
}
|
||||
|
||||
func structPointer_Word64(p structPointer, f field) word64 {
|
||||
return word64((**uint64)(unsafe.Pointer(uintptr(p) + uintptr(f))))
|
||||
func (p pointer) isNil() bool {
|
||||
return p.p == nil
|
||||
}
|
||||
|
||||
// word64Val is like word32Val but for 64-bit values.
|
||||
type word64Val *uint64
|
||||
|
||||
func word64Val_Set(p word64Val, o *Buffer, x uint64) {
|
||||
*p = x
|
||||
func (p pointer) toInt64() *int64 {
|
||||
return (*int64)(p.p)
|
||||
}
|
||||
func (p pointer) toInt64Ptr() **int64 {
|
||||
return (**int64)(p.p)
|
||||
}
|
||||
func (p pointer) toInt64Slice() *[]int64 {
|
||||
return (*[]int64)(p.p)
|
||||
}
|
||||
func (p pointer) toInt32() *int32 {
|
||||
return (*int32)(p.p)
|
||||
}
|
||||
|
||||
func word64Val_Get(p word64Val) uint64 {
|
||||
return *p
|
||||
// See pointer_reflect.go for why toInt32Ptr/Slice doesn't exist.
|
||||
/*
|
||||
func (p pointer) toInt32Ptr() **int32 {
|
||||
return (**int32)(p.p)
|
||||
}
|
||||
func (p pointer) toInt32Slice() *[]int32 {
|
||||
return (*[]int32)(p.p)
|
||||
}
|
||||
*/
|
||||
func (p pointer) getInt32Ptr() *int32 {
|
||||
return *(**int32)(p.p)
|
||||
}
|
||||
func (p pointer) setInt32Ptr(v int32) {
|
||||
*(**int32)(p.p) = &v
|
||||
}
|
||||
|
||||
func structPointer_Word64Val(p structPointer, f field) word64Val {
|
||||
return word64Val((*uint64)(unsafe.Pointer(uintptr(p) + uintptr(f))))
|
||||
// getInt32Slice loads a []int32 from p.
|
||||
// The value returned is aliased with the original slice.
|
||||
// This behavior differs from the implementation in pointer_reflect.go.
|
||||
func (p pointer) getInt32Slice() []int32 {
|
||||
return *(*[]int32)(p.p)
|
||||
}
|
||||
|
||||
// word64Slice is like word32Slice but for 64-bit values.
|
||||
type word64Slice []uint64
|
||||
|
||||
func (v *word64Slice) Append(x uint64) { *v = append(*v, x) }
|
||||
func (v *word64Slice) Len() int { return len(*v) }
|
||||
func (v *word64Slice) Index(i int) uint64 { return (*v)[i] }
|
||||
|
||||
func structPointer_Word64Slice(p structPointer, f field) *word64Slice {
|
||||
return (*word64Slice)(unsafe.Pointer(uintptr(p) + uintptr(f)))
|
||||
// setInt32Slice stores a []int32 to p.
|
||||
// The value set is aliased with the input slice.
|
||||
// This behavior differs from the implementation in pointer_reflect.go.
|
||||
func (p pointer) setInt32Slice(v []int32) {
|
||||
*(*[]int32)(p.p) = v
|
||||
}
|
||||
|
||||
// TODO: Can we get rid of appendInt32Slice and use setInt32Slice instead?
|
||||
func (p pointer) appendInt32Slice(v int32) {
|
||||
s := (*[]int32)(p.p)
|
||||
*s = append(*s, v)
|
||||
}
|
||||
|
||||
func (p pointer) toUint64() *uint64 {
|
||||
return (*uint64)(p.p)
|
||||
}
|
||||
func (p pointer) toUint64Ptr() **uint64 {
|
||||
return (**uint64)(p.p)
|
||||
}
|
||||
func (p pointer) toUint64Slice() *[]uint64 {
|
||||
return (*[]uint64)(p.p)
|
||||
}
|
||||
func (p pointer) toUint32() *uint32 {
|
||||
return (*uint32)(p.p)
|
||||
}
|
||||
func (p pointer) toUint32Ptr() **uint32 {
|
||||
return (**uint32)(p.p)
|
||||
}
|
||||
func (p pointer) toUint32Slice() *[]uint32 {
|
||||
return (*[]uint32)(p.p)
|
||||
}
|
||||
func (p pointer) toBool() *bool {
|
||||
return (*bool)(p.p)
|
||||
}
|
||||
func (p pointer) toBoolPtr() **bool {
|
||||
return (**bool)(p.p)
|
||||
}
|
||||
func (p pointer) toBoolSlice() *[]bool {
|
||||
return (*[]bool)(p.p)
|
||||
}
|
||||
func (p pointer) toFloat64() *float64 {
|
||||
return (*float64)(p.p)
|
||||
}
|
||||
func (p pointer) toFloat64Ptr() **float64 {
|
||||
return (**float64)(p.p)
|
||||
}
|
||||
func (p pointer) toFloat64Slice() *[]float64 {
|
||||
return (*[]float64)(p.p)
|
||||
}
|
||||
func (p pointer) toFloat32() *float32 {
|
||||
return (*float32)(p.p)
|
||||
}
|
||||
func (p pointer) toFloat32Ptr() **float32 {
|
||||
return (**float32)(p.p)
|
||||
}
|
||||
func (p pointer) toFloat32Slice() *[]float32 {
|
||||
return (*[]float32)(p.p)
|
||||
}
|
||||
func (p pointer) toString() *string {
|
||||
return (*string)(p.p)
|
||||
}
|
||||
func (p pointer) toStringPtr() **string {
|
||||
return (**string)(p.p)
|
||||
}
|
||||
func (p pointer) toStringSlice() *[]string {
|
||||
return (*[]string)(p.p)
|
||||
}
|
||||
func (p pointer) toBytes() *[]byte {
|
||||
return (*[]byte)(p.p)
|
||||
}
|
||||
func (p pointer) toBytesSlice() *[][]byte {
|
||||
return (*[][]byte)(p.p)
|
||||
}
|
||||
func (p pointer) toExtensions() *XXX_InternalExtensions {
|
||||
return (*XXX_InternalExtensions)(p.p)
|
||||
}
|
||||
func (p pointer) toOldExtensions() *map[int32]Extension {
|
||||
return (*map[int32]Extension)(p.p)
|
||||
}
|
||||
|
||||
// getPointerSlice loads []*T from p as a []pointer.
|
||||
// The value returned is aliased with the original slice.
|
||||
// This behavior differs from the implementation in pointer_reflect.go.
|
||||
func (p pointer) getPointerSlice() []pointer {
|
||||
// Super-tricky - p should point to a []*T where T is a
|
||||
// message type. We load it as []pointer.
|
||||
return *(*[]pointer)(p.p)
|
||||
}
|
||||
|
||||
// setPointerSlice stores []pointer into p as a []*T.
|
||||
// The value set is aliased with the input slice.
|
||||
// This behavior differs from the implementation in pointer_reflect.go.
|
||||
func (p pointer) setPointerSlice(v []pointer) {
|
||||
// Super-tricky - p should point to a []*T where T is a
|
||||
// message type. We store it as []pointer.
|
||||
*(*[]pointer)(p.p) = v
|
||||
}
|
||||
|
||||
// getPointer loads the pointer at p and returns it.
|
||||
func (p pointer) getPointer() pointer {
|
||||
return pointer{p: *(*unsafe.Pointer)(p.p)}
|
||||
}
|
||||
|
||||
// setPointer stores the pointer q at p.
|
||||
func (p pointer) setPointer(q pointer) {
|
||||
*(*unsafe.Pointer)(p.p) = q.p
|
||||
}
|
||||
|
||||
// append q to the slice pointed to by p.
|
||||
func (p pointer) appendPointer(q pointer) {
|
||||
s := (*[]unsafe.Pointer)(p.p)
|
||||
*s = append(*s, q.p)
|
||||
}
|
||||
|
||||
// getInterfacePointer returns a pointer that points to the
|
||||
// interface data of the interface pointed by p.
|
||||
func (p pointer) getInterfacePointer() pointer {
|
||||
// Super-tricky - read pointer out of data word of interface value.
|
||||
return pointer{p: (*(*[2]unsafe.Pointer)(p.p))[1]}
|
||||
}
|
||||
|
||||
// asPointerTo returns a reflect.Value that is a pointer to an
|
||||
// object of type t stored at p.
|
||||
func (p pointer) asPointerTo(t reflect.Type) reflect.Value {
|
||||
return reflect.NewAt(t, p.p)
|
||||
}
|
||||
|
||||
func atomicLoadUnmarshalInfo(p **unmarshalInfo) *unmarshalInfo {
|
||||
return (*unmarshalInfo)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(p))))
|
||||
}
|
||||
func atomicStoreUnmarshalInfo(p **unmarshalInfo, v *unmarshalInfo) {
|
||||
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(p)), unsafe.Pointer(v))
|
||||
}
|
||||
func atomicLoadMarshalInfo(p **marshalInfo) *marshalInfo {
|
||||
return (*marshalInfo)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(p))))
|
||||
}
|
||||
func atomicStoreMarshalInfo(p **marshalInfo, v *marshalInfo) {
|
||||
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(p)), unsafe.Pointer(v))
|
||||
}
|
||||
func atomicLoadMergeInfo(p **mergeInfo) *mergeInfo {
|
||||
return (*mergeInfo)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(p))))
|
||||
}
|
||||
func atomicStoreMergeInfo(p **mergeInfo, v *mergeInfo) {
|
||||
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(p)), unsafe.Pointer(v))
|
||||
}
|
||||
func atomicLoadDiscardInfo(p **discardInfo) *discardInfo {
|
||||
return (*discardInfo)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(p))))
|
||||
}
|
||||
func atomicStoreDiscardInfo(p **discardInfo, v *discardInfo) {
|
||||
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(p)), unsafe.Pointer(v))
|
||||
}
|
||||
|
447
vendor/github.com/golang/protobuf/proto/properties.go
generated
vendored
447
vendor/github.com/golang/protobuf/proto/properties.go
generated
vendored
@ -58,42 +58,6 @@ const (
|
||||
WireFixed32 = 5
|
||||
)
|
||||
|
||||
const startSize = 10 // initial slice/string sizes
|
||||
|
||||
// Encoders are defined in encode.go
|
||||
// An encoder outputs the full representation of a field, including its
|
||||
// tag and encoder type.
|
||||
type encoder func(p *Buffer, prop *Properties, base structPointer) error
|
||||
|
||||
// A valueEncoder encodes a single integer in a particular encoding.
|
||||
type valueEncoder func(o *Buffer, x uint64) error
|
||||
|
||||
// Sizers are defined in encode.go
|
||||
// A sizer returns the encoded size of a field, including its tag and encoder
|
||||
// type.
|
||||
type sizer func(prop *Properties, base structPointer) int
|
||||
|
||||
// A valueSizer returns the encoded size of a single integer in a particular
|
||||
// encoding.
|
||||
type valueSizer func(x uint64) int
|
||||
|
||||
// Decoders are defined in decode.go
|
||||
// A decoder creates a value from its wire representation.
|
||||
// Unrecognized subelements are saved in unrec.
|
||||
type decoder func(p *Buffer, prop *Properties, base structPointer) error
|
||||
|
||||
// A valueDecoder decodes a single integer in a particular encoding.
|
||||
type valueDecoder func(o *Buffer) (x uint64, err error)
|
||||
|
||||
// A oneofMarshaler does the marshaling for all oneof fields in a message.
|
||||
type oneofMarshaler func(Message, *Buffer) error
|
||||
|
||||
// A oneofUnmarshaler does the unmarshaling for a oneof field in a message.
|
||||
type oneofUnmarshaler func(Message, int, int, *Buffer) (bool, error)
|
||||
|
||||
// A oneofSizer does the sizing for all oneof fields in a message.
|
||||
type oneofSizer func(Message) int
|
||||
|
||||
// tagMap is an optimization over map[int]int for typical protocol buffer
|
||||
// use-cases. Encoded protocol buffers are often in tag order with small tag
|
||||
// numbers.
|
||||
@ -140,13 +104,6 @@ type StructProperties struct {
|
||||
decoderTags tagMap // map from proto tag to struct field number
|
||||
decoderOrigNames map[string]int // map from original name to struct field number
|
||||
order []int // list of struct field numbers in tag order
|
||||
unrecField field // field id of the XXX_unrecognized []byte field
|
||||
extendable bool // is this an extendable proto
|
||||
|
||||
oneofMarshaler oneofMarshaler
|
||||
oneofUnmarshaler oneofUnmarshaler
|
||||
oneofSizer oneofSizer
|
||||
stype reflect.Type
|
||||
|
||||
// OneofTypes contains information about the oneof fields in this message.
|
||||
// It is keyed by the original name of a field.
|
||||
@ -182,41 +139,24 @@ type Properties struct {
|
||||
Repeated bool
|
||||
Packed bool // relevant for repeated primitives only
|
||||
Enum string // set for enum types only
|
||||
proto3 bool // whether this is known to be a proto3 field; set for []byte only
|
||||
proto3 bool // whether this is known to be a proto3 field
|
||||
oneof bool // whether this is a oneof field
|
||||
|
||||
Default string // default value
|
||||
HasDefault bool // whether an explicit default was provided
|
||||
def_uint64 uint64
|
||||
|
||||
enc encoder
|
||||
valEnc valueEncoder // set for bool and numeric types only
|
||||
field field
|
||||
tagcode []byte // encoding of EncodeVarint((Tag<<3)|WireType)
|
||||
tagbuf [8]byte
|
||||
stype reflect.Type // set for struct types only
|
||||
sprop *StructProperties // set for struct types only
|
||||
isMarshaler bool
|
||||
isUnmarshaler bool
|
||||
stype reflect.Type // set for struct types only
|
||||
sprop *StructProperties // set for struct types only
|
||||
|
||||
mtype reflect.Type // set for map types only
|
||||
mkeyprop *Properties // set for map types only
|
||||
mvalprop *Properties // set for map types only
|
||||
|
||||
size sizer
|
||||
valSize valueSizer // set for bool and numeric types only
|
||||
|
||||
dec decoder
|
||||
valDec valueDecoder // set for bool and numeric types only
|
||||
|
||||
// If this is a packable field, this will be the decoder for the packed version of the field.
|
||||
packedDec decoder
|
||||
mtype reflect.Type // set for map types only
|
||||
MapKeyProp *Properties // set for map types only
|
||||
MapValProp *Properties // set for map types only
|
||||
}
|
||||
|
||||
// String formats the properties in the protobuf struct field tag style.
|
||||
func (p *Properties) String() string {
|
||||
s := p.Wire
|
||||
s = ","
|
||||
s += ","
|
||||
s += strconv.Itoa(p.Tag)
|
||||
if p.Required {
|
||||
s += ",req"
|
||||
@ -262,29 +202,14 @@ func (p *Properties) Parse(s string) {
|
||||
switch p.Wire {
|
||||
case "varint":
|
||||
p.WireType = WireVarint
|
||||
p.valEnc = (*Buffer).EncodeVarint
|
||||
p.valDec = (*Buffer).DecodeVarint
|
||||
p.valSize = sizeVarint
|
||||
case "fixed32":
|
||||
p.WireType = WireFixed32
|
||||
p.valEnc = (*Buffer).EncodeFixed32
|
||||
p.valDec = (*Buffer).DecodeFixed32
|
||||
p.valSize = sizeFixed32
|
||||
case "fixed64":
|
||||
p.WireType = WireFixed64
|
||||
p.valEnc = (*Buffer).EncodeFixed64
|
||||
p.valDec = (*Buffer).DecodeFixed64
|
||||
p.valSize = sizeFixed64
|
||||
case "zigzag32":
|
||||
p.WireType = WireVarint
|
||||
p.valEnc = (*Buffer).EncodeZigzag32
|
||||
p.valDec = (*Buffer).DecodeZigzag32
|
||||
p.valSize = sizeZigzag32
|
||||
case "zigzag64":
|
||||
p.WireType = WireVarint
|
||||
p.valEnc = (*Buffer).EncodeZigzag64
|
||||
p.valDec = (*Buffer).DecodeZigzag64
|
||||
p.valSize = sizeZigzag64
|
||||
case "bytes", "group":
|
||||
p.WireType = WireBytes
|
||||
// no numeric converter for non-numeric types
|
||||
@ -299,6 +224,7 @@ func (p *Properties) Parse(s string) {
|
||||
return
|
||||
}
|
||||
|
||||
outer:
|
||||
for i := 2; i < len(fields); i++ {
|
||||
f := fields[i]
|
||||
switch {
|
||||
@ -326,256 +252,41 @@ func (p *Properties) Parse(s string) {
|
||||
if i+1 < len(fields) {
|
||||
// Commas aren't escaped, and def is always last.
|
||||
p.Default += "," + strings.Join(fields[i+1:], ",")
|
||||
break
|
||||
break outer
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func logNoSliceEnc(t1, t2 reflect.Type) {
|
||||
fmt.Fprintf(os.Stderr, "proto: no slice oenc for %T = []%T\n", t1, t2)
|
||||
}
|
||||
|
||||
var protoMessageType = reflect.TypeOf((*Message)(nil)).Elem()
|
||||
|
||||
// Initialize the fields for encoding and decoding.
|
||||
func (p *Properties) setEncAndDec(typ reflect.Type, f *reflect.StructField, lockGetProp bool) {
|
||||
p.enc = nil
|
||||
p.dec = nil
|
||||
p.size = nil
|
||||
|
||||
// setFieldProps initializes the field properties for submessages and maps.
|
||||
func (p *Properties) setFieldProps(typ reflect.Type, f *reflect.StructField, lockGetProp bool) {
|
||||
switch t1 := typ; t1.Kind() {
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "proto: no coders for %v\n", t1)
|
||||
|
||||
// proto3 scalar types
|
||||
|
||||
case reflect.Bool:
|
||||
p.enc = (*Buffer).enc_proto3_bool
|
||||
p.dec = (*Buffer).dec_proto3_bool
|
||||
p.size = size_proto3_bool
|
||||
case reflect.Int32:
|
||||
p.enc = (*Buffer).enc_proto3_int32
|
||||
p.dec = (*Buffer).dec_proto3_int32
|
||||
p.size = size_proto3_int32
|
||||
case reflect.Uint32:
|
||||
p.enc = (*Buffer).enc_proto3_uint32
|
||||
p.dec = (*Buffer).dec_proto3_int32 // can reuse
|
||||
p.size = size_proto3_uint32
|
||||
case reflect.Int64, reflect.Uint64:
|
||||
p.enc = (*Buffer).enc_proto3_int64
|
||||
p.dec = (*Buffer).dec_proto3_int64
|
||||
p.size = size_proto3_int64
|
||||
case reflect.Float32:
|
||||
p.enc = (*Buffer).enc_proto3_uint32 // can just treat them as bits
|
||||
p.dec = (*Buffer).dec_proto3_int32
|
||||
p.size = size_proto3_uint32
|
||||
case reflect.Float64:
|
||||
p.enc = (*Buffer).enc_proto3_int64 // can just treat them as bits
|
||||
p.dec = (*Buffer).dec_proto3_int64
|
||||
p.size = size_proto3_int64
|
||||
case reflect.String:
|
||||
p.enc = (*Buffer).enc_proto3_string
|
||||
p.dec = (*Buffer).dec_proto3_string
|
||||
p.size = size_proto3_string
|
||||
|
||||
case reflect.Ptr:
|
||||
switch t2 := t1.Elem(); t2.Kind() {
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "proto: no encoder function for %v -> %v\n", t1, t2)
|
||||
break
|
||||
case reflect.Bool:
|
||||
p.enc = (*Buffer).enc_bool
|
||||
p.dec = (*Buffer).dec_bool
|
||||
p.size = size_bool
|
||||
case reflect.Int32:
|
||||
p.enc = (*Buffer).enc_int32
|
||||
p.dec = (*Buffer).dec_int32
|
||||
p.size = size_int32
|
||||
case reflect.Uint32:
|
||||
p.enc = (*Buffer).enc_uint32
|
||||
p.dec = (*Buffer).dec_int32 // can reuse
|
||||
p.size = size_uint32
|
||||
case reflect.Int64, reflect.Uint64:
|
||||
p.enc = (*Buffer).enc_int64
|
||||
p.dec = (*Buffer).dec_int64
|
||||
p.size = size_int64
|
||||
case reflect.Float32:
|
||||
p.enc = (*Buffer).enc_uint32 // can just treat them as bits
|
||||
p.dec = (*Buffer).dec_int32
|
||||
p.size = size_uint32
|
||||
case reflect.Float64:
|
||||
p.enc = (*Buffer).enc_int64 // can just treat them as bits
|
||||
p.dec = (*Buffer).dec_int64
|
||||
p.size = size_int64
|
||||
case reflect.String:
|
||||
p.enc = (*Buffer).enc_string
|
||||
p.dec = (*Buffer).dec_string
|
||||
p.size = size_string
|
||||
case reflect.Struct:
|
||||
if t1.Elem().Kind() == reflect.Struct {
|
||||
p.stype = t1.Elem()
|
||||
p.isMarshaler = isMarshaler(t1)
|
||||
p.isUnmarshaler = isUnmarshaler(t1)
|
||||
if p.Wire == "bytes" {
|
||||
p.enc = (*Buffer).enc_struct_message
|
||||
p.dec = (*Buffer).dec_struct_message
|
||||
p.size = size_struct_message
|
||||
} else {
|
||||
p.enc = (*Buffer).enc_struct_group
|
||||
p.dec = (*Buffer).dec_struct_group
|
||||
p.size = size_struct_group
|
||||
}
|
||||
}
|
||||
|
||||
case reflect.Slice:
|
||||
switch t2 := t1.Elem(); t2.Kind() {
|
||||
default:
|
||||
logNoSliceEnc(t1, t2)
|
||||
break
|
||||
case reflect.Bool:
|
||||
if p.Packed {
|
||||
p.enc = (*Buffer).enc_slice_packed_bool
|
||||
p.size = size_slice_packed_bool
|
||||
} else {
|
||||
p.enc = (*Buffer).enc_slice_bool
|
||||
p.size = size_slice_bool
|
||||
}
|
||||
p.dec = (*Buffer).dec_slice_bool
|
||||
p.packedDec = (*Buffer).dec_slice_packed_bool
|
||||
case reflect.Int32:
|
||||
if p.Packed {
|
||||
p.enc = (*Buffer).enc_slice_packed_int32
|
||||
p.size = size_slice_packed_int32
|
||||
} else {
|
||||
p.enc = (*Buffer).enc_slice_int32
|
||||
p.size = size_slice_int32
|
||||
}
|
||||
p.dec = (*Buffer).dec_slice_int32
|
||||
p.packedDec = (*Buffer).dec_slice_packed_int32
|
||||
case reflect.Uint32:
|
||||
if p.Packed {
|
||||
p.enc = (*Buffer).enc_slice_packed_uint32
|
||||
p.size = size_slice_packed_uint32
|
||||
} else {
|
||||
p.enc = (*Buffer).enc_slice_uint32
|
||||
p.size = size_slice_uint32
|
||||
}
|
||||
p.dec = (*Buffer).dec_slice_int32
|
||||
p.packedDec = (*Buffer).dec_slice_packed_int32
|
||||
case reflect.Int64, reflect.Uint64:
|
||||
if p.Packed {
|
||||
p.enc = (*Buffer).enc_slice_packed_int64
|
||||
p.size = size_slice_packed_int64
|
||||
} else {
|
||||
p.enc = (*Buffer).enc_slice_int64
|
||||
p.size = size_slice_int64
|
||||
}
|
||||
p.dec = (*Buffer).dec_slice_int64
|
||||
p.packedDec = (*Buffer).dec_slice_packed_int64
|
||||
case reflect.Uint8:
|
||||
p.dec = (*Buffer).dec_slice_byte
|
||||
if p.proto3 {
|
||||
p.enc = (*Buffer).enc_proto3_slice_byte
|
||||
p.size = size_proto3_slice_byte
|
||||
} else {
|
||||
p.enc = (*Buffer).enc_slice_byte
|
||||
p.size = size_slice_byte
|
||||
}
|
||||
case reflect.Float32, reflect.Float64:
|
||||
switch t2.Bits() {
|
||||
case 32:
|
||||
// can just treat them as bits
|
||||
if p.Packed {
|
||||
p.enc = (*Buffer).enc_slice_packed_uint32
|
||||
p.size = size_slice_packed_uint32
|
||||
} else {
|
||||
p.enc = (*Buffer).enc_slice_uint32
|
||||
p.size = size_slice_uint32
|
||||
}
|
||||
p.dec = (*Buffer).dec_slice_int32
|
||||
p.packedDec = (*Buffer).dec_slice_packed_int32
|
||||
case 64:
|
||||
// can just treat them as bits
|
||||
if p.Packed {
|
||||
p.enc = (*Buffer).enc_slice_packed_int64
|
||||
p.size = size_slice_packed_int64
|
||||
} else {
|
||||
p.enc = (*Buffer).enc_slice_int64
|
||||
p.size = size_slice_int64
|
||||
}
|
||||
p.dec = (*Buffer).dec_slice_int64
|
||||
p.packedDec = (*Buffer).dec_slice_packed_int64
|
||||
default:
|
||||
logNoSliceEnc(t1, t2)
|
||||
break
|
||||
}
|
||||
case reflect.String:
|
||||
p.enc = (*Buffer).enc_slice_string
|
||||
p.dec = (*Buffer).dec_slice_string
|
||||
p.size = size_slice_string
|
||||
case reflect.Ptr:
|
||||
switch t3 := t2.Elem(); t3.Kind() {
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "proto: no ptr oenc for %T -> %T -> %T\n", t1, t2, t3)
|
||||
break
|
||||
case reflect.Struct:
|
||||
p.stype = t2.Elem()
|
||||
p.isMarshaler = isMarshaler(t2)
|
||||
p.isUnmarshaler = isUnmarshaler(t2)
|
||||
if p.Wire == "bytes" {
|
||||
p.enc = (*Buffer).enc_slice_struct_message
|
||||
p.dec = (*Buffer).dec_slice_struct_message
|
||||
p.size = size_slice_struct_message
|
||||
} else {
|
||||
p.enc = (*Buffer).enc_slice_struct_group
|
||||
p.dec = (*Buffer).dec_slice_struct_group
|
||||
p.size = size_slice_struct_group
|
||||
}
|
||||
}
|
||||
case reflect.Slice:
|
||||
switch t2.Elem().Kind() {
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "proto: no slice elem oenc for %T -> %T -> %T\n", t1, t2, t2.Elem())
|
||||
break
|
||||
case reflect.Uint8:
|
||||
p.enc = (*Buffer).enc_slice_slice_byte
|
||||
p.dec = (*Buffer).dec_slice_slice_byte
|
||||
p.size = size_slice_slice_byte
|
||||
}
|
||||
if t2 := t1.Elem(); t2.Kind() == reflect.Ptr && t2.Elem().Kind() == reflect.Struct {
|
||||
p.stype = t2.Elem()
|
||||
}
|
||||
|
||||
case reflect.Map:
|
||||
p.enc = (*Buffer).enc_new_map
|
||||
p.dec = (*Buffer).dec_new_map
|
||||
p.size = size_new_map
|
||||
|
||||
p.mtype = t1
|
||||
p.mkeyprop = &Properties{}
|
||||
p.mkeyprop.init(reflect.PtrTo(p.mtype.Key()), "Key", f.Tag.Get("protobuf_key"), nil, lockGetProp)
|
||||
p.mvalprop = &Properties{}
|
||||
p.MapKeyProp = &Properties{}
|
||||
p.MapKeyProp.init(reflect.PtrTo(p.mtype.Key()), "Key", f.Tag.Get("protobuf_key"), nil, lockGetProp)
|
||||
p.MapValProp = &Properties{}
|
||||
vtype := p.mtype.Elem()
|
||||
if vtype.Kind() != reflect.Ptr && vtype.Kind() != reflect.Slice {
|
||||
// The value type is not a message (*T) or bytes ([]byte),
|
||||
// so we need encoders for the pointer to this type.
|
||||
vtype = reflect.PtrTo(vtype)
|
||||
}
|
||||
p.mvalprop.init(vtype, "Value", f.Tag.Get("protobuf_val"), nil, lockGetProp)
|
||||
p.MapValProp.init(vtype, "Value", f.Tag.Get("protobuf_val"), nil, lockGetProp)
|
||||
}
|
||||
|
||||
// precalculate tag code
|
||||
wire := p.WireType
|
||||
if p.Packed {
|
||||
wire = WireBytes
|
||||
}
|
||||
x := uint32(p.Tag)<<3 | uint32(wire)
|
||||
i := 0
|
||||
for i = 0; x > 127; i++ {
|
||||
p.tagbuf[i] = 0x80 | uint8(x&0x7F)
|
||||
x >>= 7
|
||||
}
|
||||
p.tagbuf[i] = uint8(x)
|
||||
p.tagcode = p.tagbuf[0 : i+1]
|
||||
|
||||
if p.stype != nil {
|
||||
if lockGetProp {
|
||||
p.sprop = GetProperties(p.stype)
|
||||
@ -586,32 +297,9 @@ func (p *Properties) setEncAndDec(typ reflect.Type, f *reflect.StructField, lock
|
||||
}
|
||||
|
||||
var (
|
||||
marshalerType = reflect.TypeOf((*Marshaler)(nil)).Elem()
|
||||
unmarshalerType = reflect.TypeOf((*Unmarshaler)(nil)).Elem()
|
||||
marshalerType = reflect.TypeOf((*Marshaler)(nil)).Elem()
|
||||
)
|
||||
|
||||
// isMarshaler reports whether type t implements Marshaler.
|
||||
func isMarshaler(t reflect.Type) bool {
|
||||
// We're checking for (likely) pointer-receiver methods
|
||||
// so if t is not a pointer, something is very wrong.
|
||||
// The calls above only invoke isMarshaler on pointer types.
|
||||
if t.Kind() != reflect.Ptr {
|
||||
panic("proto: misuse of isMarshaler")
|
||||
}
|
||||
return t.Implements(marshalerType)
|
||||
}
|
||||
|
||||
// isUnmarshaler reports whether type t implements Unmarshaler.
|
||||
func isUnmarshaler(t reflect.Type) bool {
|
||||
// We're checking for (likely) pointer-receiver methods
|
||||
// so if t is not a pointer, something is very wrong.
|
||||
// The calls above only invoke isUnmarshaler on pointer types.
|
||||
if t.Kind() != reflect.Ptr {
|
||||
panic("proto: misuse of isUnmarshaler")
|
||||
}
|
||||
return t.Implements(unmarshalerType)
|
||||
}
|
||||
|
||||
// Init populates the properties from a protocol buffer struct tag.
|
||||
func (p *Properties) Init(typ reflect.Type, name, tag string, f *reflect.StructField) {
|
||||
p.init(typ, name, tag, f, true)
|
||||
@ -621,14 +309,11 @@ func (p *Properties) init(typ reflect.Type, name, tag string, f *reflect.StructF
|
||||
// "bytes,49,opt,def=hello!"
|
||||
p.Name = name
|
||||
p.OrigName = name
|
||||
if f != nil {
|
||||
p.field = toField(f)
|
||||
}
|
||||
if tag == "" {
|
||||
return
|
||||
}
|
||||
p.Parse(tag)
|
||||
p.setEncAndDec(typ, f, lockGetProp)
|
||||
p.setFieldProps(typ, f, lockGetProp)
|
||||
}
|
||||
|
||||
var (
|
||||
@ -649,9 +334,6 @@ func GetProperties(t reflect.Type) *StructProperties {
|
||||
sprop, ok := propertiesMap[t]
|
||||
propertiesMu.RUnlock()
|
||||
if ok {
|
||||
if collectStats {
|
||||
stats.Chit++
|
||||
}
|
||||
return sprop
|
||||
}
|
||||
|
||||
@ -664,23 +346,14 @@ func GetProperties(t reflect.Type) *StructProperties {
|
||||
// getPropertiesLocked requires that propertiesMu is held.
|
||||
func getPropertiesLocked(t reflect.Type) *StructProperties {
|
||||
if prop, ok := propertiesMap[t]; ok {
|
||||
if collectStats {
|
||||
stats.Chit++
|
||||
}
|
||||
return prop
|
||||
}
|
||||
if collectStats {
|
||||
stats.Cmiss++
|
||||
}
|
||||
|
||||
prop := new(StructProperties)
|
||||
// in case of recursive protos, fill this in now.
|
||||
propertiesMap[t] = prop
|
||||
|
||||
// build properties
|
||||
prop.extendable = reflect.PtrTo(t).Implements(extendableProtoType) ||
|
||||
reflect.PtrTo(t).Implements(extendableProtoV1Type)
|
||||
prop.unrecField = invalidField
|
||||
prop.Prop = make([]*Properties, t.NumField())
|
||||
prop.order = make([]int, t.NumField())
|
||||
|
||||
@ -690,17 +363,6 @@ func getPropertiesLocked(t reflect.Type) *StructProperties {
|
||||
name := f.Name
|
||||
p.init(f.Type, name, f.Tag.Get("protobuf"), &f, false)
|
||||
|
||||
if f.Name == "XXX_InternalExtensions" { // special case
|
||||
p.enc = (*Buffer).enc_exts
|
||||
p.dec = nil // not needed
|
||||
p.size = size_exts
|
||||
} else if f.Name == "XXX_extensions" { // special case
|
||||
p.enc = (*Buffer).enc_map
|
||||
p.dec = nil // not needed
|
||||
p.size = size_map
|
||||
} else if f.Name == "XXX_unrecognized" { // special case
|
||||
prop.unrecField = toField(&f)
|
||||
}
|
||||
oneof := f.Tag.Get("protobuf_oneof") // special case
|
||||
if oneof != "" {
|
||||
// Oneof fields don't use the traditional protobuf tag.
|
||||
@ -715,9 +377,6 @@ func getPropertiesLocked(t reflect.Type) *StructProperties {
|
||||
}
|
||||
print("\n")
|
||||
}
|
||||
if p.enc == nil && !strings.HasPrefix(f.Name, "XXX_") && oneof == "" {
|
||||
fmt.Fprintln(os.Stderr, "proto: no encoder for", f.Name, f.Type.String(), "[GetProperties]")
|
||||
}
|
||||
}
|
||||
|
||||
// Re-order prop.order.
|
||||
@ -728,8 +387,7 @@ func getPropertiesLocked(t reflect.Type) *StructProperties {
|
||||
}
|
||||
if om, ok := reflect.Zero(reflect.PtrTo(t)).Interface().(oneofMessage); ok {
|
||||
var oots []interface{}
|
||||
prop.oneofMarshaler, prop.oneofUnmarshaler, prop.oneofSizer, oots = om.XXX_OneofFuncs()
|
||||
prop.stype = t
|
||||
_, _, _, oots = om.XXX_OneofFuncs()
|
||||
|
||||
// Interpret oneof metadata.
|
||||
prop.OneofTypes = make(map[string]*OneofProperties)
|
||||
@ -779,30 +437,6 @@ func getPropertiesLocked(t reflect.Type) *StructProperties {
|
||||
return prop
|
||||
}
|
||||
|
||||
// Return the Properties object for the x[0]'th field of the structure.
|
||||
func propByIndex(t reflect.Type, x []int) *Properties {
|
||||
if len(x) != 1 {
|
||||
fmt.Fprintf(os.Stderr, "proto: field index dimension %d (not 1) for type %s\n", len(x), t)
|
||||
return nil
|
||||
}
|
||||
prop := GetProperties(t)
|
||||
return prop.Prop[x[0]]
|
||||
}
|
||||
|
||||
// Get the address and type of a pointer to a struct from an interface.
|
||||
func getbase(pb Message) (t reflect.Type, b structPointer, err error) {
|
||||
if pb == nil {
|
||||
err = ErrNil
|
||||
return
|
||||
}
|
||||
// get the reflect type of the pointer to the struct.
|
||||
t = reflect.TypeOf(pb)
|
||||
// get the address of the struct.
|
||||
value := reflect.ValueOf(pb)
|
||||
b = toStructPointer(value)
|
||||
return
|
||||
}
|
||||
|
||||
// A global registry of enum types.
|
||||
// The generated code will register the generated maps by calling RegisterEnum.
|
||||
|
||||
@ -826,20 +460,42 @@ func EnumValueMap(enumType string) map[string]int32 {
|
||||
// A registry of all linked message types.
|
||||
// The string is a fully-qualified proto name ("pkg.Message").
|
||||
var (
|
||||
protoTypes = make(map[string]reflect.Type)
|
||||
revProtoTypes = make(map[reflect.Type]string)
|
||||
protoTypedNils = make(map[string]Message) // a map from proto names to typed nil pointers
|
||||
protoMapTypes = make(map[string]reflect.Type) // a map from proto names to map types
|
||||
revProtoTypes = make(map[reflect.Type]string)
|
||||
)
|
||||
|
||||
// RegisterType is called from generated code and maps from the fully qualified
|
||||
// proto name to the type (pointer to struct) of the protocol buffer.
|
||||
func RegisterType(x Message, name string) {
|
||||
if _, ok := protoTypes[name]; ok {
|
||||
if _, ok := protoTypedNils[name]; ok {
|
||||
// TODO: Some day, make this a panic.
|
||||
log.Printf("proto: duplicate proto type registered: %s", name)
|
||||
return
|
||||
}
|
||||
t := reflect.TypeOf(x)
|
||||
protoTypes[name] = t
|
||||
if v := reflect.ValueOf(x); v.Kind() == reflect.Ptr && v.Pointer() == 0 {
|
||||
// Generated code always calls RegisterType with nil x.
|
||||
// This check is just for extra safety.
|
||||
protoTypedNils[name] = x
|
||||
} else {
|
||||
protoTypedNils[name] = reflect.Zero(t).Interface().(Message)
|
||||
}
|
||||
revProtoTypes[t] = name
|
||||
}
|
||||
|
||||
// RegisterMapType is called from generated code and maps from the fully qualified
|
||||
// proto name to the native map type of the proto map definition.
|
||||
func RegisterMapType(x interface{}, name string) {
|
||||
if reflect.TypeOf(x).Kind() != reflect.Map {
|
||||
panic(fmt.Sprintf("RegisterMapType(%T, %q); want map", x, name))
|
||||
}
|
||||
if _, ok := protoMapTypes[name]; ok {
|
||||
log.Printf("proto: duplicate proto type registered: %s", name)
|
||||
return
|
||||
}
|
||||
t := reflect.TypeOf(x)
|
||||
protoMapTypes[name] = t
|
||||
revProtoTypes[t] = name
|
||||
}
|
||||
|
||||
@ -855,7 +511,14 @@ func MessageName(x Message) string {
|
||||
}
|
||||
|
||||
// MessageType returns the message type (pointer to struct) for a named message.
|
||||
func MessageType(name string) reflect.Type { return protoTypes[name] }
|
||||
// The type is not guaranteed to implement proto.Message if the name refers to a
|
||||
// map entry.
|
||||
func MessageType(name string) reflect.Type {
|
||||
if t, ok := protoTypedNils[name]; ok {
|
||||
return reflect.TypeOf(t)
|
||||
}
|
||||
return protoMapTypes[name]
|
||||
}
|
||||
|
||||
// A registry of all linked proto files.
|
||||
var (
|
||||
|
514
vendor/github.com/golang/protobuf/proto/proto3_proto/proto3.pb.go
generated
vendored
514
vendor/github.com/golang/protobuf/proto/proto3_proto/proto3.pb.go
generated
vendored
@ -1,27 +1,15 @@
|
||||
// Code generated by protoc-gen-go.
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: proto3_proto/proto3.proto
|
||||
// DO NOT EDIT!
|
||||
|
||||
/*
|
||||
Package proto3_proto is a generated protocol buffer package.
|
||||
|
||||
It is generated from these files:
|
||||
proto3_proto/proto3.proto
|
||||
|
||||
It has these top-level messages:
|
||||
Message
|
||||
Nested
|
||||
MessageWithMap
|
||||
IntMap
|
||||
IntMaps
|
||||
*/
|
||||
package proto3_proto
|
||||
|
||||
import proto "github.com/golang/protobuf/proto"
|
||||
import fmt "fmt"
|
||||
import math "math"
|
||||
import google_protobuf "github.com/golang/protobuf/ptypes/any"
|
||||
import testdata "github.com/golang/protobuf/proto/testdata"
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
test_proto "github.com/golang/protobuf/proto/test_proto"
|
||||
any "github.com/golang/protobuf/ptypes/any"
|
||||
math "math"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
@ -49,6 +37,7 @@ var Message_Humour_name = map[int32]string{
|
||||
2: "SLAPSTICK",
|
||||
3: "BILL_BAILEY",
|
||||
}
|
||||
|
||||
var Message_Humour_value = map[string]int32{
|
||||
"UNKNOWN": 0,
|
||||
"PUNS": 1,
|
||||
@ -59,33 +48,60 @@ var Message_Humour_value = map[string]int32{
|
||||
func (x Message_Humour) String() string {
|
||||
return proto.EnumName(Message_Humour_name, int32(x))
|
||||
}
|
||||
func (Message_Humour) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{0, 0} }
|
||||
|
||||
type Message struct {
|
||||
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
|
||||
Hilarity Message_Humour `protobuf:"varint,2,opt,name=hilarity,enum=proto3_proto.Message_Humour" json:"hilarity,omitempty"`
|
||||
HeightInCm uint32 `protobuf:"varint,3,opt,name=height_in_cm,json=heightInCm" json:"height_in_cm,omitempty"`
|
||||
Data []byte `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"`
|
||||
ResultCount int64 `protobuf:"varint,7,opt,name=result_count,json=resultCount" json:"result_count,omitempty"`
|
||||
TrueScotsman bool `protobuf:"varint,8,opt,name=true_scotsman,json=trueScotsman" json:"true_scotsman,omitempty"`
|
||||
Score float32 `protobuf:"fixed32,9,opt,name=score" json:"score,omitempty"`
|
||||
Key []uint64 `protobuf:"varint,5,rep,packed,name=key" json:"key,omitempty"`
|
||||
ShortKey []int32 `protobuf:"varint,19,rep,packed,name=short_key,json=shortKey" json:"short_key,omitempty"`
|
||||
Nested *Nested `protobuf:"bytes,6,opt,name=nested" json:"nested,omitempty"`
|
||||
RFunny []Message_Humour `protobuf:"varint,16,rep,packed,name=r_funny,json=rFunny,enum=proto3_proto.Message_Humour" json:"r_funny,omitempty"`
|
||||
Terrain map[string]*Nested `protobuf:"bytes,10,rep,name=terrain" json:"terrain,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
|
||||
Proto2Field *testdata.SubDefaults `protobuf:"bytes,11,opt,name=proto2_field,json=proto2Field" json:"proto2_field,omitempty"`
|
||||
Proto2Value map[string]*testdata.SubDefaults `protobuf:"bytes,13,rep,name=proto2_value,json=proto2Value" json:"proto2_value,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
|
||||
Anything *google_protobuf.Any `protobuf:"bytes,14,opt,name=anything" json:"anything,omitempty"`
|
||||
ManyThings []*google_protobuf.Any `protobuf:"bytes,15,rep,name=many_things,json=manyThings" json:"many_things,omitempty"`
|
||||
Submessage *Message `protobuf:"bytes,17,opt,name=submessage" json:"submessage,omitempty"`
|
||||
Children []*Message `protobuf:"bytes,18,rep,name=children" json:"children,omitempty"`
|
||||
func (Message_Humour) EnumDescriptor() ([]byte, []int) {
|
||||
return fileDescriptor_1c50d9b824d4ac38, []int{0, 0}
|
||||
}
|
||||
|
||||
func (m *Message) Reset() { *m = Message{} }
|
||||
func (m *Message) String() string { return proto.CompactTextString(m) }
|
||||
func (*Message) ProtoMessage() {}
|
||||
func (*Message) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
||||
type Message struct {
|
||||
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
||||
Hilarity Message_Humour `protobuf:"varint,2,opt,name=hilarity,proto3,enum=proto3_proto.Message_Humour" json:"hilarity,omitempty"`
|
||||
HeightInCm uint32 `protobuf:"varint,3,opt,name=height_in_cm,json=heightInCm,proto3" json:"height_in_cm,omitempty"`
|
||||
Data []byte `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"`
|
||||
ResultCount int64 `protobuf:"varint,7,opt,name=result_count,json=resultCount,proto3" json:"result_count,omitempty"`
|
||||
TrueScotsman bool `protobuf:"varint,8,opt,name=true_scotsman,json=trueScotsman,proto3" json:"true_scotsman,omitempty"`
|
||||
Score float32 `protobuf:"fixed32,9,opt,name=score,proto3" json:"score,omitempty"`
|
||||
Key []uint64 `protobuf:"varint,5,rep,packed,name=key,proto3" json:"key,omitempty"`
|
||||
ShortKey []int32 `protobuf:"varint,19,rep,packed,name=short_key,json=shortKey,proto3" json:"short_key,omitempty"`
|
||||
Nested *Nested `protobuf:"bytes,6,opt,name=nested,proto3" json:"nested,omitempty"`
|
||||
RFunny []Message_Humour `protobuf:"varint,16,rep,packed,name=r_funny,json=rFunny,proto3,enum=proto3_proto.Message_Humour" json:"r_funny,omitempty"`
|
||||
Terrain map[string]*Nested `protobuf:"bytes,10,rep,name=terrain,proto3" json:"terrain,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
|
||||
Proto2Field *test_proto.SubDefaults `protobuf:"bytes,11,opt,name=proto2_field,json=proto2Field,proto3" json:"proto2_field,omitempty"`
|
||||
Proto2Value map[string]*test_proto.SubDefaults `protobuf:"bytes,13,rep,name=proto2_value,json=proto2Value,proto3" json:"proto2_value,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
|
||||
Anything *any.Any `protobuf:"bytes,14,opt,name=anything,proto3" json:"anything,omitempty"`
|
||||
ManyThings []*any.Any `protobuf:"bytes,15,rep,name=many_things,json=manyThings,proto3" json:"many_things,omitempty"`
|
||||
Submessage *Message `protobuf:"bytes,17,opt,name=submessage,proto3" json:"submessage,omitempty"`
|
||||
Children []*Message `protobuf:"bytes,18,rep,name=children,proto3" json:"children,omitempty"`
|
||||
StringMap map[string]string `protobuf:"bytes,20,rep,name=string_map,json=stringMap,proto3" json:"string_map,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Message) Reset() { *m = Message{} }
|
||||
func (m *Message) String() string { return proto.CompactTextString(m) }
|
||||
func (*Message) ProtoMessage() {}
|
||||
func (*Message) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_1c50d9b824d4ac38, []int{0}
|
||||
}
|
||||
|
||||
func (m *Message) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_Message.Unmarshal(m, b)
|
||||
}
|
||||
func (m *Message) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_Message.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *Message) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Message.Merge(m, src)
|
||||
}
|
||||
func (m *Message) XXX_Size() int {
|
||||
return xxx_messageInfo_Message.Size(m)
|
||||
}
|
||||
func (m *Message) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Message.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_Message proto.InternalMessageInfo
|
||||
|
||||
func (m *Message) GetName() string {
|
||||
if m != nil {
|
||||
@ -171,28 +187,28 @@ func (m *Message) GetTerrain() map[string]*Nested {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Message) GetProto2Field() *testdata.SubDefaults {
|
||||
func (m *Message) GetProto2Field() *test_proto.SubDefaults {
|
||||
if m != nil {
|
||||
return m.Proto2Field
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Message) GetProto2Value() map[string]*testdata.SubDefaults {
|
||||
func (m *Message) GetProto2Value() map[string]*test_proto.SubDefaults {
|
||||
if m != nil {
|
||||
return m.Proto2Value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Message) GetAnything() *google_protobuf.Any {
|
||||
func (m *Message) GetAnything() *any.Any {
|
||||
if m != nil {
|
||||
return m.Anything
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Message) GetManyThings() []*google_protobuf.Any {
|
||||
func (m *Message) GetManyThings() []*any.Any {
|
||||
if m != nil {
|
||||
return m.ManyThings
|
||||
}
|
||||
@ -213,15 +229,45 @@ func (m *Message) GetChildren() []*Message {
|
||||
return nil
|
||||
}
|
||||
|
||||
type Nested struct {
|
||||
Bunny string `protobuf:"bytes,1,opt,name=bunny" json:"bunny,omitempty"`
|
||||
Cute bool `protobuf:"varint,2,opt,name=cute" json:"cute,omitempty"`
|
||||
func (m *Message) GetStringMap() map[string]string {
|
||||
if m != nil {
|
||||
return m.StringMap
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Nested) Reset() { *m = Nested{} }
|
||||
func (m *Nested) String() string { return proto.CompactTextString(m) }
|
||||
func (*Nested) ProtoMessage() {}
|
||||
func (*Nested) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
|
||||
type Nested struct {
|
||||
Bunny string `protobuf:"bytes,1,opt,name=bunny,proto3" json:"bunny,omitempty"`
|
||||
Cute bool `protobuf:"varint,2,opt,name=cute,proto3" json:"cute,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Nested) Reset() { *m = Nested{} }
|
||||
func (m *Nested) String() string { return proto.CompactTextString(m) }
|
||||
func (*Nested) ProtoMessage() {}
|
||||
func (*Nested) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_1c50d9b824d4ac38, []int{1}
|
||||
}
|
||||
|
||||
func (m *Nested) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_Nested.Unmarshal(m, b)
|
||||
}
|
||||
func (m *Nested) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_Nested.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *Nested) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Nested.Merge(m, src)
|
||||
}
|
||||
func (m *Nested) XXX_Size() int {
|
||||
return xxx_messageInfo_Nested.Size(m)
|
||||
}
|
||||
func (m *Nested) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Nested.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_Nested proto.InternalMessageInfo
|
||||
|
||||
func (m *Nested) GetBunny() string {
|
||||
if m != nil {
|
||||
@ -238,13 +284,36 @@ func (m *Nested) GetCute() bool {
|
||||
}
|
||||
|
||||
type MessageWithMap struct {
|
||||
ByteMapping map[bool][]byte `protobuf:"bytes,1,rep,name=byte_mapping,json=byteMapping" json:"byte_mapping,omitempty" protobuf_key:"varint,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value,proto3"`
|
||||
ByteMapping map[bool][]byte `protobuf:"bytes,1,rep,name=byte_mapping,json=byteMapping,proto3" json:"byte_mapping,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `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 fileDescriptor0, []int{2} }
|
||||
func (m *MessageWithMap) Reset() { *m = MessageWithMap{} }
|
||||
func (m *MessageWithMap) String() string { return proto.CompactTextString(m) }
|
||||
func (*MessageWithMap) ProtoMessage() {}
|
||||
func (*MessageWithMap) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_1c50d9b824d4ac38, []int{2}
|
||||
}
|
||||
|
||||
func (m *MessageWithMap) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_MessageWithMap.Unmarshal(m, b)
|
||||
}
|
||||
func (m *MessageWithMap) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_MessageWithMap.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *MessageWithMap) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_MessageWithMap.Merge(m, src)
|
||||
}
|
||||
func (m *MessageWithMap) XXX_Size() int {
|
||||
return xxx_messageInfo_MessageWithMap.Size(m)
|
||||
}
|
||||
func (m *MessageWithMap) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_MessageWithMap.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_MessageWithMap proto.InternalMessageInfo
|
||||
|
||||
func (m *MessageWithMap) GetByteMapping() map[bool][]byte {
|
||||
if m != nil {
|
||||
@ -254,13 +323,36 @@ func (m *MessageWithMap) GetByteMapping() map[bool][]byte {
|
||||
}
|
||||
|
||||
type IntMap struct {
|
||||
Rtt map[int32]int32 `protobuf:"bytes,1,rep,name=rtt" json:"rtt,omitempty" protobuf_key:"varint,1,opt,name=key" protobuf_val:"varint,2,opt,name=value"`
|
||||
Rtt map[int32]int32 `protobuf:"bytes,1,rep,name=rtt,proto3" json:"rtt,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *IntMap) Reset() { *m = IntMap{} }
|
||||
func (m *IntMap) String() string { return proto.CompactTextString(m) }
|
||||
func (*IntMap) ProtoMessage() {}
|
||||
func (*IntMap) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
|
||||
func (m *IntMap) Reset() { *m = IntMap{} }
|
||||
func (m *IntMap) String() string { return proto.CompactTextString(m) }
|
||||
func (*IntMap) ProtoMessage() {}
|
||||
func (*IntMap) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_1c50d9b824d4ac38, []int{3}
|
||||
}
|
||||
|
||||
func (m *IntMap) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_IntMap.Unmarshal(m, b)
|
||||
}
|
||||
func (m *IntMap) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_IntMap.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *IntMap) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_IntMap.Merge(m, src)
|
||||
}
|
||||
func (m *IntMap) XXX_Size() int {
|
||||
return xxx_messageInfo_IntMap.Size(m)
|
||||
}
|
||||
func (m *IntMap) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_IntMap.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_IntMap proto.InternalMessageInfo
|
||||
|
||||
func (m *IntMap) GetRtt() map[int32]int32 {
|
||||
if m != nil {
|
||||
@ -270,13 +362,36 @@ func (m *IntMap) GetRtt() map[int32]int32 {
|
||||
}
|
||||
|
||||
type IntMaps struct {
|
||||
Maps []*IntMap `protobuf:"bytes,1,rep,name=maps" json:"maps,omitempty"`
|
||||
Maps []*IntMap `protobuf:"bytes,1,rep,name=maps,proto3" json:"maps,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *IntMaps) Reset() { *m = IntMaps{} }
|
||||
func (m *IntMaps) String() string { return proto.CompactTextString(m) }
|
||||
func (*IntMaps) ProtoMessage() {}
|
||||
func (*IntMaps) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} }
|
||||
func (m *IntMaps) Reset() { *m = IntMaps{} }
|
||||
func (m *IntMaps) String() string { return proto.CompactTextString(m) }
|
||||
func (*IntMaps) ProtoMessage() {}
|
||||
func (*IntMaps) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_1c50d9b824d4ac38, []int{4}
|
||||
}
|
||||
|
||||
func (m *IntMaps) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_IntMaps.Unmarshal(m, b)
|
||||
}
|
||||
func (m *IntMaps) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_IntMaps.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *IntMaps) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_IntMaps.Merge(m, src)
|
||||
}
|
||||
func (m *IntMaps) XXX_Size() int {
|
||||
return xxx_messageInfo_IntMaps.Size(m)
|
||||
}
|
||||
func (m *IntMaps) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_IntMaps.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_IntMaps proto.InternalMessageInfo
|
||||
|
||||
func (m *IntMaps) GetMaps() []*IntMap {
|
||||
if m != nil {
|
||||
@ -285,63 +400,222 @@ func (m *IntMaps) GetMaps() []*IntMap {
|
||||
return nil
|
||||
}
|
||||
|
||||
type TestUTF8 struct {
|
||||
Scalar string `protobuf:"bytes,1,opt,name=scalar,proto3" json:"scalar,omitempty"`
|
||||
Vector []string `protobuf:"bytes,2,rep,name=vector,proto3" json:"vector,omitempty"`
|
||||
// Types that are valid to be assigned to Oneof:
|
||||
// *TestUTF8_Field
|
||||
Oneof isTestUTF8_Oneof `protobuf_oneof:"oneof"`
|
||||
MapKey map[string]int64 `protobuf:"bytes,4,rep,name=map_key,json=mapKey,proto3" json:"map_key,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"`
|
||||
MapValue map[int64]string `protobuf:"bytes,5,rep,name=map_value,json=mapValue,proto3" json:"map_value,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *TestUTF8) Reset() { *m = TestUTF8{} }
|
||||
func (m *TestUTF8) String() string { return proto.CompactTextString(m) }
|
||||
func (*TestUTF8) ProtoMessage() {}
|
||||
func (*TestUTF8) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_1c50d9b824d4ac38, []int{5}
|
||||
}
|
||||
|
||||
func (m *TestUTF8) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_TestUTF8.Unmarshal(m, b)
|
||||
}
|
||||
func (m *TestUTF8) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_TestUTF8.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *TestUTF8) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_TestUTF8.Merge(m, src)
|
||||
}
|
||||
func (m *TestUTF8) XXX_Size() int {
|
||||
return xxx_messageInfo_TestUTF8.Size(m)
|
||||
}
|
||||
func (m *TestUTF8) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_TestUTF8.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_TestUTF8 proto.InternalMessageInfo
|
||||
|
||||
func (m *TestUTF8) GetScalar() string {
|
||||
if m != nil {
|
||||
return m.Scalar
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *TestUTF8) GetVector() []string {
|
||||
if m != nil {
|
||||
return m.Vector
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type isTestUTF8_Oneof interface {
|
||||
isTestUTF8_Oneof()
|
||||
}
|
||||
|
||||
type TestUTF8_Field struct {
|
||||
Field string `protobuf:"bytes,3,opt,name=field,proto3,oneof"`
|
||||
}
|
||||
|
||||
func (*TestUTF8_Field) isTestUTF8_Oneof() {}
|
||||
|
||||
func (m *TestUTF8) GetOneof() isTestUTF8_Oneof {
|
||||
if m != nil {
|
||||
return m.Oneof
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *TestUTF8) GetField() string {
|
||||
if x, ok := m.GetOneof().(*TestUTF8_Field); ok {
|
||||
return x.Field
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *TestUTF8) GetMapKey() map[string]int64 {
|
||||
if m != nil {
|
||||
return m.MapKey
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *TestUTF8) GetMapValue() map[int64]string {
|
||||
if m != nil {
|
||||
return m.MapValue
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// XXX_OneofFuncs is for the internal use of the proto package.
|
||||
func (*TestUTF8) 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 _TestUTF8_OneofMarshaler, _TestUTF8_OneofUnmarshaler, _TestUTF8_OneofSizer, []interface{}{
|
||||
(*TestUTF8_Field)(nil),
|
||||
}
|
||||
}
|
||||
|
||||
func _TestUTF8_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
|
||||
m := msg.(*TestUTF8)
|
||||
// oneof
|
||||
switch x := m.Oneof.(type) {
|
||||
case *TestUTF8_Field:
|
||||
b.EncodeVarint(3<<3 | proto.WireBytes)
|
||||
b.EncodeStringBytes(x.Field)
|
||||
case nil:
|
||||
default:
|
||||
return fmt.Errorf("TestUTF8.Oneof has unexpected type %T", x)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func _TestUTF8_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
|
||||
m := msg.(*TestUTF8)
|
||||
switch tag {
|
||||
case 3: // oneof.field
|
||||
if wire != proto.WireBytes {
|
||||
return true, proto.ErrInternalBadWireType
|
||||
}
|
||||
x, err := b.DecodeStringBytes()
|
||||
m.Oneof = &TestUTF8_Field{x}
|
||||
return true, err
|
||||
default:
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
func _TestUTF8_OneofSizer(msg proto.Message) (n int) {
|
||||
m := msg.(*TestUTF8)
|
||||
// oneof
|
||||
switch x := m.Oneof.(type) {
|
||||
case *TestUTF8_Field:
|
||||
n += 1 // tag and wire
|
||||
n += proto.SizeVarint(uint64(len(x.Field)))
|
||||
n += len(x.Field)
|
||||
case nil:
|
||||
default:
|
||||
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterEnum("proto3_proto.Message_Humour", Message_Humour_name, Message_Humour_value)
|
||||
proto.RegisterType((*Message)(nil), "proto3_proto.Message")
|
||||
proto.RegisterMapType((map[string]*test_proto.SubDefaults)(nil), "proto3_proto.Message.Proto2ValueEntry")
|
||||
proto.RegisterMapType((map[string]string)(nil), "proto3_proto.Message.StringMapEntry")
|
||||
proto.RegisterMapType((map[string]*Nested)(nil), "proto3_proto.Message.TerrainEntry")
|
||||
proto.RegisterType((*Nested)(nil), "proto3_proto.Nested")
|
||||
proto.RegisterType((*MessageWithMap)(nil), "proto3_proto.MessageWithMap")
|
||||
proto.RegisterMapType((map[bool][]byte)(nil), "proto3_proto.MessageWithMap.ByteMappingEntry")
|
||||
proto.RegisterType((*IntMap)(nil), "proto3_proto.IntMap")
|
||||
proto.RegisterMapType((map[int32]int32)(nil), "proto3_proto.IntMap.RttEntry")
|
||||
proto.RegisterType((*IntMaps)(nil), "proto3_proto.IntMaps")
|
||||
proto.RegisterEnum("proto3_proto.Message_Humour", Message_Humour_name, Message_Humour_value)
|
||||
proto.RegisterType((*TestUTF8)(nil), "proto3_proto.TestUTF8")
|
||||
proto.RegisterMapType((map[string]int64)(nil), "proto3_proto.TestUTF8.MapKeyEntry")
|
||||
proto.RegisterMapType((map[int64]string)(nil), "proto3_proto.TestUTF8.MapValueEntry")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("proto3_proto/proto3.proto", fileDescriptor0) }
|
||||
func init() { proto.RegisterFile("proto3_proto/proto3.proto", fileDescriptor_1c50d9b824d4ac38) }
|
||||
|
||||
var fileDescriptor0 = []byte{
|
||||
// 733 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x84, 0x53, 0x6d, 0x6f, 0xf3, 0x34,
|
||||
0x14, 0x25, 0x4d, 0x5f, 0xd2, 0x9b, 0x74, 0x0b, 0x5e, 0x91, 0xbc, 0x02, 0x52, 0x28, 0x12, 0x8a,
|
||||
0x78, 0x49, 0xa1, 0xd3, 0xd0, 0x84, 0x10, 0x68, 0x1b, 0x9b, 0xa8, 0xd6, 0x95, 0xca, 0xdd, 0x98,
|
||||
0xf8, 0x14, 0xa5, 0xad, 0xdb, 0x46, 0x34, 0x4e, 0x49, 0x1c, 0xa4, 0xfc, 0x1d, 0xfe, 0x28, 0x8f,
|
||||
0x6c, 0xa7, 0x5d, 0x36, 0x65, 0xcf, 0xf3, 0x29, 0xf6, 0xf1, 0xb9, 0xf7, 0x9c, 0x1c, 0x5f, 0xc3,
|
||||
0xe9, 0x2e, 0x89, 0x79, 0x7c, 0xe6, 0xcb, 0xcf, 0x40, 0x6d, 0x3c, 0xf9, 0x41, 0x56, 0xf9, 0xa8,
|
||||
0x77, 0xba, 0x8e, 0xe3, 0xf5, 0x96, 0x2a, 0xca, 0x3c, 0x5b, 0x0d, 0x02, 0x96, 0x2b, 0x62, 0xef,
|
||||
0x84, 0xd3, 0x94, 0x2f, 0x03, 0x1e, 0x0c, 0xc4, 0x42, 0x81, 0xfd, 0xff, 0x5b, 0xd0, 0xba, 0xa7,
|
||||
0x69, 0x1a, 0xac, 0x29, 0x42, 0x50, 0x67, 0x41, 0x44, 0xb1, 0xe6, 0x68, 0x6e, 0x9b, 0xc8, 0x35,
|
||||
0xba, 0x00, 0x63, 0x13, 0x6e, 0x83, 0x24, 0xe4, 0x39, 0xae, 0x39, 0x9a, 0x7b, 0x34, 0xfc, 0xcc,
|
||||
0x2b, 0x0b, 0x7a, 0x45, 0xb1, 0xf7, 0x7b, 0x16, 0xc5, 0x59, 0x42, 0x0e, 0x6c, 0xe4, 0x80, 0xb5,
|
||||
0xa1, 0xe1, 0x7a, 0xc3, 0xfd, 0x90, 0xf9, 0x8b, 0x08, 0xeb, 0x8e, 0xe6, 0x76, 0x08, 0x28, 0x6c,
|
||||
0xc4, 0xae, 0x23, 0xa1, 0x27, 0xec, 0xe0, 0xba, 0xa3, 0xb9, 0x16, 0x91, 0x6b, 0xf4, 0x05, 0x58,
|
||||
0x09, 0x4d, 0xb3, 0x2d, 0xf7, 0x17, 0x71, 0xc6, 0x38, 0x6e, 0x39, 0x9a, 0xab, 0x13, 0x53, 0x61,
|
||||
0xd7, 0x02, 0x42, 0x5f, 0x42, 0x87, 0x27, 0x19, 0xf5, 0xd3, 0x45, 0xcc, 0xd3, 0x28, 0x60, 0xd8,
|
||||
0x70, 0x34, 0xd7, 0x20, 0x96, 0x00, 0x67, 0x05, 0x86, 0xba, 0xd0, 0x48, 0x17, 0x71, 0x42, 0x71,
|
||||
0xdb, 0xd1, 0xdc, 0x1a, 0x51, 0x1b, 0x64, 0x83, 0xfe, 0x37, 0xcd, 0x71, 0xc3, 0xd1, 0xdd, 0x3a,
|
||||
0x11, 0x4b, 0xf4, 0x29, 0xb4, 0xd3, 0x4d, 0x9c, 0x70, 0x5f, 0xe0, 0x27, 0x8e, 0xee, 0x36, 0x88,
|
||||
0x21, 0x81, 0x3b, 0x9a, 0xa3, 0x6f, 0xa1, 0xc9, 0x68, 0xca, 0xe9, 0x12, 0x37, 0x1d, 0xcd, 0x35,
|
||||
0x87, 0xdd, 0x97, 0xbf, 0x3e, 0x91, 0x67, 0xa4, 0xe0, 0xa0, 0x73, 0x68, 0x25, 0xfe, 0x2a, 0x63,
|
||||
0x2c, 0xc7, 0xb6, 0xa3, 0x7f, 0x30, 0xa9, 0x66, 0x72, 0x2b, 0xb8, 0xe8, 0x67, 0x68, 0x71, 0x9a,
|
||||
0x24, 0x41, 0xc8, 0x30, 0x38, 0xba, 0x6b, 0x0e, 0xfb, 0xd5, 0x65, 0x0f, 0x8a, 0x74, 0xc3, 0x78,
|
||||
0x92, 0x93, 0x7d, 0x09, 0xba, 0x00, 0x75, 0xff, 0x43, 0x7f, 0x15, 0xd2, 0xed, 0x12, 0x9b, 0xd2,
|
||||
0xe8, 0x27, 0xde, 0xfe, 0xae, 0xbd, 0x59, 0x36, 0xff, 0x8d, 0xae, 0x82, 0x6c, 0xcb, 0x53, 0x62,
|
||||
0x2a, 0xea, 0xad, 0x60, 0xa2, 0xd1, 0xa1, 0xf2, 0xdf, 0x60, 0x9b, 0x51, 0xdc, 0x91, 0xe2, 0x5f,
|
||||
0x55, 0x8b, 0x4f, 0x25, 0xf3, 0x4f, 0x41, 0x54, 0x06, 0x8a, 0x56, 0x12, 0x41, 0xdf, 0x83, 0x11,
|
||||
0xb0, 0x9c, 0x6f, 0x42, 0xb6, 0xc6, 0x47, 0x45, 0x52, 0x6a, 0x0e, 0xbd, 0xfd, 0x1c, 0x7a, 0x97,
|
||||
0x2c, 0x27, 0x07, 0x16, 0x3a, 0x07, 0x33, 0x0a, 0x58, 0xee, 0xcb, 0x5d, 0x8a, 0x8f, 0xa5, 0x76,
|
||||
0x75, 0x11, 0x08, 0xe2, 0x83, 0xe4, 0xa1, 0x73, 0x80, 0x34, 0x9b, 0x47, 0xca, 0x14, 0xfe, 0xb8,
|
||||
0xf8, 0xd7, 0x2a, 0xc7, 0xa4, 0x44, 0x44, 0x3f, 0x80, 0xb1, 0xd8, 0x84, 0xdb, 0x65, 0x42, 0x19,
|
||||
0x46, 0x52, 0xea, 0x8d, 0xa2, 0x03, 0xad, 0x37, 0x05, 0xab, 0x1c, 0xf8, 0x7e, 0x72, 0xd4, 0xd3,
|
||||
0x90, 0x93, 0xf3, 0x35, 0x34, 0x54, 0x70, 0xb5, 0xf7, 0xcc, 0x86, 0xa2, 0xfc, 0x54, 0xbb, 0xd0,
|
||||
0x7a, 0x8f, 0x60, 0xbf, 0x4e, 0xb1, 0xa2, 0xeb, 0x37, 0x2f, 0xbb, 0xbe, 0x71, 0x91, 0xcf, 0x6d,
|
||||
0xfb, 0xbf, 0x42, 0x53, 0x0d, 0x14, 0x32, 0xa1, 0xf5, 0x38, 0xb9, 0x9b, 0xfc, 0xf1, 0x34, 0xb1,
|
||||
0x3f, 0x42, 0x06, 0xd4, 0xa7, 0x8f, 0x93, 0x99, 0xad, 0xa1, 0x0e, 0xb4, 0x67, 0xe3, 0xcb, 0xe9,
|
||||
0xec, 0x61, 0x74, 0x7d, 0x67, 0xd7, 0xd0, 0x31, 0x98, 0x57, 0xa3, 0xf1, 0xd8, 0xbf, 0xba, 0x1c,
|
||||
0x8d, 0x6f, 0xfe, 0xb2, 0xf5, 0xfe, 0x10, 0x9a, 0xca, 0xac, 0x78, 0x33, 0x73, 0x39, 0xbe, 0xca,
|
||||
0x8f, 0xda, 0x88, 0x57, 0xba, 0xc8, 0xb8, 0x32, 0x64, 0x10, 0xb9, 0xee, 0xff, 0xa7, 0xc1, 0x51,
|
||||
0x91, 0xd9, 0x53, 0xc8, 0x37, 0xf7, 0xc1, 0x0e, 0x4d, 0xc1, 0x9a, 0xe7, 0x9c, 0xfa, 0x51, 0xb0,
|
||||
0xdb, 0x89, 0x39, 0xd0, 0x64, 0xce, 0xdf, 0x55, 0xe6, 0x5c, 0xd4, 0x78, 0x57, 0x39, 0xa7, 0xf7,
|
||||
0x8a, 0x5f, 0x4c, 0xd5, 0xfc, 0x19, 0xe9, 0xfd, 0x02, 0xf6, 0x6b, 0x42, 0x39, 0x30, 0x43, 0x05,
|
||||
0xd6, 0x2d, 0x07, 0x66, 0x95, 0x93, 0xf9, 0x07, 0x9a, 0x23, 0xc6, 0x85, 0xb7, 0x01, 0xe8, 0x09,
|
||||
0xe7, 0x85, 0xa5, 0xcf, 0x5f, 0x5a, 0x52, 0x14, 0x8f, 0x70, 0xae, 0x2c, 0x08, 0x66, 0xef, 0x47,
|
||||
0x30, 0xf6, 0x40, 0x59, 0xb2, 0x51, 0x21, 0xd9, 0x28, 0x4b, 0x9e, 0x41, 0x4b, 0xf5, 0x4b, 0x91,
|
||||
0x0b, 0xf5, 0x28, 0xd8, 0xa5, 0x85, 0x68, 0xb7, 0x4a, 0x94, 0x48, 0xc6, 0xbc, 0xa9, 0x8e, 0xde,
|
||||
0x05, 0x00, 0x00, 0xff, 0xff, 0x75, 0x38, 0xad, 0x84, 0xe4, 0x05, 0x00, 0x00,
|
||||
var fileDescriptor_1c50d9b824d4ac38 = []byte{
|
||||
// 896 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x54, 0x6f, 0x6f, 0xdb, 0xb6,
|
||||
0x13, 0xae, 0x2c, 0xff, 0x91, 0xcf, 0x76, 0xea, 0x1f, 0x7f, 0x6e, 0xc7, 0x7a, 0x1b, 0xa0, 0x79,
|
||||
0xc3, 0x20, 0x0c, 0xab, 0xb2, 0xb9, 0xc8, 0x90, 0xb5, 0xc5, 0x86, 0x24, 0x6b, 0x50, 0x23, 0xb1,
|
||||
0x67, 0xd0, 0xce, 0x82, 0xbd, 0x12, 0x68, 0x87, 0xb6, 0x85, 0x59, 0x94, 0x27, 0x52, 0x05, 0xf4,
|
||||
0x05, 0xf6, 0x41, 0xf6, 0x95, 0xf6, 0x85, 0x06, 0x92, 0x72, 0x2a, 0x17, 0xea, 0xf2, 0x4a, 0xbc,
|
||||
0x47, 0xcf, 0xdd, 0x73, 0xbc, 0x3b, 0x1e, 0x3c, 0xdb, 0x25, 0xb1, 0x8c, 0x5f, 0x04, 0xfa, 0x73,
|
||||
0x6c, 0x0c, 0x5f, 0x7f, 0x50, 0xbb, 0xf8, 0xab, 0xff, 0x6c, 0x1d, 0xc7, 0xeb, 0x2d, 0x33, 0x94,
|
||||
0x45, 0xba, 0x3a, 0xa6, 0x3c, 0x33, 0xc4, 0xfe, 0x13, 0xc9, 0x84, 0xcc, 0x23, 0xa8, 0xa3, 0x81,
|
||||
0x07, 0x7f, 0x35, 0xa1, 0x31, 0x66, 0x42, 0xd0, 0x35, 0x43, 0x08, 0xaa, 0x9c, 0x46, 0x0c, 0x5b,
|
||||
0xae, 0xe5, 0x35, 0x89, 0x3e, 0xa3, 0x53, 0x70, 0x36, 0xe1, 0x96, 0x26, 0xa1, 0xcc, 0x70, 0xc5,
|
||||
0xb5, 0xbc, 0xa3, 0xe1, 0x67, 0x7e, 0x51, 0xd2, 0xcf, 0x9d, 0xfd, 0xb7, 0x69, 0x14, 0xa7, 0x09,
|
||||
0xb9, 0x67, 0x23, 0x17, 0xda, 0x1b, 0x16, 0xae, 0x37, 0x32, 0x08, 0x79, 0xb0, 0x8c, 0xb0, 0xed,
|
||||
0x5a, 0x5e, 0x87, 0x80, 0xc1, 0x46, 0xfc, 0x22, 0x52, 0x7a, 0x77, 0x54, 0x52, 0x5c, 0x75, 0x2d,
|
||||
0xaf, 0x4d, 0xf4, 0x19, 0x7d, 0x01, 0xed, 0x84, 0x89, 0x74, 0x2b, 0x83, 0x65, 0x9c, 0x72, 0x89,
|
||||
0x1b, 0xae, 0xe5, 0xd9, 0xa4, 0x65, 0xb0, 0x0b, 0x05, 0xa1, 0x2f, 0xa1, 0x23, 0x93, 0x94, 0x05,
|
||||
0x62, 0x19, 0x4b, 0x11, 0x51, 0x8e, 0x1d, 0xd7, 0xf2, 0x1c, 0xd2, 0x56, 0xe0, 0x2c, 0xc7, 0x50,
|
||||
0x0f, 0x6a, 0x62, 0x19, 0x27, 0x0c, 0x37, 0x5d, 0xcb, 0xab, 0x10, 0x63, 0xa0, 0x2e, 0xd8, 0x7f,
|
||||
0xb0, 0x0c, 0xd7, 0x5c, 0xdb, 0xab, 0x12, 0x75, 0x44, 0x9f, 0x42, 0x53, 0x6c, 0xe2, 0x44, 0x06,
|
||||
0x0a, 0xff, 0xbf, 0x6b, 0x7b, 0x35, 0xe2, 0x68, 0xe0, 0x8a, 0x65, 0xe8, 0x5b, 0xa8, 0x73, 0x26,
|
||||
0x24, 0xbb, 0xc3, 0x75, 0xd7, 0xf2, 0x5a, 0xc3, 0xde, 0xe1, 0xd5, 0x27, 0xfa, 0x1f, 0xc9, 0x39,
|
||||
0xe8, 0x04, 0x1a, 0x49, 0xb0, 0x4a, 0x39, 0xcf, 0x70, 0xd7, 0xb5, 0x1f, 0xac, 0x54, 0x3d, 0xb9,
|
||||
0x54, 0x5c, 0xf4, 0x1a, 0x1a, 0x92, 0x25, 0x09, 0x0d, 0x39, 0x06, 0xd7, 0xf6, 0x5a, 0xc3, 0x41,
|
||||
0xb9, 0xdb, 0xdc, 0x90, 0xde, 0x70, 0x99, 0x64, 0x64, 0xef, 0x82, 0x5e, 0x82, 0x99, 0x80, 0x61,
|
||||
0xb0, 0x0a, 0xd9, 0xf6, 0x0e, 0xb7, 0x74, 0xa2, 0x9f, 0xf8, 0xef, 0xbb, 0xed, 0xcf, 0xd2, 0xc5,
|
||||
0x2f, 0x6c, 0x45, 0xd3, 0xad, 0x14, 0xa4, 0x65, 0xc8, 0x97, 0x8a, 0x8b, 0x46, 0xf7, 0xbe, 0xef,
|
||||
0xe8, 0x36, 0x65, 0xb8, 0xa3, 0xe5, 0xbf, 0x2e, 0x97, 0x9f, 0x6a, 0xe6, 0x6f, 0x8a, 0x68, 0x52,
|
||||
0xc8, 0x43, 0x69, 0x04, 0x7d, 0x07, 0x0e, 0xe5, 0x99, 0xdc, 0x84, 0x7c, 0x8d, 0x8f, 0xf2, 0x5a,
|
||||
0x99, 0x59, 0xf4, 0xf7, 0xb3, 0xe8, 0x9f, 0xf1, 0x8c, 0xdc, 0xb3, 0xd0, 0x09, 0xb4, 0x22, 0xca,
|
||||
0xb3, 0x40, 0x5b, 0x02, 0x3f, 0xd6, 0xda, 0xe5, 0x4e, 0xa0, 0x88, 0x73, 0xcd, 0x43, 0x27, 0x00,
|
||||
0x22, 0x5d, 0x44, 0x26, 0x29, 0xfc, 0x3f, 0x2d, 0xf5, 0xa4, 0x34, 0x63, 0x52, 0x20, 0xa2, 0xef,
|
||||
0xc1, 0x59, 0x6e, 0xc2, 0xed, 0x5d, 0xc2, 0x38, 0x46, 0x5a, 0xea, 0x23, 0x4e, 0xf7, 0x34, 0x74,
|
||||
0x01, 0x20, 0x64, 0x12, 0xf2, 0x75, 0x10, 0xd1, 0x1d, 0xee, 0x69, 0xa7, 0xaf, 0xca, 0x6b, 0x33,
|
||||
0xd3, 0xbc, 0x31, 0xdd, 0x99, 0xca, 0x34, 0xc5, 0xde, 0xee, 0x4f, 0xa1, 0x5d, 0xec, 0xdb, 0x7e,
|
||||
0x00, 0xcd, 0x0b, 0xd3, 0x03, 0xf8, 0x0d, 0xd4, 0x4c, 0xf5, 0x2b, 0xff, 0x31, 0x62, 0x86, 0xf2,
|
||||
0xb2, 0x72, 0x6a, 0xf5, 0x6f, 0xa1, 0xfb, 0x61, 0x2b, 0x4a, 0xa2, 0x3e, 0x3f, 0x8c, 0xfa, 0xd1,
|
||||
0x79, 0x28, 0x04, 0x7e, 0x0d, 0x47, 0x87, 0xf7, 0x28, 0x09, 0xdb, 0x2b, 0x86, 0x6d, 0x16, 0xbc,
|
||||
0x07, 0x3f, 0x43, 0xdd, 0xcc, 0x35, 0x6a, 0x41, 0xe3, 0x66, 0x72, 0x35, 0xf9, 0xf5, 0x76, 0xd2,
|
||||
0x7d, 0x84, 0x1c, 0xa8, 0x4e, 0x6f, 0x26, 0xb3, 0xae, 0x85, 0x3a, 0xd0, 0x9c, 0x5d, 0x9f, 0x4d,
|
||||
0x67, 0xf3, 0xd1, 0xc5, 0x55, 0xb7, 0x82, 0x1e, 0x43, 0xeb, 0x7c, 0x74, 0x7d, 0x1d, 0x9c, 0x9f,
|
||||
0x8d, 0xae, 0xdf, 0xfc, 0xde, 0xb5, 0x07, 0x43, 0xa8, 0x9b, 0xcb, 0x2a, 0x91, 0x85, 0x7e, 0x45,
|
||||
0x46, 0xd8, 0x18, 0x6a, 0x59, 0x2c, 0x53, 0x69, 0x94, 0x1d, 0xa2, 0xcf, 0x83, 0xbf, 0x2d, 0x38,
|
||||
0xca, 0x7b, 0x70, 0x1b, 0xca, 0xcd, 0x98, 0xee, 0xd0, 0x14, 0xda, 0x8b, 0x4c, 0x32, 0xd5, 0xb3,
|
||||
0x9d, 0x1a, 0x46, 0x4b, 0xf7, 0xed, 0x79, 0x69, 0xdf, 0x72, 0x1f, 0xff, 0x3c, 0x93, 0x6c, 0x6c,
|
||||
0xf8, 0xf9, 0x68, 0x2f, 0xde, 0x23, 0xfd, 0x9f, 0xa0, 0xfb, 0x21, 0xa1, 0x58, 0x19, 0xa7, 0xa4,
|
||||
0x32, 0xed, 0x62, 0x65, 0xfe, 0x84, 0xfa, 0x88, 0x4b, 0x95, 0xdb, 0x31, 0xd8, 0x89, 0x94, 0x79,
|
||||
0x4a, 0x9f, 0x1f, 0xa6, 0x64, 0x28, 0x3e, 0x91, 0xd2, 0xa4, 0xa0, 0x98, 0xfd, 0x1f, 0xc0, 0xd9,
|
||||
0x03, 0x45, 0xc9, 0x5a, 0x89, 0x64, 0xad, 0x28, 0xf9, 0x02, 0x1a, 0x26, 0x9e, 0x40, 0x1e, 0x54,
|
||||
0x23, 0xba, 0x13, 0xb9, 0x68, 0xaf, 0x4c, 0x94, 0x68, 0xc6, 0xe0, 0x9f, 0x0a, 0x38, 0x73, 0x26,
|
||||
0xe4, 0xcd, 0xfc, 0xf2, 0x14, 0x3d, 0x85, 0xba, 0x58, 0xd2, 0x2d, 0x4d, 0xf2, 0x26, 0xe4, 0x96,
|
||||
0xc2, 0xdf, 0xb1, 0xa5, 0x8c, 0x13, 0x5c, 0x71, 0x6d, 0x85, 0x1b, 0x0b, 0x3d, 0x85, 0x9a, 0xd9,
|
||||
0x3f, 0x6a, 0xcb, 0x37, 0xdf, 0x3e, 0x22, 0xc6, 0x44, 0xaf, 0xa0, 0x11, 0xd1, 0x9d, 0x5e, 0xae,
|
||||
0xd5, 0xb2, 0xe5, 0xb6, 0x17, 0xf4, 0xc7, 0x74, 0x77, 0xc5, 0x32, 0x73, 0xf7, 0x7a, 0xa4, 0x0d,
|
||||
0x74, 0x06, 0x4d, 0xe5, 0x6c, 0x2e, 0x59, 0x2b, 0x7b, 0x80, 0x45, 0xf7, 0xc2, 0x6a, 0x72, 0xa2,
|
||||
0xdc, 0xec, 0xff, 0x08, 0xad, 0x42, 0xe4, 0x87, 0x26, 0xda, 0x2e, 0xbe, 0x87, 0x57, 0xd0, 0x39,
|
||||
0x88, 0x5a, 0x74, 0xb6, 0x1f, 0x78, 0x0e, 0xe7, 0x0d, 0xa8, 0xc5, 0x9c, 0xc5, 0xab, 0x45, 0xdd,
|
||||
0xe4, 0xfb, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xeb, 0x74, 0x17, 0x7f, 0xc3, 0x07, 0x00, 0x00,
|
||||
}
|
||||
|
16
vendor/github.com/golang/protobuf/proto/proto3_proto/proto3.proto
generated
vendored
16
vendor/github.com/golang/protobuf/proto/proto3_proto/proto3.proto
generated
vendored
@ -32,7 +32,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
import "google/protobuf/any.proto";
|
||||
import "testdata/test.proto";
|
||||
import "test_proto/test.proto";
|
||||
|
||||
package proto3_proto;
|
||||
|
||||
@ -58,14 +58,16 @@ message Message {
|
||||
repeated Humour r_funny = 16;
|
||||
|
||||
map<string, Nested> terrain = 10;
|
||||
testdata.SubDefaults proto2_field = 11;
|
||||
map<string, testdata.SubDefaults> proto2_value = 13;
|
||||
test_proto.SubDefaults proto2_field = 11;
|
||||
map<string, test_proto.SubDefaults> proto2_value = 13;
|
||||
|
||||
google.protobuf.Any anything = 14;
|
||||
repeated google.protobuf.Any many_things = 15;
|
||||
|
||||
Message submessage = 17;
|
||||
repeated Message children = 18;
|
||||
|
||||
map<string, string> string_map = 20;
|
||||
}
|
||||
|
||||
message Nested {
|
||||
@ -85,3 +87,11 @@ message IntMap {
|
||||
message IntMaps {
|
||||
repeated IntMap maps = 1;
|
||||
}
|
||||
|
||||
message TestUTF8 {
|
||||
string scalar = 1;
|
||||
repeated string vector = 2;
|
||||
oneof oneof { string field = 3; }
|
||||
map<string, int64> map_key = 4;
|
||||
map<int64, string> map_value = 5;
|
||||
}
|
||||
|
18
vendor/github.com/golang/protobuf/proto/proto3_test.go
generated
vendored
18
vendor/github.com/golang/protobuf/proto/proto3_test.go
generated
vendored
@ -32,11 +32,12 @@
|
||||
package proto_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
pb "github.com/golang/protobuf/proto/proto3_proto"
|
||||
tpb "github.com/golang/protobuf/proto/testdata"
|
||||
tpb "github.com/golang/protobuf/proto/test_proto"
|
||||
)
|
||||
|
||||
func TestProto3ZeroValues(t *testing.T) {
|
||||
@ -133,3 +134,18 @@ func TestProto3SetDefaults(t *testing.T) {
|
||||
t.Errorf("with in = %v\nproto.SetDefaults(in) =>\ngot %v\nwant %v", in, got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnknownFieldPreservation(t *testing.T) {
|
||||
b1 := "\x0a\x05David" // Known tag 1
|
||||
b2 := "\xc2\x0c\x06Google" // Unknown tag 200
|
||||
b := []byte(b1 + b2)
|
||||
|
||||
m := new(pb.Message)
|
||||
if err := proto.Unmarshal(b, m); err != nil {
|
||||
t.Fatalf("proto.Unmarshal: %v", err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(m.XXX_unrecognized, []byte(b2)) {
|
||||
t.Fatalf("mismatching unknown fields:\ngot %q\nwant %q", m.XXX_unrecognized, b2)
|
||||
}
|
||||
}
|
||||
|
7
vendor/github.com/golang/protobuf/proto/size2_test.go
generated
vendored
7
vendor/github.com/golang/protobuf/proto/size2_test.go
generated
vendored
@ -32,6 +32,7 @@
|
||||
package proto
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@ -51,11 +52,11 @@ func TestVarintSize(t *testing.T) {
|
||||
{128, 2},
|
||||
{16383, 2},
|
||||
{16384, 3},
|
||||
{1<<63 - 1, 9},
|
||||
{1 << 63, 10},
|
||||
{math.MaxInt64, 9},
|
||||
{math.MaxInt64 + 1, 10},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
size := sizeVarint(tc.n)
|
||||
size := SizeVarint(tc.n)
|
||||
if size != tc.size {
|
||||
t.Errorf("sizeVarint(%d) = %d, want %d", tc.n, size, tc.size)
|
||||
}
|
||||
|
29
vendor/github.com/golang/protobuf/proto/size_test.go
generated
vendored
29
vendor/github.com/golang/protobuf/proto/size_test.go
generated
vendored
@ -38,7 +38,7 @@ import (
|
||||
|
||||
. "github.com/golang/protobuf/proto"
|
||||
proto3pb "github.com/golang/protobuf/proto/proto3_proto"
|
||||
pb "github.com/golang/protobuf/proto/testdata"
|
||||
pb "github.com/golang/protobuf/proto/test_proto"
|
||||
)
|
||||
|
||||
var messageWithExtension1 = &pb.MyMessage{Count: Int32(7)}
|
||||
@ -59,6 +59,30 @@ func init() {
|
||||
|
||||
}
|
||||
|
||||
// non-pointer custom message
|
||||
type nonptrMessage struct{}
|
||||
|
||||
func (m nonptrMessage) ProtoMessage() {}
|
||||
func (m nonptrMessage) Reset() {}
|
||||
func (m nonptrMessage) String() string { return "" }
|
||||
|
||||
func (m nonptrMessage) Marshal() ([]byte, error) {
|
||||
return []byte{42}, nil
|
||||
}
|
||||
|
||||
// custom message embedding a proto.Message
|
||||
type messageWithEmbedding struct {
|
||||
*pb.OtherMessage
|
||||
}
|
||||
|
||||
func (m *messageWithEmbedding) ProtoMessage() {}
|
||||
func (m *messageWithEmbedding) Reset() {}
|
||||
func (m *messageWithEmbedding) String() string { return "" }
|
||||
|
||||
func (m *messageWithEmbedding) Marshal() ([]byte, error) {
|
||||
return []byte{42}, nil
|
||||
}
|
||||
|
||||
var SizeTests = []struct {
|
||||
desc string
|
||||
pb Message
|
||||
@ -146,6 +170,9 @@ var SizeTests = []struct {
|
||||
{"oneof group", &pb.Oneof{Union: &pb.Oneof_FGroup{&pb.Oneof_F_Group{X: Int32(52)}}}},
|
||||
{"oneof largest tag", &pb.Oneof{Union: &pb.Oneof_F_Largest_Tag{1}}},
|
||||
{"multiple oneofs", &pb.Oneof{Union: &pb.Oneof_F_Int32{1}, Tormato: &pb.Oneof_Value{2}}},
|
||||
|
||||
{"non-pointer message", nonptrMessage{}},
|
||||
{"custom message with embedding", &messageWithEmbedding{&pb.OtherMessage{}}},
|
||||
}
|
||||
|
||||
func TestSize(t *testing.T) {
|
||||
|
2777
vendor/github.com/golang/protobuf/proto/table_marshal.go
generated
vendored
Normal file
2777
vendor/github.com/golang/protobuf/proto/table_marshal.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
654
vendor/github.com/golang/protobuf/proto/table_merge.go
generated
vendored
Normal file
654
vendor/github.com/golang/protobuf/proto/table_merge.go
generated
vendored
Normal file
@ -0,0 +1,654 @@
|
||||
// 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
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
// Merge merges the src message into dst.
|
||||
// This assumes that dst and src of the same type and are non-nil.
|
||||
func (a *InternalMessageInfo) Merge(dst, src Message) {
|
||||
mi := atomicLoadMergeInfo(&a.merge)
|
||||
if mi == nil {
|
||||
mi = getMergeInfo(reflect.TypeOf(dst).Elem())
|
||||
atomicStoreMergeInfo(&a.merge, mi)
|
||||
}
|
||||
mi.merge(toPointer(&dst), toPointer(&src))
|
||||
}
|
||||
|
||||
type mergeInfo struct {
|
||||
typ reflect.Type
|
||||
|
||||
initialized int32 // 0: only typ is valid, 1: everything is valid
|
||||
lock sync.Mutex
|
||||
|
||||
fields []mergeFieldInfo
|
||||
unrecognized field // Offset of XXX_unrecognized
|
||||
}
|
||||
|
||||
type mergeFieldInfo struct {
|
||||
field field // Offset of field, guaranteed to be valid
|
||||
|
||||
// isPointer reports whether the value in the field is a pointer.
|
||||
// This is true for the following situations:
|
||||
// * Pointer to struct
|
||||
// * Pointer to basic type (proto2 only)
|
||||
// * Slice (first value in slice header is a pointer)
|
||||
// * String (first value in string header is a pointer)
|
||||
isPointer bool
|
||||
|
||||
// basicWidth reports the width of the field assuming that it is directly
|
||||
// embedded in the struct (as is the case for basic types in proto3).
|
||||
// The possible values are:
|
||||
// 0: invalid
|
||||
// 1: bool
|
||||
// 4: int32, uint32, float32
|
||||
// 8: int64, uint64, float64
|
||||
basicWidth int
|
||||
|
||||
// Where dst and src are pointers to the types being merged.
|
||||
merge func(dst, src pointer)
|
||||
}
|
||||
|
||||
var (
|
||||
mergeInfoMap = map[reflect.Type]*mergeInfo{}
|
||||
mergeInfoLock sync.Mutex
|
||||
)
|
||||
|
||||
func getMergeInfo(t reflect.Type) *mergeInfo {
|
||||
mergeInfoLock.Lock()
|
||||
defer mergeInfoLock.Unlock()
|
||||
mi := mergeInfoMap[t]
|
||||
if mi == nil {
|
||||
mi = &mergeInfo{typ: t}
|
||||
mergeInfoMap[t] = mi
|
||||
}
|
||||
return mi
|
||||
}
|
||||
|
||||
// merge merges src into dst assuming they are both of type *mi.typ.
|
||||
func (mi *mergeInfo) merge(dst, src pointer) {
|
||||
if dst.isNil() {
|
||||
panic("proto: nil destination")
|
||||
}
|
||||
if src.isNil() {
|
||||
return // Nothing to do.
|
||||
}
|
||||
|
||||
if atomic.LoadInt32(&mi.initialized) == 0 {
|
||||
mi.computeMergeInfo()
|
||||
}
|
||||
|
||||
for _, fi := range mi.fields {
|
||||
sfp := src.offset(fi.field)
|
||||
|
||||
// As an optimization, we can avoid the merge function call cost
|
||||
// if we know for sure that the source will have no effect
|
||||
// by checking if it is the zero value.
|
||||
if unsafeAllowed {
|
||||
if fi.isPointer && sfp.getPointer().isNil() { // Could be slice or string
|
||||
continue
|
||||
}
|
||||
if fi.basicWidth > 0 {
|
||||
switch {
|
||||
case fi.basicWidth == 1 && !*sfp.toBool():
|
||||
continue
|
||||
case fi.basicWidth == 4 && *sfp.toUint32() == 0:
|
||||
continue
|
||||
case fi.basicWidth == 8 && *sfp.toUint64() == 0:
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dfp := dst.offset(fi.field)
|
||||
fi.merge(dfp, sfp)
|
||||
}
|
||||
|
||||
// TODO: Make this faster?
|
||||
out := dst.asPointerTo(mi.typ).Elem()
|
||||
in := src.asPointerTo(mi.typ).Elem()
|
||||
if emIn, err := extendable(in.Addr().Interface()); err == nil {
|
||||
emOut, _ := extendable(out.Addr().Interface())
|
||||
mIn, muIn := emIn.extensionsRead()
|
||||
if mIn != nil {
|
||||
mOut := emOut.extensionsWrite()
|
||||
muIn.Lock()
|
||||
mergeExtension(mOut, mIn)
|
||||
muIn.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
if mi.unrecognized.IsValid() {
|
||||
if b := *src.offset(mi.unrecognized).toBytes(); len(b) > 0 {
|
||||
*dst.offset(mi.unrecognized).toBytes() = append([]byte(nil), b...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (mi *mergeInfo) computeMergeInfo() {
|
||||
mi.lock.Lock()
|
||||
defer mi.lock.Unlock()
|
||||
if mi.initialized != 0 {
|
||||
return
|
||||
}
|
||||
t := mi.typ
|
||||
n := t.NumField()
|
||||
|
||||
props := GetProperties(t)
|
||||
for i := 0; i < n; i++ {
|
||||
f := t.Field(i)
|
||||
if strings.HasPrefix(f.Name, "XXX_") {
|
||||
continue
|
||||
}
|
||||
|
||||
mfi := mergeFieldInfo{field: toField(&f)}
|
||||
tf := f.Type
|
||||
|
||||
// As an optimization, we can avoid the merge function call cost
|
||||
// if we know for sure that the source will have no effect
|
||||
// by checking if it is the zero value.
|
||||
if unsafeAllowed {
|
||||
switch tf.Kind() {
|
||||
case reflect.Ptr, reflect.Slice, reflect.String:
|
||||
// As a special case, we assume slices and strings are pointers
|
||||
// since we know that the first field in the SliceSlice or
|
||||
// StringHeader is a data pointer.
|
||||
mfi.isPointer = true
|
||||
case reflect.Bool:
|
||||
mfi.basicWidth = 1
|
||||
case reflect.Int32, reflect.Uint32, reflect.Float32:
|
||||
mfi.basicWidth = 4
|
||||
case reflect.Int64, reflect.Uint64, reflect.Float64:
|
||||
mfi.basicWidth = 8
|
||||
}
|
||||
}
|
||||
|
||||
// Unwrap tf to get at its most basic type.
|
||||
var isPointer, isSlice bool
|
||||
if tf.Kind() == reflect.Slice && tf.Elem().Kind() != reflect.Uint8 {
|
||||
isSlice = true
|
||||
tf = tf.Elem()
|
||||
}
|
||||
if tf.Kind() == reflect.Ptr {
|
||||
isPointer = true
|
||||
tf = tf.Elem()
|
||||
}
|
||||
if isPointer && isSlice && tf.Kind() != reflect.Struct {
|
||||
panic("both pointer and slice for basic type in " + tf.Name())
|
||||
}
|
||||
|
||||
switch tf.Kind() {
|
||||
case reflect.Int32:
|
||||
switch {
|
||||
case isSlice: // E.g., []int32
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
// NOTE: toInt32Slice is not defined (see pointer_reflect.go).
|
||||
/*
|
||||
sfsp := src.toInt32Slice()
|
||||
if *sfsp != nil {
|
||||
dfsp := dst.toInt32Slice()
|
||||
*dfsp = append(*dfsp, *sfsp...)
|
||||
if *dfsp == nil {
|
||||
*dfsp = []int64{}
|
||||
}
|
||||
}
|
||||
*/
|
||||
sfs := src.getInt32Slice()
|
||||
if sfs != nil {
|
||||
dfs := dst.getInt32Slice()
|
||||
dfs = append(dfs, sfs...)
|
||||
if dfs == nil {
|
||||
dfs = []int32{}
|
||||
}
|
||||
dst.setInt32Slice(dfs)
|
||||
}
|
||||
}
|
||||
case isPointer: // E.g., *int32
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
// NOTE: toInt32Ptr is not defined (see pointer_reflect.go).
|
||||
/*
|
||||
sfpp := src.toInt32Ptr()
|
||||
if *sfpp != nil {
|
||||
dfpp := dst.toInt32Ptr()
|
||||
if *dfpp == nil {
|
||||
*dfpp = Int32(**sfpp)
|
||||
} else {
|
||||
**dfpp = **sfpp
|
||||
}
|
||||
}
|
||||
*/
|
||||
sfp := src.getInt32Ptr()
|
||||
if sfp != nil {
|
||||
dfp := dst.getInt32Ptr()
|
||||
if dfp == nil {
|
||||
dst.setInt32Ptr(*sfp)
|
||||
} else {
|
||||
*dfp = *sfp
|
||||
}
|
||||
}
|
||||
}
|
||||
default: // E.g., int32
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
if v := *src.toInt32(); v != 0 {
|
||||
*dst.toInt32() = v
|
||||
}
|
||||
}
|
||||
}
|
||||
case reflect.Int64:
|
||||
switch {
|
||||
case isSlice: // E.g., []int64
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
sfsp := src.toInt64Slice()
|
||||
if *sfsp != nil {
|
||||
dfsp := dst.toInt64Slice()
|
||||
*dfsp = append(*dfsp, *sfsp...)
|
||||
if *dfsp == nil {
|
||||
*dfsp = []int64{}
|
||||
}
|
||||
}
|
||||
}
|
||||
case isPointer: // E.g., *int64
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
sfpp := src.toInt64Ptr()
|
||||
if *sfpp != nil {
|
||||
dfpp := dst.toInt64Ptr()
|
||||
if *dfpp == nil {
|
||||
*dfpp = Int64(**sfpp)
|
||||
} else {
|
||||
**dfpp = **sfpp
|
||||
}
|
||||
}
|
||||
}
|
||||
default: // E.g., int64
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
if v := *src.toInt64(); v != 0 {
|
||||
*dst.toInt64() = v
|
||||
}
|
||||
}
|
||||
}
|
||||
case reflect.Uint32:
|
||||
switch {
|
||||
case isSlice: // E.g., []uint32
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
sfsp := src.toUint32Slice()
|
||||
if *sfsp != nil {
|
||||
dfsp := dst.toUint32Slice()
|
||||
*dfsp = append(*dfsp, *sfsp...)
|
||||
if *dfsp == nil {
|
||||
*dfsp = []uint32{}
|
||||
}
|
||||
}
|
||||
}
|
||||
case isPointer: // E.g., *uint32
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
sfpp := src.toUint32Ptr()
|
||||
if *sfpp != nil {
|
||||
dfpp := dst.toUint32Ptr()
|
||||
if *dfpp == nil {
|
||||
*dfpp = Uint32(**sfpp)
|
||||
} else {
|
||||
**dfpp = **sfpp
|
||||
}
|
||||
}
|
||||
}
|
||||
default: // E.g., uint32
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
if v := *src.toUint32(); v != 0 {
|
||||
*dst.toUint32() = v
|
||||
}
|
||||
}
|
||||
}
|
||||
case reflect.Uint64:
|
||||
switch {
|
||||
case isSlice: // E.g., []uint64
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
sfsp := src.toUint64Slice()
|
||||
if *sfsp != nil {
|
||||
dfsp := dst.toUint64Slice()
|
||||
*dfsp = append(*dfsp, *sfsp...)
|
||||
if *dfsp == nil {
|
||||
*dfsp = []uint64{}
|
||||
}
|
||||
}
|
||||
}
|
||||
case isPointer: // E.g., *uint64
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
sfpp := src.toUint64Ptr()
|
||||
if *sfpp != nil {
|
||||
dfpp := dst.toUint64Ptr()
|
||||
if *dfpp == nil {
|
||||
*dfpp = Uint64(**sfpp)
|
||||
} else {
|
||||
**dfpp = **sfpp
|
||||
}
|
||||
}
|
||||
}
|
||||
default: // E.g., uint64
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
if v := *src.toUint64(); v != 0 {
|
||||
*dst.toUint64() = v
|
||||
}
|
||||
}
|
||||
}
|
||||
case reflect.Float32:
|
||||
switch {
|
||||
case isSlice: // E.g., []float32
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
sfsp := src.toFloat32Slice()
|
||||
if *sfsp != nil {
|
||||
dfsp := dst.toFloat32Slice()
|
||||
*dfsp = append(*dfsp, *sfsp...)
|
||||
if *dfsp == nil {
|
||||
*dfsp = []float32{}
|
||||
}
|
||||
}
|
||||
}
|
||||
case isPointer: // E.g., *float32
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
sfpp := src.toFloat32Ptr()
|
||||
if *sfpp != nil {
|
||||
dfpp := dst.toFloat32Ptr()
|
||||
if *dfpp == nil {
|
||||
*dfpp = Float32(**sfpp)
|
||||
} else {
|
||||
**dfpp = **sfpp
|
||||
}
|
||||
}
|
||||
}
|
||||
default: // E.g., float32
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
if v := *src.toFloat32(); v != 0 {
|
||||
*dst.toFloat32() = v
|
||||
}
|
||||
}
|
||||
}
|
||||
case reflect.Float64:
|
||||
switch {
|
||||
case isSlice: // E.g., []float64
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
sfsp := src.toFloat64Slice()
|
||||
if *sfsp != nil {
|
||||
dfsp := dst.toFloat64Slice()
|
||||
*dfsp = append(*dfsp, *sfsp...)
|
||||
if *dfsp == nil {
|
||||
*dfsp = []float64{}
|
||||
}
|
||||
}
|
||||
}
|
||||
case isPointer: // E.g., *float64
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
sfpp := src.toFloat64Ptr()
|
||||
if *sfpp != nil {
|
||||
dfpp := dst.toFloat64Ptr()
|
||||
if *dfpp == nil {
|
||||
*dfpp = Float64(**sfpp)
|
||||
} else {
|
||||
**dfpp = **sfpp
|
||||
}
|
||||
}
|
||||
}
|
||||
default: // E.g., float64
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
if v := *src.toFloat64(); v != 0 {
|
||||
*dst.toFloat64() = v
|
||||
}
|
||||
}
|
||||
}
|
||||
case reflect.Bool:
|
||||
switch {
|
||||
case isSlice: // E.g., []bool
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
sfsp := src.toBoolSlice()
|
||||
if *sfsp != nil {
|
||||
dfsp := dst.toBoolSlice()
|
||||
*dfsp = append(*dfsp, *sfsp...)
|
||||
if *dfsp == nil {
|
||||
*dfsp = []bool{}
|
||||
}
|
||||
}
|
||||
}
|
||||
case isPointer: // E.g., *bool
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
sfpp := src.toBoolPtr()
|
||||
if *sfpp != nil {
|
||||
dfpp := dst.toBoolPtr()
|
||||
if *dfpp == nil {
|
||||
*dfpp = Bool(**sfpp)
|
||||
} else {
|
||||
**dfpp = **sfpp
|
||||
}
|
||||
}
|
||||
}
|
||||
default: // E.g., bool
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
if v := *src.toBool(); v {
|
||||
*dst.toBool() = v
|
||||
}
|
||||
}
|
||||
}
|
||||
case reflect.String:
|
||||
switch {
|
||||
case isSlice: // E.g., []string
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
sfsp := src.toStringSlice()
|
||||
if *sfsp != nil {
|
||||
dfsp := dst.toStringSlice()
|
||||
*dfsp = append(*dfsp, *sfsp...)
|
||||
if *dfsp == nil {
|
||||
*dfsp = []string{}
|
||||
}
|
||||
}
|
||||
}
|
||||
case isPointer: // E.g., *string
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
sfpp := src.toStringPtr()
|
||||
if *sfpp != nil {
|
||||
dfpp := dst.toStringPtr()
|
||||
if *dfpp == nil {
|
||||
*dfpp = String(**sfpp)
|
||||
} else {
|
||||
**dfpp = **sfpp
|
||||
}
|
||||
}
|
||||
}
|
||||
default: // E.g., string
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
if v := *src.toString(); v != "" {
|
||||
*dst.toString() = v
|
||||
}
|
||||
}
|
||||
}
|
||||
case reflect.Slice:
|
||||
isProto3 := props.Prop[i].proto3
|
||||
switch {
|
||||
case isPointer:
|
||||
panic("bad pointer in byte slice case in " + tf.Name())
|
||||
case tf.Elem().Kind() != reflect.Uint8:
|
||||
panic("bad element kind in byte slice case in " + tf.Name())
|
||||
case isSlice: // E.g., [][]byte
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
sbsp := src.toBytesSlice()
|
||||
if *sbsp != nil {
|
||||
dbsp := dst.toBytesSlice()
|
||||
for _, sb := range *sbsp {
|
||||
if sb == nil {
|
||||
*dbsp = append(*dbsp, nil)
|
||||
} else {
|
||||
*dbsp = append(*dbsp, append([]byte{}, sb...))
|
||||
}
|
||||
}
|
||||
if *dbsp == nil {
|
||||
*dbsp = [][]byte{}
|
||||
}
|
||||
}
|
||||
}
|
||||
default: // E.g., []byte
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
sbp := src.toBytes()
|
||||
if *sbp != nil {
|
||||
dbp := dst.toBytes()
|
||||
if !isProto3 || len(*sbp) > 0 {
|
||||
*dbp = append([]byte{}, *sbp...)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
case reflect.Struct:
|
||||
switch {
|
||||
case !isPointer:
|
||||
panic(fmt.Sprintf("message field %s without pointer", tf))
|
||||
case isSlice: // E.g., []*pb.T
|
||||
mi := getMergeInfo(tf)
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
sps := src.getPointerSlice()
|
||||
if sps != nil {
|
||||
dps := dst.getPointerSlice()
|
||||
for _, sp := range sps {
|
||||
var dp pointer
|
||||
if !sp.isNil() {
|
||||
dp = valToPointer(reflect.New(tf))
|
||||
mi.merge(dp, sp)
|
||||
}
|
||||
dps = append(dps, dp)
|
||||
}
|
||||
if dps == nil {
|
||||
dps = []pointer{}
|
||||
}
|
||||
dst.setPointerSlice(dps)
|
||||
}
|
||||
}
|
||||
default: // E.g., *pb.T
|
||||
mi := getMergeInfo(tf)
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
sp := src.getPointer()
|
||||
if !sp.isNil() {
|
||||
dp := dst.getPointer()
|
||||
if dp.isNil() {
|
||||
dp = valToPointer(reflect.New(tf))
|
||||
dst.setPointer(dp)
|
||||
}
|
||||
mi.merge(dp, sp)
|
||||
}
|
||||
}
|
||||
}
|
||||
case reflect.Map:
|
||||
switch {
|
||||
case isPointer || isSlice:
|
||||
panic("bad pointer or slice in map case in " + tf.Name())
|
||||
default: // E.g., map[K]V
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
sm := src.asPointerTo(tf).Elem()
|
||||
if sm.Len() == 0 {
|
||||
return
|
||||
}
|
||||
dm := dst.asPointerTo(tf).Elem()
|
||||
if dm.IsNil() {
|
||||
dm.Set(reflect.MakeMap(tf))
|
||||
}
|
||||
|
||||
switch tf.Elem().Kind() {
|
||||
case reflect.Ptr: // Proto struct (e.g., *T)
|
||||
for _, key := range sm.MapKeys() {
|
||||
val := sm.MapIndex(key)
|
||||
val = reflect.ValueOf(Clone(val.Interface().(Message)))
|
||||
dm.SetMapIndex(key, val)
|
||||
}
|
||||
case reflect.Slice: // E.g. Bytes type (e.g., []byte)
|
||||
for _, key := range sm.MapKeys() {
|
||||
val := sm.MapIndex(key)
|
||||
val = reflect.ValueOf(append([]byte{}, val.Bytes()...))
|
||||
dm.SetMapIndex(key, val)
|
||||
}
|
||||
default: // Basic type (e.g., string)
|
||||
for _, key := range sm.MapKeys() {
|
||||
val := sm.MapIndex(key)
|
||||
dm.SetMapIndex(key, val)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
case reflect.Interface:
|
||||
// Must be oneof field.
|
||||
switch {
|
||||
case isPointer || isSlice:
|
||||
panic("bad pointer or slice in interface case in " + tf.Name())
|
||||
default: // E.g., interface{}
|
||||
// TODO: Make this faster?
|
||||
mfi.merge = func(dst, src pointer) {
|
||||
su := src.asPointerTo(tf).Elem()
|
||||
if !su.IsNil() {
|
||||
du := dst.asPointerTo(tf).Elem()
|
||||
typ := su.Elem().Type()
|
||||
if du.IsNil() || du.Elem().Type() != typ {
|
||||
du.Set(reflect.New(typ.Elem())) // Initialize interface if empty
|
||||
}
|
||||
sv := su.Elem().Elem().Field(0)
|
||||
if sv.Kind() == reflect.Ptr && sv.IsNil() {
|
||||
return
|
||||
}
|
||||
dv := du.Elem().Elem().Field(0)
|
||||
if dv.Kind() == reflect.Ptr && dv.IsNil() {
|
||||
dv.Set(reflect.New(sv.Type().Elem())) // Initialize proto message if empty
|
||||
}
|
||||
switch sv.Type().Kind() {
|
||||
case reflect.Ptr: // Proto struct (e.g., *T)
|
||||
Merge(dv.Interface().(Message), sv.Interface().(Message))
|
||||
case reflect.Slice: // E.g. Bytes type (e.g., []byte)
|
||||
dv.Set(reflect.ValueOf(append([]byte{}, sv.Bytes()...)))
|
||||
default: // Basic type (e.g., string)
|
||||
dv.Set(sv)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
panic(fmt.Sprintf("merger not found for type:%s", tf))
|
||||
}
|
||||
mi.fields = append(mi.fields, mfi)
|
||||
}
|
||||
|
||||
mi.unrecognized = invalidField
|
||||
if f, ok := t.FieldByName("XXX_unrecognized"); ok {
|
||||
if f.Type != reflect.TypeOf([]byte{}) {
|
||||
panic("expected XXX_unrecognized to be of type []byte")
|
||||
}
|
||||
mi.unrecognized = toField(&f)
|
||||
}
|
||||
|
||||
atomic.StoreInt32(&mi.initialized, 1)
|
||||
}
|
2051
vendor/github.com/golang/protobuf/proto/table_unmarshal.go
generated
vendored
Normal file
2051
vendor/github.com/golang/protobuf/proto/table_unmarshal.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
5377
vendor/github.com/golang/protobuf/proto/test_proto/test.pb.go
generated
vendored
Normal file
5377
vendor/github.com/golang/protobuf/proto/test_proto/test.pb.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@ -33,7 +33,9 @@
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package testdata;
|
||||
option go_package = "github.com/golang/protobuf/proto/test_proto";
|
||||
|
||||
package test_proto;
|
||||
|
||||
enum FOO { FOO1 = 1; };
|
||||
|
||||
@ -96,6 +98,8 @@ message GoTest {
|
||||
required bytes F_Bytes_required = 101;
|
||||
required sint32 F_Sint32_required = 102;
|
||||
required sint64 F_Sint64_required = 103;
|
||||
required sfixed32 F_Sfixed32_required = 104;
|
||||
required sfixed64 F_Sfixed64_required = 105;
|
||||
|
||||
// Repeated fields of all basic types
|
||||
repeated bool F_Bool_repeated = 20;
|
||||
@ -111,6 +115,8 @@ message GoTest {
|
||||
repeated bytes F_Bytes_repeated = 201;
|
||||
repeated sint32 F_Sint32_repeated = 202;
|
||||
repeated sint64 F_Sint64_repeated = 203;
|
||||
repeated sfixed32 F_Sfixed32_repeated = 204;
|
||||
repeated sfixed64 F_Sfixed64_repeated = 205;
|
||||
|
||||
// Optional fields of all basic types
|
||||
optional bool F_Bool_optional = 30;
|
||||
@ -126,6 +132,8 @@ message GoTest {
|
||||
optional bytes F_Bytes_optional = 301;
|
||||
optional sint32 F_Sint32_optional = 302;
|
||||
optional sint64 F_Sint64_optional = 303;
|
||||
optional sfixed32 F_Sfixed32_optional = 304;
|
||||
optional sfixed64 F_Sfixed64_optional = 305;
|
||||
|
||||
// Default-valued fields of all basic types
|
||||
optional bool F_Bool_defaulted = 40 [default=true];
|
||||
@ -141,6 +149,8 @@ message GoTest {
|
||||
optional bytes F_Bytes_defaulted = 401 [default="Bignose"];
|
||||
optional sint32 F_Sint32_defaulted = 402 [default = -32];
|
||||
optional sint64 F_Sint64_defaulted = 403 [default = -64];
|
||||
optional sfixed32 F_Sfixed32_defaulted = 404 [default = -32];
|
||||
optional sfixed64 F_Sfixed64_defaulted = 405 [default = -64];
|
||||
|
||||
// Packed repeated fields (no string or bytes).
|
||||
repeated bool F_Bool_repeated_packed = 50 [packed=true];
|
||||
@ -154,6 +164,8 @@ message GoTest {
|
||||
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];
|
||||
repeated sfixed32 F_Sfixed32_repeated_packed = 504 [packed=true];
|
||||
repeated sfixed64 F_Sfixed64_repeated_packed = 505 [packed=true];
|
||||
|
||||
// Required, repeated, and optional groups.
|
||||
required group RequiredGroup = 70 {
|
||||
@ -285,10 +297,12 @@ message Ext {
|
||||
}
|
||||
|
||||
optional string data = 1;
|
||||
map<int32, int32> map_field = 2;
|
||||
}
|
||||
|
||||
extend MyMessage {
|
||||
repeated string greeting = 106;
|
||||
// leave field 200 unregistered for testing
|
||||
}
|
||||
|
||||
message ComplexExtension {
|
||||
@ -342,7 +356,7 @@ extend DefaultsMessage {
|
||||
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 string default_string = 214 [default = "Hello, string,def=foo"];
|
||||
optional bytes default_bytes = 215 [default = "Hello, bytes"];
|
||||
optional DefaultsMessage.DefaultsEnum default_enum = 216 [default = ONE];
|
||||
}
|
||||
@ -546,3 +560,11 @@ message Communique {
|
||||
Strings msg = 10;
|
||||
}
|
||||
}
|
||||
|
||||
message TestUTF8 {
|
||||
optional string scalar = 1;
|
||||
repeated string vector = 2;
|
||||
oneof oneof { string field = 3; }
|
||||
map<string, int64> map_key = 4;
|
||||
map<int64, string> map_value = 5;
|
||||
}
|
50
vendor/github.com/golang/protobuf/proto/testdata/Makefile
generated
vendored
50
vendor/github.com/golang/protobuf/proto/testdata/Makefile
generated
vendored
@ -1,50 +0,0 @@
|
||||
# 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.
|
||||
|
||||
|
||||
include ../../Make.protobuf
|
||||
|
||||
all: regenerate
|
||||
|
||||
regenerate:
|
||||
rm -f test.pb.go
|
||||
make test.pb.go
|
||||
|
||||
# The following rules are just aids to development. Not needed for typical testing.
|
||||
|
||||
diff: regenerate
|
||||
git diff test.pb.go
|
||||
|
||||
restore:
|
||||
cp test.pb.go.golden test.pb.go
|
||||
|
||||
preserve:
|
||||
cp test.pb.go test.pb.go.golden
|
4147
vendor/github.com/golang/protobuf/proto/testdata/test.pb.go
generated
vendored
4147
vendor/github.com/golang/protobuf/proto/testdata/test.pb.go
generated
vendored
File diff suppressed because it is too large
Load Diff
65
vendor/github.com/golang/protobuf/proto/text.go
generated
vendored
65
vendor/github.com/golang/protobuf/proto/text.go
generated
vendored
@ -50,7 +50,6 @@ import (
|
||||
var (
|
||||
newline = []byte("\n")
|
||||
spaces = []byte(" ")
|
||||
gtNewline = []byte(">\n")
|
||||
endBraceNewline = []byte("}\n")
|
||||
backslashN = []byte{'\\', 'n'}
|
||||
backslashR = []byte{'\\', 'r'}
|
||||
@ -170,11 +169,6 @@ func writeName(w *textWriter, props *Properties) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// raw is the interface satisfied by RawMessage.
|
||||
type raw interface {
|
||||
Bytes() []byte
|
||||
}
|
||||
|
||||
func requiresQuotes(u string) bool {
|
||||
// When type URL contains any characters except [0-9A-Za-z./\-]*, it must be quoted.
|
||||
for _, ch := range u {
|
||||
@ -269,6 +263,10 @@ func (tm *TextMarshaler) writeStruct(w *textWriter, sv reflect.Value) error {
|
||||
props := sprops.Prop[i]
|
||||
name := st.Field(i).Name
|
||||
|
||||
if name == "XXX_NoUnkeyedLiteral" {
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.HasPrefix(name, "XXX_") {
|
||||
// There are two XXX_ fields:
|
||||
// XXX_unrecognized []byte
|
||||
@ -355,7 +353,7 @@ func (tm *TextMarshaler) writeStruct(w *textWriter, sv reflect.Value) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := tm.writeAny(w, key, props.mkeyprop); err != nil {
|
||||
if err := tm.writeAny(w, key, props.MapKeyProp); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := w.WriteByte('\n'); err != nil {
|
||||
@ -372,7 +370,7 @@ func (tm *TextMarshaler) writeStruct(w *textWriter, sv reflect.Value) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := tm.writeAny(w, val, props.mvalprop); err != nil {
|
||||
if err := tm.writeAny(w, val, props.MapValProp); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := w.WriteByte('\n'); err != nil {
|
||||
@ -436,12 +434,6 @@ func (tm *TextMarshaler) writeStruct(w *textWriter, sv reflect.Value) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if b, ok := fv.Interface().(raw); ok {
|
||||
if err := writeRaw(w, b.Bytes()); err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// Enums have a String method, so writeAny will work fine.
|
||||
if err := tm.writeAny(w, fv, props); err != nil {
|
||||
@ -455,7 +447,7 @@ func (tm *TextMarshaler) writeStruct(w *textWriter, sv reflect.Value) error {
|
||||
|
||||
// Extensions (the XXX_extensions field).
|
||||
pv := sv.Addr()
|
||||
if _, ok := extendable(pv.Interface()); ok {
|
||||
if _, err := extendable(pv.Interface()); err == nil {
|
||||
if err := tm.writeExtensions(w, pv); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -464,27 +456,6 @@ func (tm *TextMarshaler) writeStruct(w *textWriter, sv reflect.Value) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// writeRaw writes an uninterpreted raw message.
|
||||
func writeRaw(w *textWriter, b []byte) error {
|
||||
if err := w.WriteByte('<'); err != nil {
|
||||
return err
|
||||
}
|
||||
if !w.compact {
|
||||
if err := w.WriteByte('\n'); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
w.indent()
|
||||
if err := writeUnknownStruct(w, b); err != nil {
|
||||
return err
|
||||
}
|
||||
w.unindent()
|
||||
if err := w.WriteByte('>'); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// writeAny writes an arbitrary field.
|
||||
func (tm *TextMarshaler) writeAny(w *textWriter, v reflect.Value, props *Properties) error {
|
||||
v = reflect.Indirect(v)
|
||||
@ -535,6 +506,19 @@ func (tm *TextMarshaler) writeAny(w *textWriter, v reflect.Value, props *Propert
|
||||
}
|
||||
}
|
||||
w.indent()
|
||||
if v.CanAddr() {
|
||||
// Calling v.Interface on a struct causes the reflect package to
|
||||
// copy the entire struct. This is racy with the new Marshaler
|
||||
// since we atomically update the XXX_sizecache.
|
||||
//
|
||||
// Thus, we retrieve a pointer to the struct if possible to avoid
|
||||
// a race since v.Interface on the pointer doesn't copy the struct.
|
||||
//
|
||||
// If v is not addressable, then we are not worried about a race
|
||||
// since it implies that the binary Marshaler cannot possibly be
|
||||
// mutating this value.
|
||||
v = v.Addr()
|
||||
}
|
||||
if etm, ok := v.Interface().(encoding.TextMarshaler); ok {
|
||||
text, err := etm.MarshalText()
|
||||
if err != nil {
|
||||
@ -543,8 +527,13 @@ func (tm *TextMarshaler) writeAny(w *textWriter, v reflect.Value, props *Propert
|
||||
if _, err = w.Write(text); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if err := tm.writeStruct(w, v); err != nil {
|
||||
return err
|
||||
} else {
|
||||
if v.Kind() == reflect.Ptr {
|
||||
v = v.Elem()
|
||||
}
|
||||
if err := tm.writeStruct(w, v); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
w.unindent()
|
||||
if err := w.WriteByte(ket); err != nil {
|
||||
|
83
vendor/github.com/golang/protobuf/proto/text_parser.go
generated
vendored
83
vendor/github.com/golang/protobuf/proto/text_parser.go
generated
vendored
@ -206,7 +206,6 @@ func (p *textParser) advance() {
|
||||
|
||||
var (
|
||||
errBadUTF8 = errors.New("proto: bad UTF-8")
|
||||
errBadHex = errors.New("proto: bad hexadecimal")
|
||||
)
|
||||
|
||||
func unquoteC(s string, quote rune) (string, error) {
|
||||
@ -277,60 +276,47 @@ func unescape(s string) (ch string, tail string, err error) {
|
||||
return "?", s, nil // trigraph workaround
|
||||
case '\'', '"', '\\':
|
||||
return string(r), s, nil
|
||||
case '0', '1', '2', '3', '4', '5', '6', '7', 'x', 'X':
|
||||
case '0', '1', '2', '3', '4', '5', '6', '7':
|
||||
if len(s) < 2 {
|
||||
return "", "", fmt.Errorf(`\%c requires 2 following digits`, r)
|
||||
}
|
||||
base := 8
|
||||
ss := s[:2]
|
||||
ss := string(r) + s[:2]
|
||||
s = s[2:]
|
||||
if r == 'x' || r == 'X' {
|
||||
base = 16
|
||||
} else {
|
||||
ss = string(r) + ss
|
||||
}
|
||||
i, err := strconv.ParseUint(ss, base, 8)
|
||||
i, err := strconv.ParseUint(ss, 8, 8)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
return "", "", fmt.Errorf(`\%s contains non-octal digits`, ss)
|
||||
}
|
||||
return string([]byte{byte(i)}), s, nil
|
||||
case 'u', 'U':
|
||||
n := 4
|
||||
if r == 'U' {
|
||||
case 'x', 'X', 'u', 'U':
|
||||
var n int
|
||||
switch r {
|
||||
case 'x', 'X':
|
||||
n = 2
|
||||
case 'u':
|
||||
n = 4
|
||||
case 'U':
|
||||
n = 8
|
||||
}
|
||||
if len(s) < n {
|
||||
return "", "", fmt.Errorf(`\%c requires %d digits`, r, n)
|
||||
}
|
||||
|
||||
bs := make([]byte, n/2)
|
||||
for i := 0; i < n; i += 2 {
|
||||
a, ok1 := unhex(s[i])
|
||||
b, ok2 := unhex(s[i+1])
|
||||
if !ok1 || !ok2 {
|
||||
return "", "", errBadHex
|
||||
}
|
||||
bs[i/2] = a<<4 | b
|
||||
return "", "", fmt.Errorf(`\%c requires %d following digits`, r, n)
|
||||
}
|
||||
ss := s[:n]
|
||||
s = s[n:]
|
||||
return string(bs), s, nil
|
||||
i, err := strconv.ParseUint(ss, 16, 64)
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf(`\%c%s contains non-hexadecimal digits`, r, ss)
|
||||
}
|
||||
if r == 'x' || r == 'X' {
|
||||
return string([]byte{byte(i)}), s, nil
|
||||
}
|
||||
if i > utf8.MaxRune {
|
||||
return "", "", fmt.Errorf(`\%c%s is not a valid Unicode code point`, r, ss)
|
||||
}
|
||||
return string(i), s, nil
|
||||
}
|
||||
return "", "", fmt.Errorf(`unknown escape \%c`, r)
|
||||
}
|
||||
|
||||
// Adapted from src/pkg/strconv/quote.go.
|
||||
func unhex(b byte) (v byte, ok bool) {
|
||||
switch {
|
||||
case '0' <= b && b <= '9':
|
||||
return b - '0', true
|
||||
case 'a' <= b && b <= 'f':
|
||||
return b - 'a' + 10, true
|
||||
case 'A' <= b && b <= 'F':
|
||||
return b - 'A' + 10, true
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
||||
// Back off the parser by one token. Can only be done between calls to next().
|
||||
// It makes the next advance() a no-op.
|
||||
func (p *textParser) back() { p.backed = true }
|
||||
@ -644,17 +630,17 @@ func (p *textParser) readStruct(sv reflect.Value, terminator string) error {
|
||||
if err := p.consumeToken(":"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := p.readAny(key, props.mkeyprop); err != nil {
|
||||
if err := p.readAny(key, props.MapKeyProp); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := p.consumeOptionalSeparator(); err != nil {
|
||||
return err
|
||||
}
|
||||
case "value":
|
||||
if err := p.checkForColon(props.mvalprop, dst.Type().Elem()); err != nil {
|
||||
if err := p.checkForColon(props.MapValProp, dst.Type().Elem()); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := p.readAny(val, props.mvalprop); err != nil {
|
||||
if err := p.readAny(val, props.MapValProp); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := p.consumeOptionalSeparator(); err != nil {
|
||||
@ -728,6 +714,9 @@ func (p *textParser) consumeExtName() (string, error) {
|
||||
if tok.err != nil {
|
||||
return "", p.errorf("unrecognized type_url or extension name: %s", tok.err)
|
||||
}
|
||||
if p.done && tok.value != "]" {
|
||||
return "", p.errorf("unclosed type_url or extension name")
|
||||
}
|
||||
}
|
||||
return strings.Join(parts, ""), nil
|
||||
}
|
||||
@ -865,7 +854,7 @@ func (p *textParser) readAny(v reflect.Value, props *Properties) error {
|
||||
return p.readStruct(fv, terminator)
|
||||
case reflect.Uint32:
|
||||
if x, err := strconv.ParseUint(tok.value, 0, 32); err == nil {
|
||||
fv.SetUint(x)
|
||||
fv.SetUint(uint64(x))
|
||||
return nil
|
||||
}
|
||||
case reflect.Uint64:
|
||||
@ -883,13 +872,9 @@ func (p *textParser) readAny(v reflect.Value, props *Properties) error {
|
||||
// UnmarshalText returns *RequiredNotSetError.
|
||||
func UnmarshalText(s string, pb Message) error {
|
||||
if um, ok := pb.(encoding.TextUnmarshaler); ok {
|
||||
err := um.UnmarshalText([]byte(s))
|
||||
return err
|
||||
return um.UnmarshalText([]byte(s))
|
||||
}
|
||||
pb.Reset()
|
||||
v := reflect.ValueOf(pb)
|
||||
if pe := newTextParser(s).readStruct(v.Elem(), ""); pe != nil {
|
||||
return pe
|
||||
}
|
||||
return nil
|
||||
return newTextParser(s).readStruct(v.Elem(), "")
|
||||
}
|
||||
|
57
vendor/github.com/golang/protobuf/proto/text_parser_test.go
generated
vendored
57
vendor/github.com/golang/protobuf/proto/text_parser_test.go
generated
vendored
@ -32,13 +32,13 @@
|
||||
package proto_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
. "github.com/golang/protobuf/proto"
|
||||
proto3pb "github.com/golang/protobuf/proto/proto3_proto"
|
||||
. "github.com/golang/protobuf/proto/testdata"
|
||||
. "github.com/golang/protobuf/proto/test_proto"
|
||||
)
|
||||
|
||||
type UnmarshalTextTest struct {
|
||||
@ -167,10 +167,19 @@ var unMarshalTextTests = []UnmarshalTextTest{
|
||||
|
||||
// Quoted string with UTF-8 bytes.
|
||||
{
|
||||
in: "count:42 name: '\303\277\302\201\xAB'",
|
||||
in: "count:42 name: '\303\277\302\201\x00\xAB\xCD\xEF'",
|
||||
out: &MyMessage{
|
||||
Count: Int32(42),
|
||||
Name: String("\303\277\302\201\xAB"),
|
||||
Name: String("\303\277\302\201\x00\xAB\xCD\xEF"),
|
||||
},
|
||||
},
|
||||
|
||||
// Quoted string with unicode escapes.
|
||||
{
|
||||
in: `count: 42 name: "\u0047\U00000047\uffff\U0010ffff"`,
|
||||
out: &MyMessage{
|
||||
Count: Int32(42),
|
||||
Name: String("GG\uffff\U0010ffff"),
|
||||
},
|
||||
},
|
||||
|
||||
@ -180,6 +189,24 @@ var unMarshalTextTests = []UnmarshalTextTest{
|
||||
err: `line 1.15: invalid quoted string "\0": \0 requires 2 following digits`,
|
||||
},
|
||||
|
||||
// Bad \u escape
|
||||
{
|
||||
in: `count: 42 name: "\u000"`,
|
||||
err: `line 1.16: invalid quoted string "\u000": \u requires 4 following digits`,
|
||||
},
|
||||
|
||||
// Bad \U escape
|
||||
{
|
||||
in: `count: 42 name: "\U0000000"`,
|
||||
err: `line 1.16: invalid quoted string "\U0000000": \U requires 8 following digits`,
|
||||
},
|
||||
|
||||
// Bad \U escape
|
||||
{
|
||||
in: `count: 42 name: "\xxx"`,
|
||||
err: `line 1.16: invalid quoted string "\xxx": \xxx contains non-hexadecimal digits`,
|
||||
},
|
||||
|
||||
// Number too large for int64
|
||||
{
|
||||
in: "count: 1 others { key: 123456789012345678901 }",
|
||||
@ -263,6 +290,12 @@ var unMarshalTextTests = []UnmarshalTextTest{
|
||||
err: `line 1.17: invalid float32: "17.4"`,
|
||||
},
|
||||
|
||||
// unclosed bracket doesn't cause infinite loop
|
||||
{
|
||||
in: `[`,
|
||||
err: `line 1.0: unclosed type_url or extension name`,
|
||||
},
|
||||
|
||||
// Enum
|
||||
{
|
||||
in: `count:42 bikeshed: BLUE`,
|
||||
@ -330,7 +363,7 @@ var unMarshalTextTests = []UnmarshalTextTest{
|
||||
// Missing required field
|
||||
{
|
||||
in: `name: "Pawel"`,
|
||||
err: `proto: required field "testdata.MyMessage.count" not set`,
|
||||
err: fmt.Sprintf(`proto: required field "%T.count" not set`, MyMessage{}),
|
||||
out: &MyMessage{
|
||||
Name: String("Pawel"),
|
||||
},
|
||||
@ -339,7 +372,7 @@ var unMarshalTextTests = []UnmarshalTextTest{
|
||||
// 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`,
|
||||
err: fmt.Sprintf(`proto: required field "%T.host" not set`, InnerMessage{}),
|
||||
out: &MyMessage{
|
||||
Count: Int32(42),
|
||||
WeMustGoDeeper: &RequiredInnerMessage{LeoFinallyWonAnOscar: &InnerMessage{}},
|
||||
@ -470,10 +503,10 @@ var unMarshalTextTests = []UnmarshalTextTest{
|
||||
},
|
||||
|
||||
// Extension
|
||||
buildExtStructTest(`count: 42 [testdata.Ext.more]:<data:"Hello, world!" >`),
|
||||
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"`),
|
||||
buildExtStructTest(`count: 42 [test_proto.Ext.more]:<data:"Hello, world!" >`),
|
||||
buildExtStructTest(`count: 42 [test_proto.Ext.more] {data:"Hello, world!"}`),
|
||||
buildExtDataTest(`count: 42 [test_proto.Ext.text]:"Hello, world!" [test_proto.Ext.number]:1729`),
|
||||
buildExtRepStringTest(`count: 42 [test_proto.greeting]:"bula" [test_proto.greeting]:"hola"`),
|
||||
|
||||
// Big all-in-one
|
||||
{
|
||||
@ -534,7 +567,7 @@ func TestUnmarshalText(t *testing.T) {
|
||||
// We don't expect failure.
|
||||
if err != nil {
|
||||
t.Errorf("Test %d: Unexpected error: %v", i, err)
|
||||
} else if !reflect.DeepEqual(pb, test.out) {
|
||||
} else if !Equal(pb, test.out) {
|
||||
t.Errorf("Test %d: Incorrect populated \nHave: %v\nWant: %v",
|
||||
i, pb, test.out)
|
||||
}
|
||||
@ -545,7 +578,7 @@ func TestUnmarshalText(t *testing.T) {
|
||||
} 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) {
|
||||
} else if _, ok := err.(*RequiredNotSetError); ok && test.out != nil && !Equal(pb, test.out) {
|
||||
t.Errorf("Test %d: Incorrect populated \nHave: %v\nWant: %v",
|
||||
i, pb, test.out)
|
||||
}
|
||||
|
54
vendor/github.com/golang/protobuf/proto/text_test.go
generated
vendored
54
vendor/github.com/golang/protobuf/proto/text_test.go
generated
vendored
@ -37,12 +37,14 @@ import (
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
|
||||
proto3pb "github.com/golang/protobuf/proto/proto3_proto"
|
||||
pb "github.com/golang/protobuf/proto/testdata"
|
||||
pb "github.com/golang/protobuf/proto/test_proto"
|
||||
anypb "github.com/golang/protobuf/ptypes/any"
|
||||
)
|
||||
|
||||
// textMessage implements the methods that allow it to marshal and unmarshal
|
||||
@ -151,12 +153,12 @@ SomeGroup {
|
||||
}
|
||||
/* 2 unknown bytes */
|
||||
13: 4
|
||||
[testdata.Ext.more]: <
|
||||
[test_proto.Ext.more]: <
|
||||
data: "Big gobs for big rats"
|
||||
>
|
||||
[testdata.greeting]: "adg"
|
||||
[testdata.greeting]: "easy"
|
||||
[testdata.greeting]: "cow"
|
||||
[test_proto.greeting]: "adg"
|
||||
[test_proto.greeting]: "easy"
|
||||
[test_proto.greeting]: "cow"
|
||||
/* 13 unknown bytes */
|
||||
201: "\t3G skiing"
|
||||
/* 3 unknown bytes */
|
||||
@ -472,3 +474,45 @@ func TestProto3Text(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRacyMarshal(t *testing.T) {
|
||||
// This test should be run with the race detector.
|
||||
|
||||
any := &pb.MyMessage{Count: proto.Int32(47), Name: proto.String("David")}
|
||||
proto.SetExtension(any, pb.E_Ext_Text, proto.String("bar"))
|
||||
b, err := proto.Marshal(any)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
m := &proto3pb.Message{
|
||||
Name: "David",
|
||||
ResultCount: 47,
|
||||
Anything: &anypb.Any{TypeUrl: "type.googleapis.com/" + proto.MessageName(any), Value: b},
|
||||
}
|
||||
|
||||
wantText := proto.MarshalTextString(m)
|
||||
wantBytes, err := proto.Marshal(m)
|
||||
if err != nil {
|
||||
t.Fatalf("proto.Marshal error: %v", err)
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
defer wg.Wait()
|
||||
wg.Add(20)
|
||||
for i := 0; i < 10; i++ {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
got := proto.MarshalTextString(m)
|
||||
if got != wantText {
|
||||
t.Errorf("proto.MarshalTextString = %q, want %q", got, wantText)
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
got, err := proto.Marshal(m)
|
||||
if !bytes.Equal(got, wantBytes) || err != nil {
|
||||
t.Errorf("proto.Marshal = (%x, %v), want (%x, nil)", got, err, wantBytes)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
33
vendor/github.com/golang/protobuf/protoc-gen-go/Makefile
generated
vendored
33
vendor/github.com/golang/protobuf/protoc-gen-go/Makefile
generated
vendored
@ -1,33 +0,0 @@
|
||||
# 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
|
36
vendor/github.com/golang/protobuf/protoc-gen-go/descriptor/Makefile
generated
vendored
36
vendor/github.com/golang/protobuf/protoc-gen-go/descriptor/Makefile
generated
vendored
@ -1,36 +0,0 @@
|
||||
# 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 descriptor.proto is in https://github.com/google/protobuf/
|
||||
# at src/google/protobuf/descriptor.proto
|
||||
regenerate:
|
||||
@echo WARNING! THIS RULE IS PROBABLY NOT RIGHT FOR YOUR INSTALLATION
|
||||
protoc --go_out=../../../../.. -I$(HOME)/src/protobuf/include $(HOME)/src/protobuf/include/google/protobuf/descriptor.proto
|
1421
vendor/github.com/golang/protobuf/protoc-gen-go/descriptor/descriptor.pb.go
generated
vendored
1421
vendor/github.com/golang/protobuf/protoc-gen-go/descriptor/descriptor.pb.go
generated
vendored
File diff suppressed because it is too large
Load Diff
872
vendor/github.com/golang/protobuf/protoc-gen-go/descriptor/descriptor.proto
generated
vendored
Normal file
872
vendor/github.com/golang/protobuf/protoc-gen-go/descriptor/descriptor.proto
generated
vendored
Normal file
@ -0,0 +1,872 @@
|
||||
// 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 = "github.com/golang/protobuf/protoc-gen-go/descriptor;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 the documentation for the "Options" section above.
|
||||
repeated UninterpretedOption uninterpreted_option = 999;
|
||||
|
||||
// Clients can define custom options in extensions of this message.
|
||||
// See the documentation for the "Options" section 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<KeyType, ValueType> 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;
|
||||
}
|
||||
}
|
40
vendor/github.com/golang/protobuf/protoc-gen-go/generator/Makefile
generated
vendored
40
vendor/github.com/golang/protobuf/protoc-gen-go/generator/Makefile
generated
vendored
@ -1,40 +0,0 @@
|
||||
# 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.
|
||||
|
||||
include $(GOROOT)/src/Make.inc
|
||||
|
||||
TARG=github.com/golang/protobuf/compiler/generator
|
||||
GOFILES=\
|
||||
generator.go\
|
||||
|
||||
DEPS=../descriptor ../plugin ../../proto
|
||||
|
||||
include $(GOROOT)/src/Make.pkg
|
2675
vendor/github.com/golang/protobuf/protoc-gen-go/generator/generator.go
generated
vendored
2675
vendor/github.com/golang/protobuf/protoc-gen-go/generator/generator.go
generated
vendored
File diff suppressed because it is too large
Load Diff
117
vendor/github.com/golang/protobuf/protoc-gen-go/generator/internal/remap/remap.go
generated
vendored
Normal file
117
vendor/github.com/golang/protobuf/protoc-gen-go/generator/internal/remap/remap.go
generated
vendored
Normal file
@ -0,0 +1,117 @@
|
||||
// Go support for Protocol Buffers - Google's data interchange format
|
||||
//
|
||||
// Copyright 2017 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 remap handles tracking the locations of Go tokens in a source text
|
||||
across a rewrite by the Go formatter.
|
||||
*/
|
||||
package remap
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/scanner"
|
||||
"go/token"
|
||||
)
|
||||
|
||||
// A Location represents a span of byte offsets in the source text.
|
||||
type Location struct {
|
||||
Pos, End int // End is exclusive
|
||||
}
|
||||
|
||||
// A Map represents a mapping between token locations in an input source text
|
||||
// and locations in the correspnding output text.
|
||||
type Map map[Location]Location
|
||||
|
||||
// Find reports whether the specified span is recorded by m, and if so returns
|
||||
// the new location it was mapped to. If the input span was not found, the
|
||||
// returned location is the same as the input.
|
||||
func (m Map) Find(pos, end int) (Location, bool) {
|
||||
key := Location{
|
||||
Pos: pos,
|
||||
End: end,
|
||||
}
|
||||
if loc, ok := m[key]; ok {
|
||||
return loc, true
|
||||
}
|
||||
return key, false
|
||||
}
|
||||
|
||||
func (m Map) add(opos, oend, npos, nend int) {
|
||||
m[Location{Pos: opos, End: oend}] = Location{Pos: npos, End: nend}
|
||||
}
|
||||
|
||||
// Compute constructs a location mapping from input to output. An error is
|
||||
// reported if any of the tokens of output cannot be mapped.
|
||||
func Compute(input, output []byte) (Map, error) {
|
||||
itok := tokenize(input)
|
||||
otok := tokenize(output)
|
||||
if len(itok) != len(otok) {
|
||||
return nil, fmt.Errorf("wrong number of tokens, %d ≠ %d", len(itok), len(otok))
|
||||
}
|
||||
m := make(Map)
|
||||
for i, ti := range itok {
|
||||
to := otok[i]
|
||||
if ti.Token != to.Token {
|
||||
return nil, fmt.Errorf("token %d type mismatch: %s ≠ %s", i+1, ti, to)
|
||||
}
|
||||
m.add(ti.pos, ti.end, to.pos, to.end)
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// tokinfo records the span and type of a source token.
|
||||
type tokinfo struct {
|
||||
pos, end int
|
||||
token.Token
|
||||
}
|
||||
|
||||
func tokenize(src []byte) []tokinfo {
|
||||
fs := token.NewFileSet()
|
||||
var s scanner.Scanner
|
||||
s.Init(fs.AddFile("src", fs.Base(), len(src)), src, nil, scanner.ScanComments)
|
||||
var info []tokinfo
|
||||
for {
|
||||
pos, next, lit := s.Scan()
|
||||
switch next {
|
||||
case token.SEMICOLON:
|
||||
continue
|
||||
}
|
||||
info = append(info, tokinfo{
|
||||
pos: int(pos - 1),
|
||||
end: int(pos + token.Pos(len(lit)) - 1),
|
||||
Token: next,
|
||||
})
|
||||
if next == token.EOF {
|
||||
break
|
||||
}
|
||||
}
|
||||
return info
|
||||
}
|
82
vendor/github.com/golang/protobuf/protoc-gen-go/generator/internal/remap/remap_test.go
generated
vendored
Normal file
82
vendor/github.com/golang/protobuf/protoc-gen-go/generator/internal/remap/remap_test.go
generated
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
// Go support for Protocol Buffers - Google's data interchange format
|
||||
//
|
||||
// Copyright 2017 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 remap
|
||||
|
||||
import (
|
||||
"go/format"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestErrors(t *testing.T) {
|
||||
tests := []struct {
|
||||
in, out string
|
||||
}{
|
||||
{"", "x"},
|
||||
{"x", ""},
|
||||
{"var x int = 5\n", "var x = 5\n"},
|
||||
{"these are \"one\" thing", "those are 'another' thing"},
|
||||
}
|
||||
for _, test := range tests {
|
||||
m, err := Compute([]byte(test.in), []byte(test.out))
|
||||
if err != nil {
|
||||
t.Logf("Got expected error: %v", err)
|
||||
continue
|
||||
}
|
||||
t.Errorf("Compute(%q, %q): got %+v, wanted error", test.in, test.out, m)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMatching(t *testing.T) {
|
||||
// The input is a source text that will be rearranged by the formatter.
|
||||
const input = `package foo
|
||||
var s int
|
||||
func main(){}
|
||||
`
|
||||
|
||||
output, err := format.Source([]byte(input))
|
||||
if err != nil {
|
||||
t.Fatalf("Formatting failed: %v", err)
|
||||
}
|
||||
m, err := Compute([]byte(input), output)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
|
||||
// Verify that the mapped locations have the same text.
|
||||
for key, val := range m {
|
||||
want := input[key.Pos:key.End]
|
||||
got := string(output[val.Pos:val.End])
|
||||
if got != want {
|
||||
t.Errorf("Token at %d:%d: got %q, want %q", key.Pos, key.End, got, want)
|
||||
}
|
||||
}
|
||||
}
|
56
vendor/github.com/golang/protobuf/protoc-gen-go/generator/name_test.go
generated
vendored
56
vendor/github.com/golang/protobuf/protoc-gen-go/generator/name_test.go
generated
vendored
@ -59,14 +59,16 @@ func TestCamelCase(t *testing.T) {
|
||||
|
||||
func TestGoPackageOption(t *testing.T) {
|
||||
tests := []struct {
|
||||
in string
|
||||
impPath, pkg string
|
||||
ok bool
|
||||
in string
|
||||
impPath GoImportPath
|
||||
pkg GoPackageName
|
||||
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},
|
||||
{"github.com/golang/string", "github.com/golang/string", "string", true},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
d := &FileDescriptor{
|
||||
@ -83,3 +85,51 @@ func TestGoPackageOption(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPackageNames(t *testing.T) {
|
||||
g := New()
|
||||
g.packageNames = make(map[GoImportPath]GoPackageName)
|
||||
g.usedPackageNames = make(map[GoPackageName]bool)
|
||||
for _, test := range []struct {
|
||||
importPath GoImportPath
|
||||
want GoPackageName
|
||||
}{
|
||||
{"github.com/golang/foo", "foo"},
|
||||
{"github.com/golang/second/package/named/foo", "foo1"},
|
||||
{"github.com/golang/third/package/named/foo", "foo2"},
|
||||
{"github.com/golang/conflicts/with/predeclared/ident/string", "string1"},
|
||||
} {
|
||||
if got := g.GoPackageName(test.importPath); got != test.want {
|
||||
t.Errorf("GoPackageName(%v) = %v, want %v", test.importPath, got, test.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
363
vendor/github.com/golang/protobuf/protoc-gen-go/golden_test.go
generated
vendored
Normal file
363
vendor/github.com/golang/protobuf/protoc-gen-go/golden_test.go
generated
vendored
Normal file
@ -0,0 +1,363 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"flag"
|
||||
"go/build"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Set --regenerate to regenerate the golden files.
|
||||
var regenerate = flag.Bool("regenerate", false, "regenerate golden files")
|
||||
|
||||
// When the environment variable RUN_AS_PROTOC_GEN_GO is set, we skip running
|
||||
// tests and instead act as protoc-gen-go. This allows the test binary to
|
||||
// pass itself to protoc.
|
||||
func init() {
|
||||
if os.Getenv("RUN_AS_PROTOC_GEN_GO") != "" {
|
||||
main()
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGolden(t *testing.T) {
|
||||
workdir, err := ioutil.TempDir("", "proto-test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(workdir)
|
||||
|
||||
// Find all the proto files we need to compile. We assume that each directory
|
||||
// contains the files for a single package.
|
||||
supportTypeAliases := hasReleaseTag("go1.9")
|
||||
packages := map[string][]string{}
|
||||
err = filepath.Walk("testdata", func(path string, info os.FileInfo, err error) error {
|
||||
if filepath.Base(path) == "import_public" && !supportTypeAliases {
|
||||
// Public imports require type alias support.
|
||||
return filepath.SkipDir
|
||||
}
|
||||
if !strings.HasSuffix(path, ".proto") {
|
||||
return nil
|
||||
}
|
||||
dir := filepath.Dir(path)
|
||||
packages[dir] = append(packages[dir], path)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Compile each package, using this binary as protoc-gen-go.
|
||||
for _, sources := range packages {
|
||||
args := []string{"-Itestdata", "--go_out=plugins=grpc,paths=source_relative:" + workdir}
|
||||
args = append(args, sources...)
|
||||
protoc(t, args)
|
||||
}
|
||||
|
||||
// Compare each generated file to the golden version.
|
||||
filepath.Walk(workdir, func(genPath string, info os.FileInfo, _ error) error {
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// For each generated file, figure out the path to the corresponding
|
||||
// golden file in the testdata directory.
|
||||
relPath, err := filepath.Rel(workdir, genPath)
|
||||
if err != nil {
|
||||
t.Errorf("filepath.Rel(%q, %q): %v", workdir, genPath, err)
|
||||
return nil
|
||||
}
|
||||
if filepath.SplitList(relPath)[0] == ".." {
|
||||
t.Errorf("generated file %q is not relative to %q", genPath, workdir)
|
||||
}
|
||||
goldenPath := filepath.Join("testdata", relPath)
|
||||
|
||||
got, err := ioutil.ReadFile(genPath)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return nil
|
||||
}
|
||||
if *regenerate {
|
||||
// If --regenerate set, just rewrite the golden files.
|
||||
err := ioutil.WriteFile(goldenPath, got, 0666)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
want, err := ioutil.ReadFile(goldenPath)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
want = fdescRE.ReplaceAll(want, nil)
|
||||
got = fdescRE.ReplaceAll(got, nil)
|
||||
if bytes.Equal(got, want) {
|
||||
return nil
|
||||
}
|
||||
|
||||
cmd := exec.Command("diff", "-u", goldenPath, genPath)
|
||||
out, _ := cmd.CombinedOutput()
|
||||
t.Errorf("golden file differs: %v\n%v", relPath, string(out))
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
var fdescRE = regexp.MustCompile(`(?ms)^var fileDescriptor.*}`)
|
||||
|
||||
// Source files used by TestParameters.
|
||||
const (
|
||||
aProto = `
|
||||
syntax = "proto3";
|
||||
package test.alpha;
|
||||
option go_package = "package/alpha";
|
||||
import "beta/b.proto";
|
||||
message M { test.beta.M field = 1; }`
|
||||
|
||||
bProto = `
|
||||
syntax = "proto3";
|
||||
package test.beta;
|
||||
// no go_package option
|
||||
message M {}`
|
||||
)
|
||||
|
||||
func TestParameters(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
parameters string
|
||||
wantFiles map[string]bool
|
||||
wantImportsA map[string]bool
|
||||
wantPackageA string
|
||||
wantPackageB string
|
||||
}{{
|
||||
parameters: "",
|
||||
wantFiles: map[string]bool{
|
||||
"package/alpha/a.pb.go": true,
|
||||
"beta/b.pb.go": true,
|
||||
},
|
||||
wantPackageA: "alpha",
|
||||
wantPackageB: "test_beta",
|
||||
wantImportsA: map[string]bool{
|
||||
"github.com/golang/protobuf/proto": true,
|
||||
"beta": true,
|
||||
},
|
||||
}, {
|
||||
parameters: "import_prefix=prefix",
|
||||
wantFiles: map[string]bool{
|
||||
"package/alpha/a.pb.go": true,
|
||||
"beta/b.pb.go": true,
|
||||
},
|
||||
wantPackageA: "alpha",
|
||||
wantPackageB: "test_beta",
|
||||
wantImportsA: map[string]bool{
|
||||
// This really doesn't seem like useful behavior.
|
||||
"prefixgithub.com/golang/protobuf/proto": true,
|
||||
"prefixbeta": true,
|
||||
},
|
||||
}, {
|
||||
// import_path only affects the 'package' line.
|
||||
parameters: "import_path=import/path/of/pkg",
|
||||
wantPackageA: "alpha",
|
||||
wantPackageB: "pkg",
|
||||
wantFiles: map[string]bool{
|
||||
"package/alpha/a.pb.go": true,
|
||||
"beta/b.pb.go": true,
|
||||
},
|
||||
}, {
|
||||
parameters: "Mbeta/b.proto=package/gamma",
|
||||
wantFiles: map[string]bool{
|
||||
"package/alpha/a.pb.go": true,
|
||||
"beta/b.pb.go": true,
|
||||
},
|
||||
wantPackageA: "alpha",
|
||||
wantPackageB: "test_beta",
|
||||
wantImportsA: map[string]bool{
|
||||
"github.com/golang/protobuf/proto": true,
|
||||
// Rewritten by the M parameter.
|
||||
"package/gamma": true,
|
||||
},
|
||||
}, {
|
||||
parameters: "import_prefix=prefix,Mbeta/b.proto=package/gamma",
|
||||
wantFiles: map[string]bool{
|
||||
"package/alpha/a.pb.go": true,
|
||||
"beta/b.pb.go": true,
|
||||
},
|
||||
wantPackageA: "alpha",
|
||||
wantPackageB: "test_beta",
|
||||
wantImportsA: map[string]bool{
|
||||
// import_prefix applies after M.
|
||||
"prefixpackage/gamma": true,
|
||||
},
|
||||
}, {
|
||||
parameters: "paths=source_relative",
|
||||
wantFiles: map[string]bool{
|
||||
"alpha/a.pb.go": true,
|
||||
"beta/b.pb.go": true,
|
||||
},
|
||||
wantPackageA: "alpha",
|
||||
wantPackageB: "test_beta",
|
||||
}, {
|
||||
parameters: "paths=source_relative,import_prefix=prefix",
|
||||
wantFiles: map[string]bool{
|
||||
// import_prefix doesn't affect filenames.
|
||||
"alpha/a.pb.go": true,
|
||||
"beta/b.pb.go": true,
|
||||
},
|
||||
wantPackageA: "alpha",
|
||||
wantPackageB: "test_beta",
|
||||
}} {
|
||||
name := test.parameters
|
||||
if name == "" {
|
||||
name = "defaults"
|
||||
}
|
||||
// TODO: Switch to t.Run when we no longer support Go 1.6.
|
||||
t.Logf("TEST: %v", name)
|
||||
workdir, err := ioutil.TempDir("", "proto-test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(workdir)
|
||||
|
||||
for _, dir := range []string{"alpha", "beta", "out"} {
|
||||
if err := os.MkdirAll(filepath.Join(workdir, dir), 0777); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(filepath.Join(workdir, "alpha", "a.proto"), []byte(aProto), 0666); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(filepath.Join(workdir, "beta", "b.proto"), []byte(bProto), 0666); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
protoc(t, []string{
|
||||
"-I" + workdir,
|
||||
"--go_out=" + test.parameters + ":" + filepath.Join(workdir, "out"),
|
||||
filepath.Join(workdir, "alpha", "a.proto"),
|
||||
})
|
||||
protoc(t, []string{
|
||||
"-I" + workdir,
|
||||
"--go_out=" + test.parameters + ":" + filepath.Join(workdir, "out"),
|
||||
filepath.Join(workdir, "beta", "b.proto"),
|
||||
})
|
||||
|
||||
contents := make(map[string]string)
|
||||
gotFiles := make(map[string]bool)
|
||||
outdir := filepath.Join(workdir, "out")
|
||||
filepath.Walk(outdir, func(p string, info os.FileInfo, _ error) error {
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
base := filepath.Base(p)
|
||||
if base == "a.pb.go" || base == "b.pb.go" {
|
||||
b, err := ioutil.ReadFile(p)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
contents[base] = string(b)
|
||||
}
|
||||
relPath, _ := filepath.Rel(outdir, p)
|
||||
gotFiles[relPath] = true
|
||||
return nil
|
||||
})
|
||||
for got := range gotFiles {
|
||||
if runtime.GOOS == "windows" {
|
||||
got = filepath.ToSlash(got)
|
||||
}
|
||||
if !test.wantFiles[got] {
|
||||
t.Errorf("unexpected output file: %v", got)
|
||||
}
|
||||
}
|
||||
for want := range test.wantFiles {
|
||||
if runtime.GOOS == "windows" {
|
||||
want = filepath.FromSlash(want)
|
||||
}
|
||||
if !gotFiles[want] {
|
||||
t.Errorf("missing output file: %v", want)
|
||||
}
|
||||
}
|
||||
gotPackageA, gotImports, err := parseFile(contents["a.pb.go"])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
gotPackageB, _, err := parseFile(contents["b.pb.go"])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got, want := gotPackageA, test.wantPackageA; want != got {
|
||||
t.Errorf("output file a.pb.go is package %q, want %q", got, want)
|
||||
}
|
||||
if got, want := gotPackageB, test.wantPackageB; want != got {
|
||||
t.Errorf("output file b.pb.go is package %q, want %q", got, want)
|
||||
}
|
||||
missingImport := false
|
||||
WantImport:
|
||||
for want := range test.wantImportsA {
|
||||
for _, imp := range gotImports {
|
||||
if `"`+want+`"` == imp {
|
||||
continue WantImport
|
||||
}
|
||||
}
|
||||
t.Errorf("output file a.pb.go does not contain expected import %q", want)
|
||||
missingImport = true
|
||||
}
|
||||
if missingImport {
|
||||
t.Error("got imports:")
|
||||
for _, imp := range gotImports {
|
||||
t.Errorf(" %v", imp)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// parseFile returns a file's package name and a list of all packages it imports.
|
||||
func parseFile(source string) (packageName string, imports []string, err error) {
|
||||
fset := token.NewFileSet()
|
||||
f, err := parser.ParseFile(fset, "<source>", source, parser.ImportsOnly)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
for _, imp := range f.Imports {
|
||||
imports = append(imports, imp.Path.Value)
|
||||
}
|
||||
return f.Name.Name, imports, nil
|
||||
}
|
||||
|
||||
func protoc(t *testing.T, args []string) {
|
||||
cmd := exec.Command("protoc", "--plugin=protoc-gen-go="+os.Args[0])
|
||||
cmd.Args = append(cmd.Args, args...)
|
||||
// We set the RUN_AS_PROTOC_GEN_GO environment variable to indicate that
|
||||
// the subprocess should act as a proto compiler rather than a test.
|
||||
cmd.Env = append(os.Environ(), "RUN_AS_PROTOC_GEN_GO=1")
|
||||
out, err := cmd.CombinedOutput()
|
||||
if len(out) > 0 || err != nil {
|
||||
t.Log("RUNNING: ", strings.Join(cmd.Args, " "))
|
||||
}
|
||||
if len(out) > 0 {
|
||||
t.Log(string(out))
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("protoc: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func hasReleaseTag(want string) bool {
|
||||
for _, tag := range build.Default.ReleaseTags {
|
||||
if tag == want {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
53
vendor/github.com/golang/protobuf/protoc-gen-go/grpc/grpc.go
generated
vendored
53
vendor/github.com/golang/protobuf/protoc-gen-go/grpc/grpc.go
generated
vendored
@ -36,7 +36,6 @@ package grpc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -53,7 +52,7 @@ const generatedCodeVersion = 4
|
||||
// Paths for packages used by code generated in this file,
|
||||
// relative to the import_prefix of the generator.Generator.
|
||||
const (
|
||||
contextPkgPath = "golang.org/x/net/context"
|
||||
contextPkgPath = "context"
|
||||
grpcPkgPath = "google.golang.org/grpc"
|
||||
)
|
||||
|
||||
@ -83,8 +82,6 @@ var (
|
||||
// Init initializes the plugin.
|
||||
func (g *grpc) Init(gen *generator.Generator) {
|
||||
g.gen = gen
|
||||
contextPkg = generator.RegisterUniquePackageName("context", nil)
|
||||
grpcPkg = generator.RegisterUniquePackageName("grpc", nil)
|
||||
}
|
||||
|
||||
// Given a type name defined in a .proto, return its object.
|
||||
@ -108,6 +105,9 @@ func (g *grpc) Generate(file *generator.FileDescriptor) {
|
||||
return
|
||||
}
|
||||
|
||||
contextPkg = string(g.gen.AddImport(contextPkgPath))
|
||||
grpcPkg = string(g.gen.AddImport(grpcPkgPath))
|
||||
|
||||
g.P("// Reference imports to suppress errors if they are not otherwise used.")
|
||||
g.P("var _ ", contextPkg, ".Context")
|
||||
g.P("var _ ", grpcPkg, ".ClientConn")
|
||||
@ -126,23 +126,19 @@ func (g *grpc) Generate(file *generator.FileDescriptor) {
|
||||
|
||||
// GenerateImports generates the import declaration for this file.
|
||||
func (g *grpc) GenerateImports(file *generator.FileDescriptor) {
|
||||
if len(file.FileDescriptorProto.Service) == 0 {
|
||||
return
|
||||
}
|
||||
g.P("import (")
|
||||
g.P(contextPkg, " ", strconv.Quote(path.Join(g.gen.ImportPrefix, contextPkgPath)))
|
||||
g.P(grpcPkg, " ", strconv.Quote(path.Join(g.gen.ImportPrefix, grpcPkgPath)))
|
||||
g.P(")")
|
||||
g.P()
|
||||
}
|
||||
|
||||
// reservedClientName records whether a client name is reserved on the client side.
|
||||
var reservedClientName = map[string]bool{
|
||||
// TODO: do we need any in gRPC?
|
||||
// TODO: do we need any in gRPC?
|
||||
}
|
||||
|
||||
func unexport(s string) string { return strings.ToLower(s[:1]) + s[1:] }
|
||||
|
||||
// deprecationComment is the standard comment added to deprecated
|
||||
// messages, fields, enums, and enum values.
|
||||
var deprecationComment = "// Deprecated: Do not use."
|
||||
|
||||
// generateService generates all the code for the named service.
|
||||
func (g *grpc) generateService(file *generator.FileDescriptor, service *pb.ServiceDescriptorProto, index int) {
|
||||
path := fmt.Sprintf("6,%d", index) // 6 means service.
|
||||
@ -153,12 +149,18 @@ func (g *grpc) generateService(file *generator.FileDescriptor, service *pb.Servi
|
||||
fullServName = pkg + "." + fullServName
|
||||
}
|
||||
servName := generator.CamelCase(origServName)
|
||||
deprecated := service.GetOptions().GetDeprecated()
|
||||
|
||||
g.P()
|
||||
g.P("// Client API for ", servName, " service")
|
||||
g.P()
|
||||
g.P(fmt.Sprintf(`// %sClient is the client API for %s service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.`, servName, servName))
|
||||
|
||||
// Client interface.
|
||||
if deprecated {
|
||||
g.P("//")
|
||||
g.P(deprecationComment)
|
||||
}
|
||||
g.P("type ", servName, "Client interface {")
|
||||
for i, method := range service.Method {
|
||||
g.gen.PrintComments(fmt.Sprintf("%s,2,%d", path, i)) // 2 means method in a service.
|
||||
@ -174,6 +176,9 @@ func (g *grpc) generateService(file *generator.FileDescriptor, service *pb.Servi
|
||||
g.P()
|
||||
|
||||
// NewClient factory.
|
||||
if deprecated {
|
||||
g.P(deprecationComment)
|
||||
}
|
||||
g.P("func New", servName, "Client (cc *", grpcPkg, ".ClientConn) ", servName, "Client {")
|
||||
g.P("return &", unexport(servName), "Client{cc}")
|
||||
g.P("}")
|
||||
@ -196,11 +201,13 @@ func (g *grpc) generateService(file *generator.FileDescriptor, service *pb.Servi
|
||||
g.generateClientMethod(servName, fullServName, serviceDescVar, method, descExpr)
|
||||
}
|
||||
|
||||
g.P("// Server API for ", servName, " service")
|
||||
g.P()
|
||||
|
||||
// Server interface.
|
||||
serverType := servName + "Server"
|
||||
g.P("// ", serverType, " is the server API for ", servName, " service.")
|
||||
if deprecated {
|
||||
g.P("//")
|
||||
g.P(deprecationComment)
|
||||
}
|
||||
g.P("type ", serverType, " interface {")
|
||||
for i, method := range service.Method {
|
||||
g.gen.PrintComments(fmt.Sprintf("%s,2,%d", path, i)) // 2 means method in a service.
|
||||
@ -210,6 +217,9 @@ func (g *grpc) generateService(file *generator.FileDescriptor, service *pb.Servi
|
||||
g.P()
|
||||
|
||||
// Server registration.
|
||||
if deprecated {
|
||||
g.P(deprecationComment)
|
||||
}
|
||||
g.P("func Register", servName, "Server(s *", grpcPkg, ".Server, srv ", serverType, ") {")
|
||||
g.P("s.RegisterService(&", serviceDescVar, `, srv)`)
|
||||
g.P("}")
|
||||
@ -283,11 +293,14 @@ func (g *grpc) generateClientMethod(servName, fullServName, serviceDescVar strin
|
||||
inType := g.typeName(method.GetInputType())
|
||||
outType := g.typeName(method.GetOutputType())
|
||||
|
||||
if method.GetOptions().GetDeprecated() {
|
||||
g.P(deprecationComment)
|
||||
}
|
||||
g.P("func (c *", unexport(servName), "Client) ", g.generateClientSignature(servName, method), "{")
|
||||
if !method.GetServerStreaming() && !method.GetClientStreaming() {
|
||||
g.P("out := new(", outType, ")")
|
||||
// TODO: Pass descExpr to Invoke.
|
||||
g.P("err := ", grpcPkg, `.Invoke(ctx, "`, sname, `", in, out, c.cc, opts...)`)
|
||||
g.P(`err := c.cc.Invoke(ctx, "`, sname, `", in, out, opts...)`)
|
||||
g.P("if err != nil { return nil, err }")
|
||||
g.P("return out, nil")
|
||||
g.P("}")
|
||||
@ -295,7 +308,7 @@ func (g *grpc) generateClientMethod(servName, fullServName, serviceDescVar strin
|
||||
return
|
||||
}
|
||||
streamType := unexport(servName) + methName + "Client"
|
||||
g.P("stream, err := ", grpcPkg, ".NewClientStream(ctx, ", descExpr, `, c.cc, "`, sname, `", opts...)`)
|
||||
g.P("stream, err := c.cc.NewStream(ctx, ", descExpr, `, "`, sname, `", opts...)`)
|
||||
g.P("if err != nil { return nil, err }")
|
||||
g.P("x := &", streamType, "{stream}")
|
||||
if !method.GetClientStreaming() {
|
||||
|
44
vendor/github.com/golang/protobuf/protoc-gen-go/plugin/Makefile
generated
vendored
44
vendor/github.com/golang/protobuf/protoc-gen-go/plugin/Makefile
generated
vendored
@ -1,44 +0,0 @@
|
||||
# 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:
|
||||
@echo WARNING! THIS RULE IS PROBABLY NOT RIGHT FOR YOUR INSTALLATION
|
||||
protoc --go_out=Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor:../../../../.. \
|
||||
-I$(HOME)/src/protobuf/include $(HOME)/src/protobuf/include/google/protobuf/compiler/plugin.proto
|
||||
|
||||
restore:
|
||||
cp plugin.pb.golden plugin.pb.go
|
||||
|
||||
preserve:
|
||||
cp plugin.pb.go plugin.pb.golden
|
94
vendor/github.com/golang/protobuf/protoc-gen-go/plugin/plugin.pb.go
generated
vendored
94
vendor/github.com/golang/protobuf/protoc-gen-go/plugin/plugin.pb.go
generated
vendored
@ -37,14 +37,33 @@ type Version struct {
|
||||
Patch *int32 `protobuf:"varint,3,opt,name=patch" json:"patch,omitempty"`
|
||||
// A suffix for alpha, beta or rc release, e.g., "alpha-1", "rc2". It should
|
||||
// be empty for mainline stable releases.
|
||||
Suffix *string `protobuf:"bytes,4,opt,name=suffix" json:"suffix,omitempty"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
Suffix *string `protobuf:"bytes,4,opt,name=suffix" json:"suffix,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Version) Reset() { *m = Version{} }
|
||||
func (m *Version) String() string { return proto.CompactTextString(m) }
|
||||
func (*Version) ProtoMessage() {}
|
||||
func (*Version) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
||||
func (m *Version) Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_Version.Unmarshal(m, b)
|
||||
}
|
||||
func (m *Version) Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_Version.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (dst *Version) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Version.Merge(dst, src)
|
||||
}
|
||||
func (m *Version) XXX_Size() int {
|
||||
return xxx_messageInfo_Version.Size(m)
|
||||
}
|
||||
func (m *Version) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Version.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_Version proto.InternalMessageInfo
|
||||
|
||||
func (m *Version) GetMajor() int32 {
|
||||
if m != nil && m.Major != nil {
|
||||
@ -98,14 +117,33 @@ type CodeGeneratorRequest struct {
|
||||
// fully qualified.
|
||||
ProtoFile []*google_protobuf.FileDescriptorProto `protobuf:"bytes,15,rep,name=proto_file,json=protoFile" json:"proto_file,omitempty"`
|
||||
// The version number of protocol compiler.
|
||||
CompilerVersion *Version `protobuf:"bytes,3,opt,name=compiler_version,json=compilerVersion" json:"compiler_version,omitempty"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
CompilerVersion *Version `protobuf:"bytes,3,opt,name=compiler_version,json=compilerVersion" json:"compiler_version,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *CodeGeneratorRequest) Reset() { *m = CodeGeneratorRequest{} }
|
||||
func (m *CodeGeneratorRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*CodeGeneratorRequest) ProtoMessage() {}
|
||||
func (*CodeGeneratorRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
|
||||
func (m *CodeGeneratorRequest) Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_CodeGeneratorRequest.Unmarshal(m, b)
|
||||
}
|
||||
func (m *CodeGeneratorRequest) Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_CodeGeneratorRequest.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (dst *CodeGeneratorRequest) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_CodeGeneratorRequest.Merge(dst, src)
|
||||
}
|
||||
func (m *CodeGeneratorRequest) XXX_Size() int {
|
||||
return xxx_messageInfo_CodeGeneratorRequest.Size(m)
|
||||
}
|
||||
func (m *CodeGeneratorRequest) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_CodeGeneratorRequest.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_CodeGeneratorRequest proto.InternalMessageInfo
|
||||
|
||||
func (m *CodeGeneratorRequest) GetFileToGenerate() []string {
|
||||
if m != nil {
|
||||
@ -145,15 +183,34 @@ type CodeGeneratorResponse struct {
|
||||
// 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.
|
||||
Error *string `protobuf:"bytes,1,opt,name=error" json:"error,omitempty"`
|
||||
File []*CodeGeneratorResponse_File `protobuf:"bytes,15,rep,name=file" json:"file,omitempty"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
Error *string `protobuf:"bytes,1,opt,name=error" json:"error,omitempty"`
|
||||
File []*CodeGeneratorResponse_File `protobuf:"bytes,15,rep,name=file" json:"file,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *CodeGeneratorResponse) Reset() { *m = CodeGeneratorResponse{} }
|
||||
func (m *CodeGeneratorResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*CodeGeneratorResponse) ProtoMessage() {}
|
||||
func (*CodeGeneratorResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
|
||||
func (m *CodeGeneratorResponse) Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_CodeGeneratorResponse.Unmarshal(m, b)
|
||||
}
|
||||
func (m *CodeGeneratorResponse) Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_CodeGeneratorResponse.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (dst *CodeGeneratorResponse) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_CodeGeneratorResponse.Merge(dst, src)
|
||||
}
|
||||
func (m *CodeGeneratorResponse) XXX_Size() int {
|
||||
return xxx_messageInfo_CodeGeneratorResponse.Size(m)
|
||||
}
|
||||
func (m *CodeGeneratorResponse) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_CodeGeneratorResponse.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_CodeGeneratorResponse proto.InternalMessageInfo
|
||||
|
||||
func (m *CodeGeneratorResponse) GetError() string {
|
||||
if m != nil && m.Error != nil {
|
||||
@ -222,14 +279,33 @@ type CodeGeneratorResponse_File struct {
|
||||
// If |insertion_point| is present, |name| must also be present.
|
||||
InsertionPoint *string `protobuf:"bytes,2,opt,name=insertion_point,json=insertionPoint" json:"insertion_point,omitempty"`
|
||||
// The file contents.
|
||||
Content *string `protobuf:"bytes,15,opt,name=content" json:"content,omitempty"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
Content *string `protobuf:"bytes,15,opt,name=content" json:"content,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *CodeGeneratorResponse_File) Reset() { *m = CodeGeneratorResponse_File{} }
|
||||
func (m *CodeGeneratorResponse_File) String() string { return proto.CompactTextString(m) }
|
||||
func (*CodeGeneratorResponse_File) ProtoMessage() {}
|
||||
func (*CodeGeneratorResponse_File) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2, 0} }
|
||||
func (m *CodeGeneratorResponse_File) Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_CodeGeneratorResponse_File.Unmarshal(m, b)
|
||||
}
|
||||
func (m *CodeGeneratorResponse_File) Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_CodeGeneratorResponse_File.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (dst *CodeGeneratorResponse_File) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_CodeGeneratorResponse_File.Merge(dst, src)
|
||||
}
|
||||
func (m *CodeGeneratorResponse_File) XXX_Size() int {
|
||||
return xxx_messageInfo_CodeGeneratorResponse_File.Size(m)
|
||||
}
|
||||
func (m *CodeGeneratorResponse_File) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_CodeGeneratorResponse_File.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_CodeGeneratorResponse_File proto.InternalMessageInfo
|
||||
|
||||
func (m *CodeGeneratorResponse_File) GetName() string {
|
||||
if m != nil && m.Name != nil {
|
||||
|
167
vendor/github.com/golang/protobuf/protoc-gen-go/plugin/plugin.proto
generated
vendored
Normal file
167
vendor/github.com/golang/protobuf/protoc-gen-go/plugin/plugin.proto
generated
vendored
Normal file
@ -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 = "github.com/golang/protobuf/protoc-gen-go/plugin;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;
|
||||
}
|
73
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/Makefile
generated
vendored
73
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/Makefile
generated
vendored
@ -1,73 +0,0 @@
|
||||
# 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
|
||||
|
||||
include ../../Make.protobuf
|
||||
|
||||
test: golden testbuild
|
||||
|
||||
#test: golden testbuild extension_test
|
||||
# ./extension_test
|
||||
# @echo PASS
|
||||
|
||||
my_test/test.pb.go: my_test/test.proto
|
||||
protoc --go_out=Mmulti/multi1.proto=github.com/golang/protobuf/protoc-gen-go/testdata/multi:. $<
|
||||
|
||||
golden:
|
||||
make -B my_test/test.pb.go
|
||||
sed -i -e '/return.*fileDescriptor/d' my_test/test.pb.go
|
||||
sed -i -e '/^var fileDescriptor/,/^}/d' my_test/test.pb.go
|
||||
sed -i -e '/proto.RegisterFile.*fileDescriptor/d' my_test/test.pb.go
|
||||
gofmt -w my_test/test.pb.go
|
||||
diff -w my_test/test.pb.go my_test/test.pb.go.golden
|
||||
|
||||
nuke: clean
|
||||
|
||||
testbuild: regenerate
|
||||
go test
|
||||
|
||||
regenerate:
|
||||
# Invoke protoc once to generate three independent .pb.go files in the same package.
|
||||
protoc --go_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
|
316
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/deprecated/deprecated.pb.go
generated
vendored
Normal file
316
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/deprecated/deprecated.pb.go
generated
vendored
Normal file
@ -0,0 +1,316 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// deprecated/deprecated.proto is a deprecated file.
|
||||
|
||||
// package deprecated contains only deprecated messages and services.
|
||||
|
||||
package deprecated
|
||||
|
||||
import (
|
||||
context "context"
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
grpc "google.golang.org/grpc"
|
||||
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.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
// DeprecatedEnum contains deprecated values.
|
||||
type DeprecatedEnum int32 // Deprecated: Do not use.
|
||||
const (
|
||||
// DEPRECATED is the iota value of this enum.
|
||||
DeprecatedEnum_DEPRECATED DeprecatedEnum = 0 // Deprecated: Do not use.
|
||||
)
|
||||
|
||||
var DeprecatedEnum_name = map[int32]string{
|
||||
0: "DEPRECATED",
|
||||
}
|
||||
|
||||
var DeprecatedEnum_value = map[string]int32{
|
||||
"DEPRECATED": 0,
|
||||
}
|
||||
|
||||
func (x DeprecatedEnum) String() string {
|
||||
return proto.EnumName(DeprecatedEnum_name, int32(x))
|
||||
}
|
||||
|
||||
func (DeprecatedEnum) EnumDescriptor() ([]byte, []int) {
|
||||
return fileDescriptor_f64ba265cd7eae3f, []int{0}
|
||||
}
|
||||
|
||||
// DeprecatedRequest is a request to DeprecatedCall.
|
||||
//
|
||||
// Deprecated: Do not use.
|
||||
type DeprecatedRequest struct {
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *DeprecatedRequest) Reset() { *m = DeprecatedRequest{} }
|
||||
func (m *DeprecatedRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*DeprecatedRequest) ProtoMessage() {}
|
||||
func (*DeprecatedRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_f64ba265cd7eae3f, []int{0}
|
||||
}
|
||||
|
||||
func (m *DeprecatedRequest) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_DeprecatedRequest.Unmarshal(m, b)
|
||||
}
|
||||
func (m *DeprecatedRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_DeprecatedRequest.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *DeprecatedRequest) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_DeprecatedRequest.Merge(m, src)
|
||||
}
|
||||
func (m *DeprecatedRequest) XXX_Size() int {
|
||||
return xxx_messageInfo_DeprecatedRequest.Size(m)
|
||||
}
|
||||
func (m *DeprecatedRequest) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_DeprecatedRequest.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_DeprecatedRequest proto.InternalMessageInfo
|
||||
|
||||
// Deprecated: Do not use.
|
||||
type DeprecatedResponse struct {
|
||||
// DeprecatedField contains a DeprecatedEnum.
|
||||
DeprecatedField DeprecatedEnum `protobuf:"varint,1,opt,name=deprecated_field,json=deprecatedField,proto3,enum=deprecated.DeprecatedEnum" json:"deprecated_field,omitempty"` // Deprecated: Do not use.
|
||||
// DeprecatedOneof contains a deprecated field.
|
||||
//
|
||||
// Types that are valid to be assigned to DeprecatedOneof:
|
||||
// *DeprecatedResponse_DeprecatedOneofField
|
||||
DeprecatedOneof isDeprecatedResponse_DeprecatedOneof `protobuf_oneof:"deprecated_oneof"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *DeprecatedResponse) Reset() { *m = DeprecatedResponse{} }
|
||||
func (m *DeprecatedResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*DeprecatedResponse) ProtoMessage() {}
|
||||
func (*DeprecatedResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_f64ba265cd7eae3f, []int{1}
|
||||
}
|
||||
|
||||
func (m *DeprecatedResponse) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_DeprecatedResponse.Unmarshal(m, b)
|
||||
}
|
||||
func (m *DeprecatedResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_DeprecatedResponse.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *DeprecatedResponse) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_DeprecatedResponse.Merge(m, src)
|
||||
}
|
||||
func (m *DeprecatedResponse) XXX_Size() int {
|
||||
return xxx_messageInfo_DeprecatedResponse.Size(m)
|
||||
}
|
||||
func (m *DeprecatedResponse) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_DeprecatedResponse.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_DeprecatedResponse proto.InternalMessageInfo
|
||||
|
||||
// Deprecated: Do not use.
|
||||
func (m *DeprecatedResponse) GetDeprecatedField() DeprecatedEnum {
|
||||
if m != nil {
|
||||
return m.DeprecatedField
|
||||
}
|
||||
return DeprecatedEnum_DEPRECATED
|
||||
}
|
||||
|
||||
type isDeprecatedResponse_DeprecatedOneof interface {
|
||||
isDeprecatedResponse_DeprecatedOneof()
|
||||
}
|
||||
|
||||
type DeprecatedResponse_DeprecatedOneofField struct {
|
||||
DeprecatedOneofField string `protobuf:"bytes,2,opt,name=deprecated_oneof_field,json=deprecatedOneofField,proto3,oneof"`
|
||||
}
|
||||
|
||||
func (*DeprecatedResponse_DeprecatedOneofField) isDeprecatedResponse_DeprecatedOneof() {}
|
||||
|
||||
func (m *DeprecatedResponse) GetDeprecatedOneof() isDeprecatedResponse_DeprecatedOneof {
|
||||
if m != nil {
|
||||
return m.DeprecatedOneof
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Deprecated: Do not use.
|
||||
func (m *DeprecatedResponse) GetDeprecatedOneofField() string {
|
||||
if x, ok := m.GetDeprecatedOneof().(*DeprecatedResponse_DeprecatedOneofField); ok {
|
||||
return x.DeprecatedOneofField
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// XXX_OneofFuncs is for the internal use of the proto package.
|
||||
func (*DeprecatedResponse) 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 _DeprecatedResponse_OneofMarshaler, _DeprecatedResponse_OneofUnmarshaler, _DeprecatedResponse_OneofSizer, []interface{}{
|
||||
(*DeprecatedResponse_DeprecatedOneofField)(nil),
|
||||
}
|
||||
}
|
||||
|
||||
func _DeprecatedResponse_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
|
||||
m := msg.(*DeprecatedResponse)
|
||||
// deprecated_oneof
|
||||
switch x := m.DeprecatedOneof.(type) {
|
||||
case *DeprecatedResponse_DeprecatedOneofField:
|
||||
b.EncodeVarint(2<<3 | proto.WireBytes)
|
||||
b.EncodeStringBytes(x.DeprecatedOneofField)
|
||||
case nil:
|
||||
default:
|
||||
return fmt.Errorf("DeprecatedResponse.DeprecatedOneof has unexpected type %T", x)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func _DeprecatedResponse_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
|
||||
m := msg.(*DeprecatedResponse)
|
||||
switch tag {
|
||||
case 2: // deprecated_oneof.deprecated_oneof_field
|
||||
if wire != proto.WireBytes {
|
||||
return true, proto.ErrInternalBadWireType
|
||||
}
|
||||
x, err := b.DecodeStringBytes()
|
||||
m.DeprecatedOneof = &DeprecatedResponse_DeprecatedOneofField{x}
|
||||
return true, err
|
||||
default:
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
func _DeprecatedResponse_OneofSizer(msg proto.Message) (n int) {
|
||||
m := msg.(*DeprecatedResponse)
|
||||
// deprecated_oneof
|
||||
switch x := m.DeprecatedOneof.(type) {
|
||||
case *DeprecatedResponse_DeprecatedOneofField:
|
||||
n += 1 // tag and wire
|
||||
n += proto.SizeVarint(uint64(len(x.DeprecatedOneofField)))
|
||||
n += len(x.DeprecatedOneofField)
|
||||
case nil:
|
||||
default:
|
||||
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterEnum("deprecated.DeprecatedEnum", DeprecatedEnum_name, DeprecatedEnum_value)
|
||||
proto.RegisterType((*DeprecatedRequest)(nil), "deprecated.DeprecatedRequest")
|
||||
proto.RegisterType((*DeprecatedResponse)(nil), "deprecated.DeprecatedResponse")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("deprecated/deprecated.proto", fileDescriptor_f64ba265cd7eae3f) }
|
||||
|
||||
var fileDescriptor_f64ba265cd7eae3f = []byte{
|
||||
// 287 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0xcd, 0x4a, 0xf3, 0x40,
|
||||
0x14, 0x86, 0x7b, 0xe6, 0x83, 0x0f, 0x9d, 0x45, 0xad, 0x83, 0x68, 0x88, 0x28, 0x25, 0xab, 0x20,
|
||||
0x34, 0x81, 0xba, 0x2b, 0x6e, 0x9a, 0x26, 0xa2, 0x2b, 0x25, 0x76, 0xe5, 0x46, 0xf2, 0x73, 0x12,
|
||||
0x03, 0xe9, 0x4c, 0x4c, 0x26, 0x5e, 0x83, 0xf7, 0xe3, 0xc6, 0xcb, 0x93, 0x49, 0x8b, 0x33, 0x05,
|
||||
0xdd, 0x84, 0x93, 0x79, 0xdf, 0xe7, 0xfc, 0xd2, 0xf3, 0x1c, 0x9b, 0x16, 0xb3, 0x44, 0x62, 0xee,
|
||||
0xeb, 0xd0, 0x6b, 0x5a, 0x21, 0x05, 0xa3, 0xfa, 0xc5, 0x39, 0xa3, 0xc7, 0xe1, 0xcf, 0x5f, 0x8c,
|
||||
0x6f, 0x3d, 0x76, 0x72, 0x41, 0x2c, 0x70, 0x3e, 0x81, 0x32, 0x53, 0xe9, 0x1a, 0xc1, 0x3b, 0x64,
|
||||
0xf7, 0x74, 0xa2, 0xe9, 0x97, 0xa2, 0xc2, 0x3a, 0xb7, 0x60, 0x0a, 0xee, 0x78, 0x6e, 0x7b, 0x46,
|
||||
0x21, 0x4d, 0x46, 0xbc, 0xdf, 0x04, 0xc4, 0x82, 0xf8, 0x48, 0xcb, 0xb7, 0x0a, 0x63, 0x0b, 0x7a,
|
||||
0x6a, 0xa4, 0x12, 0x1c, 0x45, 0xb1, 0x4b, 0x48, 0xa6, 0xe0, 0x1e, 0x2a, 0xe8, 0x6e, 0x14, 0x9f,
|
||||
0x68, 0xcf, 0x83, 0xb2, 0x0c, 0xac, 0xea, 0x30, 0x60, 0x7b, 0xad, 0x0c, 0xfc, 0x95, 0x4b, 0xc7,
|
||||
0xfb, 0xa5, 0x19, 0xa3, 0x34, 0x8c, 0x1e, 0xe3, 0x68, 0xb5, 0x5c, 0x47, 0xe1, 0x64, 0x64, 0x93,
|
||||
0x03, 0xb0, 0x89, 0x05, 0x73, 0x6e, 0x0e, 0xfe, 0x84, 0xed, 0x7b, 0x95, 0x21, 0x5b, 0x9b, 0xf8,
|
||||
0x2a, 0xa9, 0x6b, 0x76, 0xf1, 0xfb, 0x54, 0xbb, 0x4d, 0xd9, 0x97, 0x7f, 0xc9, 0xdb, 0x75, 0x39,
|
||||
0xff, 0x3e, 0x08, 0xd8, 0xea, 0x13, 0x2c, 0x9f, 0x6f, 0xca, 0x4a, 0xbe, 0xf6, 0xa9, 0x97, 0x89,
|
||||
0x8d, 0x5f, 0x8a, 0x3a, 0xe1, 0xa5, 0x3f, 0xdc, 0x23, 0xed, 0x8b, 0x6d, 0x90, 0xcd, 0x4a, 0xe4,
|
||||
0xb3, 0x52, 0xf8, 0x12, 0x3b, 0x99, 0x27, 0x32, 0x31, 0x4e, 0xf7, 0x05, 0x90, 0xfe, 0x1f, 0x5c,
|
||||
0xd7, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x08, 0xd5, 0xa0, 0x89, 0xdd, 0x01, 0x00, 0x00,
|
||||
}
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ context.Context
|
||||
var _ grpc.ClientConn
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
const _ = grpc.SupportPackageIsVersion4
|
||||
|
||||
// DeprecatedServiceClient is the client API for DeprecatedService service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
|
||||
//
|
||||
// Deprecated: Do not use.
|
||||
type DeprecatedServiceClient interface {
|
||||
// DeprecatedCall takes a DeprecatedRequest and returns a DeprecatedResponse.
|
||||
DeprecatedCall(ctx context.Context, in *DeprecatedRequest, opts ...grpc.CallOption) (*DeprecatedResponse, error)
|
||||
}
|
||||
|
||||
type deprecatedServiceClient struct {
|
||||
cc *grpc.ClientConn
|
||||
}
|
||||
|
||||
// Deprecated: Do not use.
|
||||
func NewDeprecatedServiceClient(cc *grpc.ClientConn) DeprecatedServiceClient {
|
||||
return &deprecatedServiceClient{cc}
|
||||
}
|
||||
|
||||
// Deprecated: Do not use.
|
||||
func (c *deprecatedServiceClient) DeprecatedCall(ctx context.Context, in *DeprecatedRequest, opts ...grpc.CallOption) (*DeprecatedResponse, error) {
|
||||
out := new(DeprecatedResponse)
|
||||
err := c.cc.Invoke(ctx, "/deprecated.DeprecatedService/DeprecatedCall", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// DeprecatedServiceServer is the server API for DeprecatedService service.
|
||||
//
|
||||
// Deprecated: Do not use.
|
||||
type DeprecatedServiceServer interface {
|
||||
// DeprecatedCall takes a DeprecatedRequest and returns a DeprecatedResponse.
|
||||
DeprecatedCall(context.Context, *DeprecatedRequest) (*DeprecatedResponse, error)
|
||||
}
|
||||
|
||||
// Deprecated: Do not use.
|
||||
func RegisterDeprecatedServiceServer(s *grpc.Server, srv DeprecatedServiceServer) {
|
||||
s.RegisterService(&_DeprecatedService_serviceDesc, srv)
|
||||
}
|
||||
|
||||
func _DeprecatedService_DeprecatedCall_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(DeprecatedRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(DeprecatedServiceServer).DeprecatedCall(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/deprecated.DeprecatedService/DeprecatedCall",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(DeprecatedServiceServer).DeprecatedCall(ctx, req.(*DeprecatedRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
var _DeprecatedService_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "deprecated.DeprecatedService",
|
||||
HandlerType: (*DeprecatedServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "DeprecatedCall",
|
||||
Handler: _DeprecatedService_DeprecatedCall_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "deprecated/deprecated.proto",
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
// Go support for Protocol Buffers - Google's data interchange format
|
||||
//
|
||||
// Copyright 2012 The Go Authors. All rights reserved.
|
||||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// https://github.com/golang/protobuf
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
@ -29,58 +29,46 @@
|
||||
// (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.
|
||||
syntax = "proto3";
|
||||
|
||||
package testdata
|
||||
// package deprecated contains only deprecated messages and services.
|
||||
package deprecated;
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
option go_package = "github.com/golang/protobuf/protoc-gen-go/testdata/deprecated";
|
||||
|
||||
// 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))
|
||||
option deprecated = true; // file-level deprecation
|
||||
|
||||
// DeprecatedRequest is a request to DeprecatedCall.
|
||||
message DeprecatedRequest {
|
||||
option deprecated = true;
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
message DeprecatedResponse {
|
||||
// comment for DeprecatedResponse is omitted to guarantee deprecation
|
||||
// message doesn't append unnecessary comments.
|
||||
option deprecated = true;
|
||||
// DeprecatedField contains a DeprecatedEnum.
|
||||
DeprecatedEnum deprecated_field = 1 [deprecated=true];
|
||||
// DeprecatedOneof contains a deprecated field.
|
||||
oneof deprecated_oneof {
|
||||
// DeprecatedOneofField is a deprecated field.
|
||||
string deprecated_oneof_field = 2 [deprecated=true];
|
||||
}
|
||||
}
|
||||
|
||||
func TestGolden(t *testing.T) {
|
||||
// Compute the original checksum.
|
||||
goldenSum := sum(t, "test.pb.go")
|
||||
// Run the proto compiler.
|
||||
run(t, "protoc", "--go_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")
|
||||
}
|
||||
// DeprecatedEnum contains deprecated values.
|
||||
enum DeprecatedEnum {
|
||||
option deprecated = true;
|
||||
// DEPRECATED is the iota value of this enum.
|
||||
DEPRECATED = 0 [deprecated=true];
|
||||
}
|
||||
|
||||
// DeprecatedService is for making DeprecatedCalls
|
||||
service DeprecatedService {
|
||||
option deprecated = true;
|
||||
|
||||
// DeprecatedCall takes a DeprecatedRequest and returns a DeprecatedResponse.
|
||||
rpc DeprecatedCall(DeprecatedRequest) returns (DeprecatedResponse) {
|
||||
option deprecated = true;
|
||||
}
|
||||
}
|
136
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/extension_base/extension_base.pb.go
generated
vendored
Normal file
136
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/extension_base/extension_base.pb.go
generated
vendored
Normal file
@ -0,0 +1,136 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: extension_base/extension_base.proto
|
||||
|
||||
package extension_base
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
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.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
type BaseMessage struct {
|
||||
Height *int32 `protobuf:"varint,1,opt,name=height" json:"height,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
proto.XXX_InternalExtensions `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *BaseMessage) Reset() { *m = BaseMessage{} }
|
||||
func (m *BaseMessage) String() string { return proto.CompactTextString(m) }
|
||||
func (*BaseMessage) ProtoMessage() {}
|
||||
func (*BaseMessage) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_2fbd53bac0b7ca8a, []int{0}
|
||||
}
|
||||
|
||||
var extRange_BaseMessage = []proto.ExtensionRange{
|
||||
{Start: 4, End: 9},
|
||||
{Start: 16, End: 536870911},
|
||||
}
|
||||
|
||||
func (*BaseMessage) ExtensionRangeArray() []proto.ExtensionRange {
|
||||
return extRange_BaseMessage
|
||||
}
|
||||
|
||||
func (m *BaseMessage) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_BaseMessage.Unmarshal(m, b)
|
||||
}
|
||||
func (m *BaseMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_BaseMessage.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *BaseMessage) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_BaseMessage.Merge(m, src)
|
||||
}
|
||||
func (m *BaseMessage) XXX_Size() int {
|
||||
return xxx_messageInfo_BaseMessage.Size(m)
|
||||
}
|
||||
func (m *BaseMessage) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_BaseMessage.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_BaseMessage proto.InternalMessageInfo
|
||||
|
||||
func (m *BaseMessage) GetHeight() int32 {
|
||||
if m != nil && m.Height != nil {
|
||||
return *m.Height
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// Another message that may be extended, using message_set_wire_format.
|
||||
type OldStyleMessage struct {
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
proto.XXX_InternalExtensions `protobuf_messageset:"1" json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *OldStyleMessage) Reset() { *m = OldStyleMessage{} }
|
||||
func (m *OldStyleMessage) String() string { return proto.CompactTextString(m) }
|
||||
func (*OldStyleMessage) ProtoMessage() {}
|
||||
func (*OldStyleMessage) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_2fbd53bac0b7ca8a, []int{1}
|
||||
}
|
||||
|
||||
var extRange_OldStyleMessage = []proto.ExtensionRange{
|
||||
{Start: 100, End: 2147483646},
|
||||
}
|
||||
|
||||
func (*OldStyleMessage) ExtensionRangeArray() []proto.ExtensionRange {
|
||||
return extRange_OldStyleMessage
|
||||
}
|
||||
|
||||
func (m *OldStyleMessage) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_OldStyleMessage.Unmarshal(m, b)
|
||||
}
|
||||
func (m *OldStyleMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_OldStyleMessage.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *OldStyleMessage) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_OldStyleMessage.Merge(m, src)
|
||||
}
|
||||
func (m *OldStyleMessage) XXX_Size() int {
|
||||
return xxx_messageInfo_OldStyleMessage.Size(m)
|
||||
}
|
||||
func (m *OldStyleMessage) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_OldStyleMessage.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_OldStyleMessage proto.InternalMessageInfo
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*BaseMessage)(nil), "extension_base.BaseMessage")
|
||||
proto.RegisterType((*OldStyleMessage)(nil), "extension_base.OldStyleMessage")
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterFile("extension_base/extension_base.proto", fileDescriptor_2fbd53bac0b7ca8a)
|
||||
}
|
||||
|
||||
var fileDescriptor_2fbd53bac0b7ca8a = []byte{
|
||||
// 179 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4e, 0xad, 0x28, 0x49,
|
||||
0xcd, 0x2b, 0xce, 0xcc, 0xcf, 0x8b, 0x4f, 0x4a, 0x2c, 0x4e, 0xd5, 0x47, 0xe5, 0xea, 0x15, 0x14,
|
||||
0xe5, 0x97, 0xe4, 0x0b, 0xf1, 0xa1, 0x8a, 0x2a, 0x99, 0x72, 0x71, 0x3b, 0x25, 0x16, 0xa7, 0xfa,
|
||||
0xa6, 0x16, 0x17, 0x27, 0xa6, 0xa7, 0x0a, 0x89, 0x71, 0xb1, 0x65, 0xa4, 0x66, 0xa6, 0x67, 0x94,
|
||||
0x48, 0x30, 0x2a, 0x30, 0x6a, 0xb0, 0x06, 0x41, 0x79, 0x5a, 0x2c, 0x1c, 0x2c, 0x02, 0x5c, 0x5a,
|
||||
0x1c, 0x1c, 0x02, 0x02, 0x0d, 0x0d, 0x0d, 0x0d, 0x4c, 0x4a, 0xf2, 0x5c, 0xfc, 0xfe, 0x39, 0x29,
|
||||
0xc1, 0x25, 0x95, 0x39, 0x30, 0xad, 0x5a, 0x1c, 0x1c, 0x29, 0x02, 0xff, 0xff, 0xff, 0xff, 0xcf,
|
||||
0x6e, 0xc5, 0xc4, 0xc1, 0xe8, 0xe4, 0x14, 0xe5, 0x90, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97,
|
||||
0x9c, 0x9f, 0xab, 0x9f, 0x9e, 0x9f, 0x93, 0x98, 0x97, 0xae, 0x0f, 0x76, 0x42, 0x52, 0x69, 0x1a,
|
||||
0x84, 0x91, 0xac, 0x9b, 0x9e, 0x9a, 0xa7, 0x9b, 0x9e, 0xaf, 0x5f, 0x92, 0x5a, 0x5c, 0x92, 0x92,
|
||||
0x58, 0x92, 0x88, 0xe6, 0x62, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7a, 0x7f, 0xb7, 0x2a, 0xd1,
|
||||
0x00, 0x00, 0x00,
|
||||
}
|
@ -33,6 +33,8 @@ syntax = "proto2";
|
||||
|
||||
package extension_base;
|
||||
|
||||
option go_package = "github.com/golang/protobuf/protoc-gen-go/testdata/extension_base";
|
||||
|
||||
message BaseMessage {
|
||||
optional int32 height = 1;
|
||||
extensions 4 to 9;
|
81
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/extension_extra/extension_extra.pb.go
generated
vendored
Normal file
81
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/extension_extra/extension_extra.pb.go
generated
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: extension_extra/extension_extra.proto
|
||||
|
||||
package extension_extra
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
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.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
type ExtraMessage struct {
|
||||
Width *int32 `protobuf:"varint,1,opt,name=width" json:"width,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *ExtraMessage) Reset() { *m = ExtraMessage{} }
|
||||
func (m *ExtraMessage) String() string { return proto.CompactTextString(m) }
|
||||
func (*ExtraMessage) ProtoMessage() {}
|
||||
func (*ExtraMessage) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_fce75f5a63502cd5, []int{0}
|
||||
}
|
||||
|
||||
func (m *ExtraMessage) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_ExtraMessage.Unmarshal(m, b)
|
||||
}
|
||||
func (m *ExtraMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_ExtraMessage.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *ExtraMessage) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_ExtraMessage.Merge(m, src)
|
||||
}
|
||||
func (m *ExtraMessage) XXX_Size() int {
|
||||
return xxx_messageInfo_ExtraMessage.Size(m)
|
||||
}
|
||||
func (m *ExtraMessage) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_ExtraMessage.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_ExtraMessage proto.InternalMessageInfo
|
||||
|
||||
func (m *ExtraMessage) GetWidth() int32 {
|
||||
if m != nil && m.Width != nil {
|
||||
return *m.Width
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*ExtraMessage)(nil), "extension_extra.ExtraMessage")
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterFile("extension_extra/extension_extra.proto", fileDescriptor_fce75f5a63502cd5)
|
||||
}
|
||||
|
||||
var fileDescriptor_fce75f5a63502cd5 = []byte{
|
||||
// 133 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4d, 0xad, 0x28, 0x49,
|
||||
0xcd, 0x2b, 0xce, 0xcc, 0xcf, 0x8b, 0x4f, 0xad, 0x28, 0x29, 0x4a, 0xd4, 0x47, 0xe3, 0xeb, 0x15,
|
||||
0x14, 0xe5, 0x97, 0xe4, 0x0b, 0xf1, 0xa3, 0x09, 0x2b, 0xa9, 0x70, 0xf1, 0xb8, 0x82, 0x18, 0xbe,
|
||||
0xa9, 0xc5, 0xc5, 0x89, 0xe9, 0xa9, 0x42, 0x22, 0x5c, 0xac, 0xe5, 0x99, 0x29, 0x25, 0x19, 0x12,
|
||||
0x8c, 0x0a, 0x8c, 0x1a, 0xac, 0x41, 0x10, 0x8e, 0x93, 0x73, 0x94, 0x63, 0x7a, 0x66, 0x49, 0x46,
|
||||
0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x7e, 0x7a, 0x7e, 0x4e, 0x62, 0x5e, 0xba, 0x3e, 0xd8, 0xc4,
|
||||
0xa4, 0xd2, 0x34, 0x08, 0x23, 0x59, 0x37, 0x3d, 0x35, 0x4f, 0x37, 0x3d, 0x5f, 0xbf, 0x24, 0xb5,
|
||||
0xb8, 0x24, 0x25, 0xb1, 0x04, 0xc3, 0x05, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf1, 0xec, 0xe3,
|
||||
0xb7, 0xa3, 0x00, 0x00, 0x00,
|
||||
}
|
@ -33,6 +33,8 @@ syntax = "proto2";
|
||||
|
||||
package extension_extra;
|
||||
|
||||
option go_package = "github.com/golang/protobuf/protoc-gen-go/testdata/extension_extra";
|
||||
|
||||
message ExtraMessage {
|
||||
optional int32 width = 1;
|
||||
}
|
8
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/extension_test.go
generated
vendored
8
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/extension_test.go
generated
vendored
@ -33,16 +33,14 @@
|
||||
|
||||
package testdata
|
||||
|
||||
/*
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
base "extension_base.pb"
|
||||
user "extension_user.pb"
|
||||
base "github.com/golang/protobuf/protoc-gen-go/testdata/extension_base"
|
||||
user "github.com/golang/protobuf/protoc-gen-go/testdata/extension_user"
|
||||
)
|
||||
|
||||
func TestSingleFieldExtension(t *testing.T) {
|
||||
@ -206,5 +204,3 @@ func main() {
|
||||
[]testing.InternalBenchmark{},
|
||||
[]testing.InternalExample{})
|
||||
}
|
||||
|
||||
*/
|
||||
|
408
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/extension_user/extension_user.pb.go
generated
vendored
Normal file
408
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/extension_user/extension_user.pb.go
generated
vendored
Normal file
@ -0,0 +1,408 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: extension_user/extension_user.proto
|
||||
|
||||
package extension_user
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
extension_base "github.com/golang/protobuf/protoc-gen-go/testdata/extension_base"
|
||||
extension_extra "github.com/golang/protobuf/protoc-gen-go/testdata/extension_extra"
|
||||
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.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
type UserMessage struct {
|
||||
Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
|
||||
Rank *string `protobuf:"bytes,2,opt,name=rank" json:"rank,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *UserMessage) Reset() { *m = UserMessage{} }
|
||||
func (m *UserMessage) String() string { return proto.CompactTextString(m) }
|
||||
func (*UserMessage) ProtoMessage() {}
|
||||
func (*UserMessage) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_359ba8abf543ca10, []int{0}
|
||||
}
|
||||
|
||||
func (m *UserMessage) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_UserMessage.Unmarshal(m, b)
|
||||
}
|
||||
func (m *UserMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_UserMessage.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *UserMessage) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_UserMessage.Merge(m, src)
|
||||
}
|
||||
func (m *UserMessage) XXX_Size() int {
|
||||
return xxx_messageInfo_UserMessage.Size(m)
|
||||
}
|
||||
func (m *UserMessage) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_UserMessage.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_UserMessage proto.InternalMessageInfo
|
||||
|
||||
func (m *UserMessage) GetName() string {
|
||||
if m != nil && m.Name != nil {
|
||||
return *m.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *UserMessage) GetRank() string {
|
||||
if m != nil && m.Rank != nil {
|
||||
return *m.Rank
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Extend inside the scope of another type
|
||||
type LoudMessage struct {
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
proto.XXX_InternalExtensions `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *LoudMessage) Reset() { *m = LoudMessage{} }
|
||||
func (m *LoudMessage) String() string { return proto.CompactTextString(m) }
|
||||
func (*LoudMessage) ProtoMessage() {}
|
||||
func (*LoudMessage) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_359ba8abf543ca10, []int{1}
|
||||
}
|
||||
|
||||
var extRange_LoudMessage = []proto.ExtensionRange{
|
||||
{Start: 100, End: 536870911},
|
||||
}
|
||||
|
||||
func (*LoudMessage) ExtensionRangeArray() []proto.ExtensionRange {
|
||||
return extRange_LoudMessage
|
||||
}
|
||||
|
||||
func (m *LoudMessage) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_LoudMessage.Unmarshal(m, b)
|
||||
}
|
||||
func (m *LoudMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_LoudMessage.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *LoudMessage) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_LoudMessage.Merge(m, src)
|
||||
}
|
||||
func (m *LoudMessage) XXX_Size() int {
|
||||
return xxx_messageInfo_LoudMessage.Size(m)
|
||||
}
|
||||
func (m *LoudMessage) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_LoudMessage.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_LoudMessage proto.InternalMessageInfo
|
||||
|
||||
var E_LoudMessage_Volume = &proto.ExtensionDesc{
|
||||
ExtendedType: (*extension_base.BaseMessage)(nil),
|
||||
ExtensionType: (*uint32)(nil),
|
||||
Field: 8,
|
||||
Name: "extension_user.LoudMessage.volume",
|
||||
Tag: "varint,8,opt,name=volume",
|
||||
Filename: "extension_user/extension_user.proto",
|
||||
}
|
||||
|
||||
// Extend inside the scope of another type, using a message.
|
||||
type LoginMessage struct {
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *LoginMessage) Reset() { *m = LoginMessage{} }
|
||||
func (m *LoginMessage) String() string { return proto.CompactTextString(m) }
|
||||
func (*LoginMessage) ProtoMessage() {}
|
||||
func (*LoginMessage) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_359ba8abf543ca10, []int{2}
|
||||
}
|
||||
|
||||
func (m *LoginMessage) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_LoginMessage.Unmarshal(m, b)
|
||||
}
|
||||
func (m *LoginMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_LoginMessage.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *LoginMessage) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_LoginMessage.Merge(m, src)
|
||||
}
|
||||
func (m *LoginMessage) XXX_Size() int {
|
||||
return xxx_messageInfo_LoginMessage.Size(m)
|
||||
}
|
||||
func (m *LoginMessage) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_LoginMessage.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_LoginMessage proto.InternalMessageInfo
|
||||
|
||||
var E_LoginMessage_UserMessage = &proto.ExtensionDesc{
|
||||
ExtendedType: (*extension_base.BaseMessage)(nil),
|
||||
ExtensionType: (*UserMessage)(nil),
|
||||
Field: 16,
|
||||
Name: "extension_user.LoginMessage.user_message",
|
||||
Tag: "bytes,16,opt,name=user_message",
|
||||
Filename: "extension_user/extension_user.proto",
|
||||
}
|
||||
|
||||
type Detail struct {
|
||||
Color *string `protobuf:"bytes,1,opt,name=color" json:"color,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Detail) Reset() { *m = Detail{} }
|
||||
func (m *Detail) String() string { return proto.CompactTextString(m) }
|
||||
func (*Detail) ProtoMessage() {}
|
||||
func (*Detail) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_359ba8abf543ca10, []int{3}
|
||||
}
|
||||
|
||||
func (m *Detail) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_Detail.Unmarshal(m, b)
|
||||
}
|
||||
func (m *Detail) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_Detail.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *Detail) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Detail.Merge(m, src)
|
||||
}
|
||||
func (m *Detail) XXX_Size() int {
|
||||
return xxx_messageInfo_Detail.Size(m)
|
||||
}
|
||||
func (m *Detail) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Detail.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_Detail proto.InternalMessageInfo
|
||||
|
||||
func (m *Detail) GetColor() string {
|
||||
if m != nil && m.Color != nil {
|
||||
return *m.Color
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// An extension of an extension
|
||||
type Announcement struct {
|
||||
Words *string `protobuf:"bytes,1,opt,name=words" json:"words,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Announcement) Reset() { *m = Announcement{} }
|
||||
func (m *Announcement) String() string { return proto.CompactTextString(m) }
|
||||
func (*Announcement) ProtoMessage() {}
|
||||
func (*Announcement) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_359ba8abf543ca10, []int{4}
|
||||
}
|
||||
|
||||
func (m *Announcement) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_Announcement.Unmarshal(m, b)
|
||||
}
|
||||
func (m *Announcement) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_Announcement.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *Announcement) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Announcement.Merge(m, src)
|
||||
}
|
||||
func (m *Announcement) XXX_Size() int {
|
||||
return xxx_messageInfo_Announcement.Size(m)
|
||||
}
|
||||
func (m *Announcement) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Announcement.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_Announcement proto.InternalMessageInfo
|
||||
|
||||
func (m *Announcement) GetWords() string {
|
||||
if m != nil && m.Words != nil {
|
||||
return *m.Words
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
var E_Announcement_LoudExt = &proto.ExtensionDesc{
|
||||
ExtendedType: (*LoudMessage)(nil),
|
||||
ExtensionType: (*Announcement)(nil),
|
||||
Field: 100,
|
||||
Name: "extension_user.Announcement.loud_ext",
|
||||
Tag: "bytes,100,opt,name=loud_ext",
|
||||
Filename: "extension_user/extension_user.proto",
|
||||
}
|
||||
|
||||
// Something that can be put in a message set.
|
||||
type OldStyleParcel struct {
|
||||
Name *string `protobuf:"bytes,1,req,name=name" json:"name,omitempty"`
|
||||
Height *int32 `protobuf:"varint,2,opt,name=height" json:"height,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *OldStyleParcel) Reset() { *m = OldStyleParcel{} }
|
||||
func (m *OldStyleParcel) String() string { return proto.CompactTextString(m) }
|
||||
func (*OldStyleParcel) ProtoMessage() {}
|
||||
func (*OldStyleParcel) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_359ba8abf543ca10, []int{5}
|
||||
}
|
||||
|
||||
func (m *OldStyleParcel) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_OldStyleParcel.Unmarshal(m, b)
|
||||
}
|
||||
func (m *OldStyleParcel) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_OldStyleParcel.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *OldStyleParcel) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_OldStyleParcel.Merge(m, src)
|
||||
}
|
||||
func (m *OldStyleParcel) XXX_Size() int {
|
||||
return xxx_messageInfo_OldStyleParcel.Size(m)
|
||||
}
|
||||
func (m *OldStyleParcel) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_OldStyleParcel.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_OldStyleParcel proto.InternalMessageInfo
|
||||
|
||||
func (m *OldStyleParcel) GetName() string {
|
||||
if m != nil && m.Name != nil {
|
||||
return *m.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *OldStyleParcel) GetHeight() int32 {
|
||||
if m != nil && m.Height != nil {
|
||||
return *m.Height
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
var E_OldStyleParcel_MessageSetExtension = &proto.ExtensionDesc{
|
||||
ExtendedType: (*extension_base.OldStyleMessage)(nil),
|
||||
ExtensionType: (*OldStyleParcel)(nil),
|
||||
Field: 2001,
|
||||
Name: "extension_user.OldStyleParcel",
|
||||
Tag: "bytes,2001,opt,name=message_set_extension",
|
||||
Filename: "extension_user/extension_user.proto",
|
||||
}
|
||||
|
||||
var E_UserMessage = &proto.ExtensionDesc{
|
||||
ExtendedType: (*extension_base.BaseMessage)(nil),
|
||||
ExtensionType: (*UserMessage)(nil),
|
||||
Field: 5,
|
||||
Name: "extension_user.user_message",
|
||||
Tag: "bytes,5,opt,name=user_message",
|
||||
Filename: "extension_user/extension_user.proto",
|
||||
}
|
||||
|
||||
var E_ExtraMessage = &proto.ExtensionDesc{
|
||||
ExtendedType: (*extension_base.BaseMessage)(nil),
|
||||
ExtensionType: (*extension_extra.ExtraMessage)(nil),
|
||||
Field: 9,
|
||||
Name: "extension_user.extra_message",
|
||||
Tag: "bytes,9,opt,name=extra_message",
|
||||
Filename: "extension_user/extension_user.proto",
|
||||
}
|
||||
|
||||
var E_Width = &proto.ExtensionDesc{
|
||||
ExtendedType: (*extension_base.BaseMessage)(nil),
|
||||
ExtensionType: (*int32)(nil),
|
||||
Field: 6,
|
||||
Name: "extension_user.width",
|
||||
Tag: "varint,6,opt,name=width",
|
||||
Filename: "extension_user/extension_user.proto",
|
||||
}
|
||||
|
||||
var E_Area = &proto.ExtensionDesc{
|
||||
ExtendedType: (*extension_base.BaseMessage)(nil),
|
||||
ExtensionType: (*int64)(nil),
|
||||
Field: 7,
|
||||
Name: "extension_user.area",
|
||||
Tag: "varint,7,opt,name=area",
|
||||
Filename: "extension_user/extension_user.proto",
|
||||
}
|
||||
|
||||
var E_Detail = &proto.ExtensionDesc{
|
||||
ExtendedType: (*extension_base.BaseMessage)(nil),
|
||||
ExtensionType: ([]*Detail)(nil),
|
||||
Field: 17,
|
||||
Name: "extension_user.detail",
|
||||
Tag: "bytes,17,rep,name=detail",
|
||||
Filename: "extension_user/extension_user.proto",
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*UserMessage)(nil), "extension_user.UserMessage")
|
||||
proto.RegisterExtension(E_LoudMessage_Volume)
|
||||
proto.RegisterType((*LoudMessage)(nil), "extension_user.LoudMessage")
|
||||
proto.RegisterExtension(E_LoginMessage_UserMessage)
|
||||
proto.RegisterType((*LoginMessage)(nil), "extension_user.LoginMessage")
|
||||
proto.RegisterType((*Detail)(nil), "extension_user.Detail")
|
||||
proto.RegisterExtension(E_Announcement_LoudExt)
|
||||
proto.RegisterType((*Announcement)(nil), "extension_user.Announcement")
|
||||
proto.RegisterExtension(E_OldStyleParcel_MessageSetExtension)
|
||||
proto.RegisterType((*OldStyleParcel)(nil), "extension_user.OldStyleParcel")
|
||||
proto.RegisterExtension(E_UserMessage)
|
||||
proto.RegisterExtension(E_ExtraMessage)
|
||||
proto.RegisterExtension(E_Width)
|
||||
proto.RegisterExtension(E_Area)
|
||||
proto.RegisterExtension(E_Detail)
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterFile("extension_user/extension_user.proto", fileDescriptor_359ba8abf543ca10)
|
||||
}
|
||||
|
||||
var fileDescriptor_359ba8abf543ca10 = []byte{
|
||||
// 492 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0x51, 0x6f, 0x94, 0x40,
|
||||
0x10, 0x0e, 0x6d, 0x8f, 0x5e, 0x87, 0x6b, 0xad, 0xa8, 0xcd, 0xa5, 0x6a, 0x25, 0x18, 0x13, 0x62,
|
||||
0xd2, 0x23, 0x62, 0x7c, 0xe1, 0x49, 0x2f, 0xde, 0x93, 0x67, 0x34, 0x54, 0x5f, 0xf4, 0x81, 0xec,
|
||||
0xc1, 0xc8, 0x91, 0xc2, 0xae, 0xd9, 0x5d, 0xec, 0xe9, 0xd3, 0xfd, 0x26, 0xff, 0x89, 0xff, 0xc8,
|
||||
0xb0, 0x2c, 0x2d, 0x87, 0xc9, 0xc5, 0xbe, 0x90, 0xfd, 0x86, 0x6f, 0xbe, 0x99, 0xfd, 0x66, 0x00,
|
||||
0x9e, 0xe2, 0x4a, 0x22, 0x15, 0x39, 0xa3, 0x71, 0x25, 0x90, 0xfb, 0x9b, 0x70, 0xf2, 0x9d, 0x33,
|
||||
0xc9, 0xec, 0xa3, 0xcd, 0xe8, 0x69, 0x27, 0x69, 0x41, 0x04, 0xfa, 0x9b, 0xb0, 0x49, 0x3a, 0x7d,
|
||||
0x76, 0x13, 0xc5, 0x95, 0xe4, 0xc4, 0xef, 0xe1, 0x86, 0xe6, 0xbe, 0x02, 0xeb, 0xb3, 0x40, 0xfe,
|
||||
0x1e, 0x85, 0x20, 0x19, 0xda, 0x36, 0xec, 0x51, 0x52, 0xe2, 0xd8, 0x70, 0x0c, 0xef, 0x20, 0x52,
|
||||
0xe7, 0x3a, 0xc6, 0x09, 0xbd, 0x1c, 0xef, 0x34, 0xb1, 0xfa, 0xec, 0xce, 0xc1, 0x9a, 0xb3, 0x2a,
|
||||
0xd5, 0x69, 0xcf, 0x87, 0xc3, 0xf4, 0x78, 0xbd, 0x5e, 0xaf, 0x77, 0x82, 0x97, 0x60, 0xfe, 0x60,
|
||||
0x45, 0x55, 0xa2, 0xfd, 0x70, 0xd2, 0xeb, 0x6b, 0x4a, 0x04, 0xea, 0x84, 0xf1, 0xd0, 0x31, 0xbc,
|
||||
0xc3, 0x48, 0x53, 0xdd, 0x4b, 0x18, 0xcd, 0x59, 0x96, 0x53, 0xfd, 0x36, 0xf8, 0x0a, 0xa3, 0xfa,
|
||||
0xa2, 0x71, 0xa9, 0xbb, 0xda, 0x2a, 0x75, 0xec, 0x18, 0x9e, 0x15, 0x74, 0x29, 0xca, 0xba, 0xce,
|
||||
0xad, 0x22, 0xab, 0xba, 0x01, 0xee, 0x19, 0x98, 0x6f, 0x51, 0x92, 0xbc, 0xb0, 0xef, 0xc3, 0x20,
|
||||
0x61, 0x05, 0xe3, 0xfa, 0xb6, 0x0d, 0x70, 0x7f, 0xc1, 0xe8, 0x0d, 0xa5, 0xac, 0xa2, 0x09, 0x96,
|
||||
0x48, 0x65, 0xcd, 0xba, 0x62, 0x3c, 0x15, 0x2d, 0x4b, 0x81, 0xe0, 0x13, 0x0c, 0x0b, 0x56, 0xa5,
|
||||
0xb5, 0x97, 0xf6, 0x3f, 0xb5, 0x3b, 0xd6, 0x8c, 0x53, 0xd5, 0xde, 0xa3, 0x3e, 0xa5, 0x5b, 0x22,
|
||||
0xda, 0xaf, 0xa5, 0x66, 0x2b, 0xe9, 0xfe, 0x36, 0xe0, 0xe8, 0x43, 0x91, 0x5e, 0xc8, 0x9f, 0x05,
|
||||
0x7e, 0x24, 0x3c, 0xc1, 0xa2, 0x33, 0x91, 0x9d, 0xeb, 0x89, 0x9c, 0x80, 0xb9, 0xc4, 0x3c, 0x5b,
|
||||
0x4a, 0x35, 0x93, 0x41, 0xa4, 0x51, 0x20, 0xe1, 0x81, 0xb6, 0x2c, 0x16, 0x28, 0xe3, 0xeb, 0x92,
|
||||
0xf6, 0x93, 0xbe, 0x81, 0x6d, 0x91, 0xb6, 0xcb, 0x3f, 0x77, 0x54, 0x9b, 0x67, 0xfd, 0x36, 0x37,
|
||||
0x9b, 0x89, 0xee, 0x69, 0xf9, 0x0b, 0x94, 0xb3, 0x96, 0x18, 0xde, 0x6a, 0x5a, 0x83, 0xdb, 0x4d,
|
||||
0x2b, 0x8c, 0xe1, 0x50, 0xad, 0xeb, 0xff, 0xa9, 0x1f, 0x28, 0xf5, 0xc7, 0x93, 0xfe, 0xae, 0xcf,
|
||||
0xea, 0x67, 0xab, 0x3f, 0xc2, 0x0e, 0x0a, 0x5f, 0xc0, 0xe0, 0x2a, 0x4f, 0xe5, 0x72, 0xbb, 0xb0,
|
||||
0xa9, 0x7c, 0x6e, 0x98, 0xa1, 0x0f, 0x7b, 0x84, 0x23, 0xd9, 0x9e, 0xb1, 0xef, 0x18, 0xde, 0x6e,
|
||||
0xa4, 0x88, 0xe1, 0x3b, 0x30, 0xd3, 0x66, 0xe5, 0xb6, 0xa6, 0xdc, 0x75, 0x76, 0x3d, 0x2b, 0x38,
|
||||
0xe9, 0x7b, 0xd3, 0x6c, 0x6b, 0xa4, 0x25, 0xa6, 0xd3, 0x2f, 0xaf, 0xb3, 0x5c, 0x2e, 0xab, 0xc5,
|
||||
0x24, 0x61, 0xa5, 0x9f, 0xb1, 0x82, 0xd0, 0xcc, 0x57, 0x1f, 0xf3, 0xa2, 0xfa, 0xd6, 0x1c, 0x92,
|
||||
0xf3, 0x0c, 0xe9, 0x79, 0xc6, 0x7c, 0x89, 0x42, 0xa6, 0x44, 0x92, 0xde, 0x7f, 0xe5, 0x6f, 0x00,
|
||||
0x00, 0x00, 0xff, 0xff, 0xdf, 0x18, 0x64, 0x15, 0x77, 0x04, 0x00, 0x00,
|
||||
}
|
@ -31,11 +31,13 @@
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
import "extension_base.proto";
|
||||
import "extension_extra.proto";
|
||||
import "extension_base/extension_base.proto";
|
||||
import "extension_extra/extension_extra.proto";
|
||||
|
||||
package extension_user;
|
||||
|
||||
option go_package = "github.com/golang/protobuf/protoc-gen-go/testdata/extension_user";
|
||||
|
||||
message UserMessage {
|
||||
optional string name = 1;
|
||||
optional string rank = 2;
|
447
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/grpc/grpc.pb.go
generated
vendored
Normal file
447
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/grpc/grpc.pb.go
generated
vendored
Normal file
@ -0,0 +1,447 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: grpc/grpc.proto
|
||||
|
||||
package testing
|
||||
|
||||
import (
|
||||
context "context"
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
grpc "google.golang.org/grpc"
|
||||
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.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
type SimpleRequest struct {
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *SimpleRequest) Reset() { *m = SimpleRequest{} }
|
||||
func (m *SimpleRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*SimpleRequest) ProtoMessage() {}
|
||||
func (*SimpleRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_81ea47a3f88c2082, []int{0}
|
||||
}
|
||||
|
||||
func (m *SimpleRequest) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_SimpleRequest.Unmarshal(m, b)
|
||||
}
|
||||
func (m *SimpleRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_SimpleRequest.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *SimpleRequest) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_SimpleRequest.Merge(m, src)
|
||||
}
|
||||
func (m *SimpleRequest) XXX_Size() int {
|
||||
return xxx_messageInfo_SimpleRequest.Size(m)
|
||||
}
|
||||
func (m *SimpleRequest) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_SimpleRequest.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_SimpleRequest proto.InternalMessageInfo
|
||||
|
||||
type SimpleResponse struct {
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *SimpleResponse) Reset() { *m = SimpleResponse{} }
|
||||
func (m *SimpleResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*SimpleResponse) ProtoMessage() {}
|
||||
func (*SimpleResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_81ea47a3f88c2082, []int{1}
|
||||
}
|
||||
|
||||
func (m *SimpleResponse) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_SimpleResponse.Unmarshal(m, b)
|
||||
}
|
||||
func (m *SimpleResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_SimpleResponse.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *SimpleResponse) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_SimpleResponse.Merge(m, src)
|
||||
}
|
||||
func (m *SimpleResponse) XXX_Size() int {
|
||||
return xxx_messageInfo_SimpleResponse.Size(m)
|
||||
}
|
||||
func (m *SimpleResponse) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_SimpleResponse.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_SimpleResponse proto.InternalMessageInfo
|
||||
|
||||
type StreamMsg struct {
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *StreamMsg) Reset() { *m = StreamMsg{} }
|
||||
func (m *StreamMsg) String() string { return proto.CompactTextString(m) }
|
||||
func (*StreamMsg) ProtoMessage() {}
|
||||
func (*StreamMsg) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_81ea47a3f88c2082, []int{2}
|
||||
}
|
||||
|
||||
func (m *StreamMsg) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_StreamMsg.Unmarshal(m, b)
|
||||
}
|
||||
func (m *StreamMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_StreamMsg.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *StreamMsg) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_StreamMsg.Merge(m, src)
|
||||
}
|
||||
func (m *StreamMsg) XXX_Size() int {
|
||||
return xxx_messageInfo_StreamMsg.Size(m)
|
||||
}
|
||||
func (m *StreamMsg) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_StreamMsg.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_StreamMsg proto.InternalMessageInfo
|
||||
|
||||
type StreamMsg2 struct {
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *StreamMsg2) Reset() { *m = StreamMsg2{} }
|
||||
func (m *StreamMsg2) String() string { return proto.CompactTextString(m) }
|
||||
func (*StreamMsg2) ProtoMessage() {}
|
||||
func (*StreamMsg2) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_81ea47a3f88c2082, []int{3}
|
||||
}
|
||||
|
||||
func (m *StreamMsg2) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_StreamMsg2.Unmarshal(m, b)
|
||||
}
|
||||
func (m *StreamMsg2) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_StreamMsg2.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *StreamMsg2) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_StreamMsg2.Merge(m, src)
|
||||
}
|
||||
func (m *StreamMsg2) XXX_Size() int {
|
||||
return xxx_messageInfo_StreamMsg2.Size(m)
|
||||
}
|
||||
func (m *StreamMsg2) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_StreamMsg2.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_StreamMsg2 proto.InternalMessageInfo
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*SimpleRequest)(nil), "grpc.testing.SimpleRequest")
|
||||
proto.RegisterType((*SimpleResponse)(nil), "grpc.testing.SimpleResponse")
|
||||
proto.RegisterType((*StreamMsg)(nil), "grpc.testing.StreamMsg")
|
||||
proto.RegisterType((*StreamMsg2)(nil), "grpc.testing.StreamMsg2")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("grpc/grpc.proto", fileDescriptor_81ea47a3f88c2082) }
|
||||
|
||||
var fileDescriptor_81ea47a3f88c2082 = []byte{
|
||||
// 244 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4f, 0x2f, 0x2a, 0x48,
|
||||
0xd6, 0x07, 0x11, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x3c, 0x60, 0x76, 0x49, 0x6a, 0x71,
|
||||
0x49, 0x66, 0x5e, 0xba, 0x12, 0x3f, 0x17, 0x6f, 0x70, 0x66, 0x6e, 0x41, 0x4e, 0x6a, 0x50, 0x6a,
|
||||
0x61, 0x69, 0x6a, 0x71, 0x89, 0x92, 0x00, 0x17, 0x1f, 0x4c, 0xa0, 0xb8, 0x20, 0x3f, 0xaf, 0x38,
|
||||
0x55, 0x89, 0x9b, 0x8b, 0x33, 0xb8, 0xa4, 0x28, 0x35, 0x31, 0xd7, 0xb7, 0x38, 0x5d, 0x89, 0x87,
|
||||
0x8b, 0x0b, 0xce, 0x31, 0x32, 0x9a, 0xc1, 0xc4, 0xc5, 0x12, 0x92, 0x5a, 0x5c, 0x22, 0xe4, 0xc6,
|
||||
0xc5, 0x19, 0x9a, 0x97, 0x58, 0x54, 0xe9, 0x9c, 0x98, 0x93, 0x23, 0x24, 0xad, 0x87, 0x6c, 0x85,
|
||||
0x1e, 0x8a, 0xf9, 0x52, 0x32, 0xd8, 0x25, 0x21, 0x76, 0x09, 0xb9, 0x70, 0x71, 0xb9, 0xe4, 0x97,
|
||||
0xe7, 0x15, 0x83, 0xad, 0xc0, 0x6f, 0x90, 0x38, 0x9a, 0x24, 0xcc, 0x55, 0x06, 0x8c, 0x42, 0xce,
|
||||
0x5c, 0x1c, 0xa1, 0x05, 0x50, 0x33, 0x70, 0x29, 0xc3, 0xef, 0x10, 0x0d, 0x46, 0x21, 0x5b, 0x2e,
|
||||
0x16, 0xa7, 0xcc, 0x94, 0x4c, 0xdc, 0x06, 0x48, 0xe0, 0x90, 0x30, 0xd2, 0x60, 0x34, 0x60, 0x74,
|
||||
0x72, 0x88, 0xb2, 0x4b, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xcf,
|
||||
0xcf, 0x49, 0xcc, 0x4b, 0xd7, 0x07, 0xc7, 0x40, 0x52, 0x69, 0x1a, 0x84, 0x91, 0xac, 0x9b, 0x9e,
|
||||
0x9a, 0xa7, 0x9b, 0x9e, 0xaf, 0x0f, 0x32, 0x22, 0x25, 0xb1, 0x24, 0x11, 0x1c, 0x4d, 0xd6, 0x50,
|
||||
0x03, 0x93, 0xd8, 0xc0, 0x8a, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x90, 0xb9, 0x95, 0x42,
|
||||
0xc2, 0x01, 0x00, 0x00,
|
||||
}
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ context.Context
|
||||
var _ grpc.ClientConn
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
const _ = grpc.SupportPackageIsVersion4
|
||||
|
||||
// TestClient is the client API for Test service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
|
||||
type TestClient interface {
|
||||
UnaryCall(ctx context.Context, in *SimpleRequest, opts ...grpc.CallOption) (*SimpleResponse, error)
|
||||
// This RPC streams from the server only.
|
||||
Downstream(ctx context.Context, in *SimpleRequest, opts ...grpc.CallOption) (Test_DownstreamClient, error)
|
||||
// This RPC streams from the client.
|
||||
Upstream(ctx context.Context, opts ...grpc.CallOption) (Test_UpstreamClient, error)
|
||||
// This one streams in both directions.
|
||||
Bidi(ctx context.Context, opts ...grpc.CallOption) (Test_BidiClient, error)
|
||||
}
|
||||
|
||||
type testClient struct {
|
||||
cc *grpc.ClientConn
|
||||
}
|
||||
|
||||
func NewTestClient(cc *grpc.ClientConn) TestClient {
|
||||
return &testClient{cc}
|
||||
}
|
||||
|
||||
func (c *testClient) UnaryCall(ctx context.Context, in *SimpleRequest, opts ...grpc.CallOption) (*SimpleResponse, error) {
|
||||
out := new(SimpleResponse)
|
||||
err := c.cc.Invoke(ctx, "/grpc.testing.Test/UnaryCall", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *testClient) Downstream(ctx context.Context, in *SimpleRequest, opts ...grpc.CallOption) (Test_DownstreamClient, error) {
|
||||
stream, err := c.cc.NewStream(ctx, &_Test_serviceDesc.Streams[0], "/grpc.testing.Test/Downstream", opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
x := &testDownstreamClient{stream}
|
||||
if err := x.ClientStream.SendMsg(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := x.ClientStream.CloseSend(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return x, nil
|
||||
}
|
||||
|
||||
type Test_DownstreamClient interface {
|
||||
Recv() (*StreamMsg, error)
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
type testDownstreamClient struct {
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
func (x *testDownstreamClient) Recv() (*StreamMsg, error) {
|
||||
m := new(StreamMsg)
|
||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (c *testClient) Upstream(ctx context.Context, opts ...grpc.CallOption) (Test_UpstreamClient, error) {
|
||||
stream, err := c.cc.NewStream(ctx, &_Test_serviceDesc.Streams[1], "/grpc.testing.Test/Upstream", opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
x := &testUpstreamClient{stream}
|
||||
return x, nil
|
||||
}
|
||||
|
||||
type Test_UpstreamClient interface {
|
||||
Send(*StreamMsg) error
|
||||
CloseAndRecv() (*SimpleResponse, error)
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
type testUpstreamClient struct {
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
func (x *testUpstreamClient) Send(m *StreamMsg) error {
|
||||
return x.ClientStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func (x *testUpstreamClient) CloseAndRecv() (*SimpleResponse, error) {
|
||||
if err := x.ClientStream.CloseSend(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m := new(SimpleResponse)
|
||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (c *testClient) Bidi(ctx context.Context, opts ...grpc.CallOption) (Test_BidiClient, error) {
|
||||
stream, err := c.cc.NewStream(ctx, &_Test_serviceDesc.Streams[2], "/grpc.testing.Test/Bidi", opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
x := &testBidiClient{stream}
|
||||
return x, nil
|
||||
}
|
||||
|
||||
type Test_BidiClient interface {
|
||||
Send(*StreamMsg) error
|
||||
Recv() (*StreamMsg2, error)
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
type testBidiClient struct {
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
func (x *testBidiClient) Send(m *StreamMsg) error {
|
||||
return x.ClientStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func (x *testBidiClient) Recv() (*StreamMsg2, error) {
|
||||
m := new(StreamMsg2)
|
||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// TestServer is the server API for Test service.
|
||||
type TestServer interface {
|
||||
UnaryCall(context.Context, *SimpleRequest) (*SimpleResponse, error)
|
||||
// This RPC streams from the server only.
|
||||
Downstream(*SimpleRequest, Test_DownstreamServer) error
|
||||
// This RPC streams from the client.
|
||||
Upstream(Test_UpstreamServer) error
|
||||
// This one streams in both directions.
|
||||
Bidi(Test_BidiServer) error
|
||||
}
|
||||
|
||||
func RegisterTestServer(s *grpc.Server, srv TestServer) {
|
||||
s.RegisterService(&_Test_serviceDesc, srv)
|
||||
}
|
||||
|
||||
func _Test_UnaryCall_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(SimpleRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(TestServer).UnaryCall(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/grpc.testing.Test/UnaryCall",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(TestServer).UnaryCall(ctx, req.(*SimpleRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Test_Downstream_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||
m := new(SimpleRequest)
|
||||
if err := stream.RecvMsg(m); err != nil {
|
||||
return err
|
||||
}
|
||||
return srv.(TestServer).Downstream(m, &testDownstreamServer{stream})
|
||||
}
|
||||
|
||||
type Test_DownstreamServer interface {
|
||||
Send(*StreamMsg) error
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
type testDownstreamServer struct {
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
func (x *testDownstreamServer) Send(m *StreamMsg) error {
|
||||
return x.ServerStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func _Test_Upstream_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||
return srv.(TestServer).Upstream(&testUpstreamServer{stream})
|
||||
}
|
||||
|
||||
type Test_UpstreamServer interface {
|
||||
SendAndClose(*SimpleResponse) error
|
||||
Recv() (*StreamMsg, error)
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
type testUpstreamServer struct {
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
func (x *testUpstreamServer) SendAndClose(m *SimpleResponse) error {
|
||||
return x.ServerStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func (x *testUpstreamServer) Recv() (*StreamMsg, error) {
|
||||
m := new(StreamMsg)
|
||||
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func _Test_Bidi_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||
return srv.(TestServer).Bidi(&testBidiServer{stream})
|
||||
}
|
||||
|
||||
type Test_BidiServer interface {
|
||||
Send(*StreamMsg2) error
|
||||
Recv() (*StreamMsg, error)
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
type testBidiServer struct {
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
func (x *testBidiServer) Send(m *StreamMsg2) error {
|
||||
return x.ServerStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func (x *testBidiServer) Recv() (*StreamMsg, error) {
|
||||
m := new(StreamMsg)
|
||||
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
var _Test_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "grpc.testing.Test",
|
||||
HandlerType: (*TestServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "UnaryCall",
|
||||
Handler: _Test_UnaryCall_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{
|
||||
{
|
||||
StreamName: "Downstream",
|
||||
Handler: _Test_Downstream_Handler,
|
||||
ServerStreams: true,
|
||||
},
|
||||
{
|
||||
StreamName: "Upstream",
|
||||
Handler: _Test_Upstream_Handler,
|
||||
ClientStreams: true,
|
||||
},
|
||||
{
|
||||
StreamName: "Bidi",
|
||||
Handler: _Test_Bidi_Handler,
|
||||
ServerStreams: true,
|
||||
ClientStreams: true,
|
||||
},
|
||||
},
|
||||
Metadata: "grpc/grpc.proto",
|
||||
}
|
@ -33,6 +33,8 @@ syntax = "proto3";
|
||||
|
||||
package grpc.testing;
|
||||
|
||||
option go_package = "github.com/golang/protobuf/protoc-gen-go/testdata/grpc;testing";
|
||||
|
||||
message SimpleRequest {
|
||||
}
|
||||
|
113
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/imp.pb.go.golden
generated
vendored
113
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/imp.pb.go.golden
generated
vendored
@ -1,113 +0,0 @@
|
||||
// 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)
|
||||
}
|
141
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/import_public/a.pb.go
generated
vendored
Normal file
141
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/import_public/a.pb.go
generated
vendored
Normal file
@ -0,0 +1,141 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: import_public/a.proto
|
||||
|
||||
package import_public
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
sub "github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub"
|
||||
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.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
const Default_M_DefaultField = sub.Default_M_DefaultField
|
||||
|
||||
// M from public import import_public/sub/a.proto
|
||||
type M = sub.M
|
||||
type M_OneofInt32 = sub.M_OneofInt32
|
||||
type M_OneofInt64 = sub.M_OneofInt64
|
||||
|
||||
// M_Grouping from public import import_public/sub/a.proto
|
||||
type M_Grouping = sub.M_Grouping
|
||||
|
||||
// M_Submessage from public import import_public/sub/a.proto
|
||||
type M_Submessage = sub.M_Submessage
|
||||
type M_Submessage_SubmessageOneofInt32 = sub.M_Submessage_SubmessageOneofInt32
|
||||
type M_Submessage_SubmessageOneofInt64 = sub.M_Submessage_SubmessageOneofInt64
|
||||
|
||||
// E from public import import_public/sub/a.proto
|
||||
type E = sub.E
|
||||
|
||||
var E_name = sub.E_name
|
||||
var E_value = sub.E_value
|
||||
|
||||
const E_ZERO = E(sub.E_ZERO)
|
||||
|
||||
// M_Subenum from public import import_public/sub/a.proto
|
||||
type M_Subenum = sub.M_Subenum
|
||||
|
||||
var M_Subenum_name = sub.M_Subenum_name
|
||||
var M_Subenum_value = sub.M_Subenum_value
|
||||
|
||||
const M_M_ZERO = M_Subenum(sub.M_M_ZERO)
|
||||
|
||||
// M_Submessage_Submessage_Subenum from public import import_public/sub/a.proto
|
||||
type M_Submessage_Submessage_Subenum = sub.M_Submessage_Submessage_Subenum
|
||||
|
||||
var M_Submessage_Submessage_Subenum_name = sub.M_Submessage_Submessage_Subenum_name
|
||||
var M_Submessage_Submessage_Subenum_value = sub.M_Submessage_Submessage_Subenum_value
|
||||
|
||||
const M_Submessage_M_SUBMESSAGE_ZERO = M_Submessage_Submessage_Subenum(sub.M_Submessage_M_SUBMESSAGE_ZERO)
|
||||
|
||||
var E_ExtensionField = sub.E_ExtensionField
|
||||
|
||||
type Public struct {
|
||||
M *sub.M `protobuf:"bytes,1,opt,name=m" json:"m,omitempty"`
|
||||
E *sub.E `protobuf:"varint,2,opt,name=e,enum=goproto.test.import_public.sub.E" json:"e,omitempty"`
|
||||
Local *Local `protobuf:"bytes,3,opt,name=local" json:"local,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Public) Reset() { *m = Public{} }
|
||||
func (m *Public) String() string { return proto.CompactTextString(m) }
|
||||
func (*Public) ProtoMessage() {}
|
||||
func (*Public) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_73b7577c95fa6b70, []int{0}
|
||||
}
|
||||
|
||||
func (m *Public) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_Public.Unmarshal(m, b)
|
||||
}
|
||||
func (m *Public) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_Public.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *Public) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Public.Merge(m, src)
|
||||
}
|
||||
func (m *Public) XXX_Size() int {
|
||||
return xxx_messageInfo_Public.Size(m)
|
||||
}
|
||||
func (m *Public) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Public.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_Public proto.InternalMessageInfo
|
||||
|
||||
func (m *Public) GetM() *sub.M {
|
||||
if m != nil {
|
||||
return m.M
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Public) GetE() sub.E {
|
||||
if m != nil && m.E != nil {
|
||||
return *m.E
|
||||
}
|
||||
return sub.E_ZERO
|
||||
}
|
||||
|
||||
func (m *Public) GetLocal() *Local {
|
||||
if m != nil {
|
||||
return m.Local
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*Public)(nil), "goproto.test.import_public.Public")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("import_public/a.proto", fileDescriptor_73b7577c95fa6b70) }
|
||||
|
||||
var fileDescriptor_73b7577c95fa6b70 = []byte{
|
||||
// 195 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xcd, 0xcc, 0x2d, 0xc8,
|
||||
0x2f, 0x2a, 0x89, 0x2f, 0x28, 0x4d, 0xca, 0xc9, 0x4c, 0xd6, 0x4f, 0xd4, 0x2b, 0x28, 0xca, 0x2f,
|
||||
0xc9, 0x17, 0x92, 0x4a, 0xcf, 0x07, 0x33, 0xf4, 0x4a, 0x52, 0x8b, 0x4b, 0xf4, 0x50, 0xd4, 0x48,
|
||||
0x49, 0xa2, 0x6a, 0x29, 0x2e, 0x4d, 0x82, 0x69, 0x93, 0x42, 0x33, 0x2d, 0x09, 0x22, 0xac, 0xb4,
|
||||
0x98, 0x91, 0x8b, 0x2d, 0x00, 0x2c, 0x24, 0xa4, 0xcf, 0xc5, 0x98, 0x2b, 0xc1, 0xa8, 0xc0, 0xa8,
|
||||
0xc1, 0x6d, 0xa4, 0xa8, 0x87, 0xdb, 0x12, 0xbd, 0xe2, 0xd2, 0x24, 0x3d, 0xdf, 0x20, 0xc6, 0x5c,
|
||||
0x90, 0x86, 0x54, 0x09, 0x26, 0x05, 0x46, 0x0d, 0x3e, 0xc2, 0x1a, 0x5c, 0x83, 0x18, 0x53, 0x85,
|
||||
0xcc, 0xb9, 0x58, 0x73, 0xf2, 0x93, 0x13, 0x73, 0x24, 0x98, 0x09, 0xdb, 0xe2, 0x03, 0x52, 0x18,
|
||||
0x04, 0x51, 0xef, 0xe4, 0x18, 0x65, 0x9f, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f,
|
||||
0xab, 0x9f, 0x9e, 0x9f, 0x93, 0x98, 0x97, 0xae, 0x0f, 0xd6, 0x9a, 0x54, 0x9a, 0x06, 0x61, 0x24,
|
||||
0xeb, 0xa6, 0xa7, 0xe6, 0xe9, 0xa6, 0xe7, 0xeb, 0x83, 0xcc, 0x4a, 0x49, 0x2c, 0x49, 0xd4, 0x47,
|
||||
0x31, 0x2f, 0x80, 0x21, 0x80, 0x11, 0x10, 0x00, 0x00, 0xff, 0xff, 0x17, 0x83, 0x2d, 0xd4, 0x52,
|
||||
0x01, 0x00, 0x00,
|
||||
}
|
45
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/import_public/a.proto
generated
vendored
Normal file
45
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/import_public/a.proto
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
// Go support for Protocol Buffers - Google's data interchange format
|
||||
//
|
||||
// Copyright 2018 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 goproto.test.import_public;
|
||||
|
||||
option go_package = "github.com/golang/protobuf/protoc-gen-go/testdata/import_public";
|
||||
|
||||
import public "import_public/sub/a.proto"; // Different Go package.
|
||||
import public "import_public/b.proto"; // Same Go package.
|
||||
|
||||
message Public {
|
||||
optional goproto.test.import_public.sub.M m = 1;
|
||||
optional goproto.test.import_public.sub.E e = 2;
|
||||
optional Local local = 3;
|
||||
}
|
90
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/import_public/b.pb.go
generated
vendored
Normal file
90
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/import_public/b.pb.go
generated
vendored
Normal file
@ -0,0 +1,90 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: import_public/b.proto
|
||||
|
||||
package import_public
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
sub "github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub"
|
||||
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.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
type Local struct {
|
||||
M *sub.M `protobuf:"bytes,1,opt,name=m" json:"m,omitempty"`
|
||||
E *sub.E `protobuf:"varint,2,opt,name=e,enum=goproto.test.import_public.sub.E" json:"e,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Local) Reset() { *m = Local{} }
|
||||
func (m *Local) String() string { return proto.CompactTextString(m) }
|
||||
func (*Local) ProtoMessage() {}
|
||||
func (*Local) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_84995586b3d09710, []int{0}
|
||||
}
|
||||
|
||||
func (m *Local) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_Local.Unmarshal(m, b)
|
||||
}
|
||||
func (m *Local) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_Local.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *Local) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Local.Merge(m, src)
|
||||
}
|
||||
func (m *Local) XXX_Size() int {
|
||||
return xxx_messageInfo_Local.Size(m)
|
||||
}
|
||||
func (m *Local) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Local.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_Local proto.InternalMessageInfo
|
||||
|
||||
func (m *Local) GetM() *sub.M {
|
||||
if m != nil {
|
||||
return m.M
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Local) GetE() sub.E {
|
||||
if m != nil && m.E != nil {
|
||||
return *m.E
|
||||
}
|
||||
return sub.E_ZERO
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*Local)(nil), "goproto.test.import_public.Local")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("import_public/b.proto", fileDescriptor_84995586b3d09710) }
|
||||
|
||||
var fileDescriptor_84995586b3d09710 = []byte{
|
||||
// 169 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xcd, 0xcc, 0x2d, 0xc8,
|
||||
0x2f, 0x2a, 0x89, 0x2f, 0x28, 0x4d, 0xca, 0xc9, 0x4c, 0xd6, 0x4f, 0xd2, 0x2b, 0x28, 0xca, 0x2f,
|
||||
0xc9, 0x17, 0x92, 0x4a, 0xcf, 0x07, 0x33, 0xf4, 0x4a, 0x52, 0x8b, 0x4b, 0xf4, 0x50, 0xd4, 0x48,
|
||||
0x49, 0xa2, 0x6a, 0x29, 0x2e, 0x4d, 0xd2, 0x4f, 0x84, 0x68, 0x53, 0xca, 0xe4, 0x62, 0xf5, 0xc9,
|
||||
0x4f, 0x4e, 0xcc, 0x11, 0xd2, 0xe7, 0x62, 0xcc, 0x95, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x36, 0x52,
|
||||
0xd4, 0xc3, 0x6d, 0x96, 0x5e, 0x71, 0x69, 0x92, 0x9e, 0x6f, 0x10, 0x63, 0x2e, 0x48, 0x43, 0xaa,
|
||||
0x04, 0x93, 0x02, 0xa3, 0x06, 0x1f, 0x61, 0x0d, 0xae, 0x41, 0x8c, 0xa9, 0x4e, 0x8e, 0x51, 0xf6,
|
||||
0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xe9, 0xf9, 0x39, 0x89, 0x79,
|
||||
0xe9, 0xfa, 0x60, 0x6d, 0x49, 0xa5, 0x69, 0x10, 0x46, 0xb2, 0x6e, 0x7a, 0x6a, 0x9e, 0x6e, 0x7a,
|
||||
0xbe, 0x3e, 0xc8, 0x9c, 0x94, 0xc4, 0x92, 0x44, 0x7d, 0x14, 0xb3, 0x00, 0x01, 0x00, 0x00, 0xff,
|
||||
0xff, 0x35, 0x0e, 0x6a, 0x82, 0xfc, 0x00, 0x00, 0x00,
|
||||
}
|
43
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/import_public/b.proto
generated
vendored
Normal file
43
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/import_public/b.proto
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
// Go support for Protocol Buffers - Google's data interchange format
|
||||
//
|
||||
// Copyright 2018 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 goproto.test.import_public;
|
||||
|
||||
option go_package = "github.com/golang/protobuf/protoc-gen-go/testdata/import_public";
|
||||
|
||||
import "import_public/sub/a.proto";
|
||||
|
||||
message Local {
|
||||
optional goproto.test.import_public.sub.M m = 1;
|
||||
optional goproto.test.import_public.sub.E e = 2;
|
||||
}
|
85
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/import_public/importing/importing.pb.go
generated
vendored
Normal file
85
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/import_public/importing/importing.pb.go
generated
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: import_public/importing/importing.proto
|
||||
|
||||
package importing
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
_ "github.com/golang/protobuf/protoc-gen-go/testdata/import_public"
|
||||
sub "github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub"
|
||||
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.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
type M struct {
|
||||
// Message type defined in a file publicly imported by a file we import.
|
||||
M *sub.M `protobuf:"bytes,1,opt,name=m" json:"m,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *M) Reset() { *m = M{} }
|
||||
func (m *M) String() string { return proto.CompactTextString(m) }
|
||||
func (*M) ProtoMessage() {}
|
||||
func (*M) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_36b835b3b8f6171a, []int{0}
|
||||
}
|
||||
|
||||
func (m *M) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_M.Unmarshal(m, b)
|
||||
}
|
||||
func (m *M) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_M.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *M) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_M.Merge(m, src)
|
||||
}
|
||||
func (m *M) XXX_Size() int {
|
||||
return xxx_messageInfo_M.Size(m)
|
||||
}
|
||||
func (m *M) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_M.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_M proto.InternalMessageInfo
|
||||
|
||||
func (m *M) GetM() *sub.M {
|
||||
if m != nil {
|
||||
return m.M
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*M)(nil), "goproto.test.import_public.importing.M")
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterFile("import_public/importing/importing.proto", fileDescriptor_36b835b3b8f6171a)
|
||||
}
|
||||
|
||||
var fileDescriptor_36b835b3b8f6171a = []byte{
|
||||
// 153 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcf, 0xcc, 0x2d, 0xc8,
|
||||
0x2f, 0x2a, 0x89, 0x2f, 0x28, 0x4d, 0xca, 0xc9, 0x4c, 0xd6, 0x87, 0xf0, 0x32, 0xf3, 0xd2, 0x11,
|
||||
0x2c, 0xbd, 0x82, 0xa2, 0xfc, 0x92, 0x7c, 0x21, 0x95, 0xf4, 0x7c, 0x30, 0x43, 0xaf, 0x24, 0xb5,
|
||||
0xb8, 0x44, 0x0f, 0x45, 0x97, 0x1e, 0x5c, 0xad, 0x94, 0x28, 0xaa, 0x71, 0x89, 0x10, 0xcd, 0x4a,
|
||||
0x26, 0x5c, 0x8c, 0xbe, 0x42, 0xfa, 0x5c, 0x8c, 0xb9, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0xdc, 0x46,
|
||||
0x8a, 0x7a, 0x78, 0x4c, 0x2b, 0x2e, 0x4d, 0xd2, 0xf3, 0x0d, 0x62, 0xcc, 0x75, 0xf2, 0x8e, 0xf2,
|
||||
0x4c, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xcf, 0xcf, 0x49, 0xcc,
|
||||
0x4b, 0xd7, 0x07, 0x6b, 0x4b, 0x2a, 0x4d, 0x83, 0x30, 0x92, 0x75, 0xd3, 0x53, 0xf3, 0x74, 0xd3,
|
||||
0xf3, 0xf5, 0x41, 0xe6, 0xa4, 0x24, 0x96, 0x24, 0xea, 0xe3, 0xf0, 0x0f, 0x20, 0x00, 0x00, 0xff,
|
||||
0xff, 0xd8, 0x7e, 0x58, 0x1c, 0xe9, 0x00, 0x00, 0x00,
|
||||
}
|
43
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/import_public/importing/importing.proto
generated
vendored
Normal file
43
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/import_public/importing/importing.proto
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
// Go support for Protocol Buffers - Google's data interchange format
|
||||
//
|
||||
// Copyright 2018 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 goproto.test.import_public.importing;
|
||||
|
||||
option go_package = "github.com/golang/protobuf/protoc-gen-go/testdata/import_public/importing";
|
||||
|
||||
import "import_public/a.proto";
|
||||
|
||||
message M {
|
||||
// Message type defined in a file publicly imported by a file we import.
|
||||
optional goproto.test.import_public.sub.M m = 1;
|
||||
}
|
521
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub/a.pb.go
generated
vendored
Normal file
521
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub/a.pb.go
generated
vendored
Normal file
@ -0,0 +1,521 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: import_public/sub/a.proto
|
||||
|
||||
package sub
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
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.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
type E int32
|
||||
|
||||
const (
|
||||
E_ZERO E = 0
|
||||
)
|
||||
|
||||
var E_name = map[int32]string{
|
||||
0: "ZERO",
|
||||
}
|
||||
|
||||
var E_value = map[string]int32{
|
||||
"ZERO": 0,
|
||||
}
|
||||
|
||||
func (x E) Enum() *E {
|
||||
p := new(E)
|
||||
*p = x
|
||||
return p
|
||||
}
|
||||
|
||||
func (x E) String() string {
|
||||
return proto.EnumName(E_name, int32(x))
|
||||
}
|
||||
|
||||
func (x *E) UnmarshalJSON(data []byte) error {
|
||||
value, err := proto.UnmarshalJSONEnum(E_value, data, "E")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*x = E(value)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (E) EnumDescriptor() ([]byte, []int) {
|
||||
return fileDescriptor_382f7805394b5c4e, []int{0}
|
||||
}
|
||||
|
||||
type M_Subenum int32
|
||||
|
||||
const (
|
||||
M_M_ZERO M_Subenum = 0
|
||||
)
|
||||
|
||||
var M_Subenum_name = map[int32]string{
|
||||
0: "M_ZERO",
|
||||
}
|
||||
|
||||
var M_Subenum_value = map[string]int32{
|
||||
"M_ZERO": 0,
|
||||
}
|
||||
|
||||
func (x M_Subenum) Enum() *M_Subenum {
|
||||
p := new(M_Subenum)
|
||||
*p = x
|
||||
return p
|
||||
}
|
||||
|
||||
func (x M_Subenum) String() string {
|
||||
return proto.EnumName(M_Subenum_name, int32(x))
|
||||
}
|
||||
|
||||
func (x *M_Subenum) UnmarshalJSON(data []byte) error {
|
||||
value, err := proto.UnmarshalJSONEnum(M_Subenum_value, data, "M_Subenum")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*x = M_Subenum(value)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (M_Subenum) EnumDescriptor() ([]byte, []int) {
|
||||
return fileDescriptor_382f7805394b5c4e, []int{0, 0}
|
||||
}
|
||||
|
||||
type M_Submessage_Submessage_Subenum int32
|
||||
|
||||
const (
|
||||
M_Submessage_M_SUBMESSAGE_ZERO M_Submessage_Submessage_Subenum = 0
|
||||
)
|
||||
|
||||
var M_Submessage_Submessage_Subenum_name = map[int32]string{
|
||||
0: "M_SUBMESSAGE_ZERO",
|
||||
}
|
||||
|
||||
var M_Submessage_Submessage_Subenum_value = map[string]int32{
|
||||
"M_SUBMESSAGE_ZERO": 0,
|
||||
}
|
||||
|
||||
func (x M_Submessage_Submessage_Subenum) Enum() *M_Submessage_Submessage_Subenum {
|
||||
p := new(M_Submessage_Submessage_Subenum)
|
||||
*p = x
|
||||
return p
|
||||
}
|
||||
|
||||
func (x M_Submessage_Submessage_Subenum) String() string {
|
||||
return proto.EnumName(M_Submessage_Submessage_Subenum_name, int32(x))
|
||||
}
|
||||
|
||||
func (x *M_Submessage_Submessage_Subenum) UnmarshalJSON(data []byte) error {
|
||||
value, err := proto.UnmarshalJSONEnum(M_Submessage_Submessage_Subenum_value, data, "M_Submessage_Submessage_Subenum")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*x = M_Submessage_Submessage_Subenum(value)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (M_Submessage_Submessage_Subenum) EnumDescriptor() ([]byte, []int) {
|
||||
return fileDescriptor_382f7805394b5c4e, []int{0, 1, 0}
|
||||
}
|
||||
|
||||
type M struct {
|
||||
// Field using a type in the same Go package, but a different source file.
|
||||
M2 *M2 `protobuf:"bytes,1,opt,name=m2" json:"m2,omitempty"`
|
||||
// Types that are valid to be assigned to OneofField:
|
||||
// *M_OneofInt32
|
||||
// *M_OneofInt64
|
||||
OneofField isM_OneofField `protobuf_oneof:"oneof_field"`
|
||||
Grouping *M_Grouping `protobuf:"group,4,opt,name=Grouping,json=grouping" json:"grouping,omitempty"`
|
||||
DefaultField *string `protobuf:"bytes,6,opt,name=default_field,json=defaultField,def=def" json:"default_field,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *M) Reset() { *m = M{} }
|
||||
func (m *M) String() string { return proto.CompactTextString(m) }
|
||||
func (*M) ProtoMessage() {}
|
||||
func (*M) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_382f7805394b5c4e, []int{0}
|
||||
}
|
||||
|
||||
func (m *M) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_M.Unmarshal(m, b)
|
||||
}
|
||||
func (m *M) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_M.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *M) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_M.Merge(m, src)
|
||||
}
|
||||
func (m *M) XXX_Size() int {
|
||||
return xxx_messageInfo_M.Size(m)
|
||||
}
|
||||
func (m *M) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_M.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_M proto.InternalMessageInfo
|
||||
|
||||
const Default_M_DefaultField string = "def"
|
||||
|
||||
func (m *M) GetM2() *M2 {
|
||||
if m != nil {
|
||||
return m.M2
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type isM_OneofField interface {
|
||||
isM_OneofField()
|
||||
}
|
||||
|
||||
type M_OneofInt32 struct {
|
||||
OneofInt32 int32 `protobuf:"varint,2,opt,name=oneof_int32,json=oneofInt32,oneof"`
|
||||
}
|
||||
|
||||
type M_OneofInt64 struct {
|
||||
OneofInt64 int64 `protobuf:"varint,3,opt,name=oneof_int64,json=oneofInt64,oneof"`
|
||||
}
|
||||
|
||||
func (*M_OneofInt32) isM_OneofField() {}
|
||||
|
||||
func (*M_OneofInt64) isM_OneofField() {}
|
||||
|
||||
func (m *M) GetOneofField() isM_OneofField {
|
||||
if m != nil {
|
||||
return m.OneofField
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *M) GetOneofInt32() int32 {
|
||||
if x, ok := m.GetOneofField().(*M_OneofInt32); ok {
|
||||
return x.OneofInt32
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *M) GetOneofInt64() int64 {
|
||||
if x, ok := m.GetOneofField().(*M_OneofInt64); ok {
|
||||
return x.OneofInt64
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *M) GetGrouping() *M_Grouping {
|
||||
if m != nil {
|
||||
return m.Grouping
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *M) GetDefaultField() string {
|
||||
if m != nil && m.DefaultField != nil {
|
||||
return *m.DefaultField
|
||||
}
|
||||
return Default_M_DefaultField
|
||||
}
|
||||
|
||||
// XXX_OneofFuncs is for the internal use of the proto package.
|
||||
func (*M) 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 _M_OneofMarshaler, _M_OneofUnmarshaler, _M_OneofSizer, []interface{}{
|
||||
(*M_OneofInt32)(nil),
|
||||
(*M_OneofInt64)(nil),
|
||||
}
|
||||
}
|
||||
|
||||
func _M_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
|
||||
m := msg.(*M)
|
||||
// oneof_field
|
||||
switch x := m.OneofField.(type) {
|
||||
case *M_OneofInt32:
|
||||
b.EncodeVarint(2<<3 | proto.WireVarint)
|
||||
b.EncodeVarint(uint64(x.OneofInt32))
|
||||
case *M_OneofInt64:
|
||||
b.EncodeVarint(3<<3 | proto.WireVarint)
|
||||
b.EncodeVarint(uint64(x.OneofInt64))
|
||||
case nil:
|
||||
default:
|
||||
return fmt.Errorf("M.OneofField has unexpected type %T", x)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func _M_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
|
||||
m := msg.(*M)
|
||||
switch tag {
|
||||
case 2: // oneof_field.oneof_int32
|
||||
if wire != proto.WireVarint {
|
||||
return true, proto.ErrInternalBadWireType
|
||||
}
|
||||
x, err := b.DecodeVarint()
|
||||
m.OneofField = &M_OneofInt32{int32(x)}
|
||||
return true, err
|
||||
case 3: // oneof_field.oneof_int64
|
||||
if wire != proto.WireVarint {
|
||||
return true, proto.ErrInternalBadWireType
|
||||
}
|
||||
x, err := b.DecodeVarint()
|
||||
m.OneofField = &M_OneofInt64{int64(x)}
|
||||
return true, err
|
||||
default:
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
func _M_OneofSizer(msg proto.Message) (n int) {
|
||||
m := msg.(*M)
|
||||
// oneof_field
|
||||
switch x := m.OneofField.(type) {
|
||||
case *M_OneofInt32:
|
||||
n += 1 // tag and wire
|
||||
n += proto.SizeVarint(uint64(x.OneofInt32))
|
||||
case *M_OneofInt64:
|
||||
n += 1 // tag and wire
|
||||
n += proto.SizeVarint(uint64(x.OneofInt64))
|
||||
case nil:
|
||||
default:
|
||||
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
type M_Grouping struct {
|
||||
GroupField *string `protobuf:"bytes,5,opt,name=group_field,json=groupField" json:"group_field,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *M_Grouping) Reset() { *m = M_Grouping{} }
|
||||
func (m *M_Grouping) String() string { return proto.CompactTextString(m) }
|
||||
func (*M_Grouping) ProtoMessage() {}
|
||||
func (*M_Grouping) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_382f7805394b5c4e, []int{0, 0}
|
||||
}
|
||||
|
||||
func (m *M_Grouping) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_M_Grouping.Unmarshal(m, b)
|
||||
}
|
||||
func (m *M_Grouping) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_M_Grouping.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *M_Grouping) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_M_Grouping.Merge(m, src)
|
||||
}
|
||||
func (m *M_Grouping) XXX_Size() int {
|
||||
return xxx_messageInfo_M_Grouping.Size(m)
|
||||
}
|
||||
func (m *M_Grouping) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_M_Grouping.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_M_Grouping proto.InternalMessageInfo
|
||||
|
||||
func (m *M_Grouping) GetGroupField() string {
|
||||
if m != nil && m.GroupField != nil {
|
||||
return *m.GroupField
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type M_Submessage struct {
|
||||
// Types that are valid to be assigned to SubmessageOneofField:
|
||||
// *M_Submessage_SubmessageOneofInt32
|
||||
// *M_Submessage_SubmessageOneofInt64
|
||||
SubmessageOneofField isM_Submessage_SubmessageOneofField `protobuf_oneof:"submessage_oneof_field"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *M_Submessage) Reset() { *m = M_Submessage{} }
|
||||
func (m *M_Submessage) String() string { return proto.CompactTextString(m) }
|
||||
func (*M_Submessage) ProtoMessage() {}
|
||||
func (*M_Submessage) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_382f7805394b5c4e, []int{0, 1}
|
||||
}
|
||||
|
||||
func (m *M_Submessage) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_M_Submessage.Unmarshal(m, b)
|
||||
}
|
||||
func (m *M_Submessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_M_Submessage.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *M_Submessage) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_M_Submessage.Merge(m, src)
|
||||
}
|
||||
func (m *M_Submessage) XXX_Size() int {
|
||||
return xxx_messageInfo_M_Submessage.Size(m)
|
||||
}
|
||||
func (m *M_Submessage) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_M_Submessage.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_M_Submessage proto.InternalMessageInfo
|
||||
|
||||
type isM_Submessage_SubmessageOneofField interface {
|
||||
isM_Submessage_SubmessageOneofField()
|
||||
}
|
||||
|
||||
type M_Submessage_SubmessageOneofInt32 struct {
|
||||
SubmessageOneofInt32 int32 `protobuf:"varint,1,opt,name=submessage_oneof_int32,json=submessageOneofInt32,oneof"`
|
||||
}
|
||||
|
||||
type M_Submessage_SubmessageOneofInt64 struct {
|
||||
SubmessageOneofInt64 int64 `protobuf:"varint,2,opt,name=submessage_oneof_int64,json=submessageOneofInt64,oneof"`
|
||||
}
|
||||
|
||||
func (*M_Submessage_SubmessageOneofInt32) isM_Submessage_SubmessageOneofField() {}
|
||||
|
||||
func (*M_Submessage_SubmessageOneofInt64) isM_Submessage_SubmessageOneofField() {}
|
||||
|
||||
func (m *M_Submessage) GetSubmessageOneofField() isM_Submessage_SubmessageOneofField {
|
||||
if m != nil {
|
||||
return m.SubmessageOneofField
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *M_Submessage) GetSubmessageOneofInt32() int32 {
|
||||
if x, ok := m.GetSubmessageOneofField().(*M_Submessage_SubmessageOneofInt32); ok {
|
||||
return x.SubmessageOneofInt32
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *M_Submessage) GetSubmessageOneofInt64() int64 {
|
||||
if x, ok := m.GetSubmessageOneofField().(*M_Submessage_SubmessageOneofInt64); ok {
|
||||
return x.SubmessageOneofInt64
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// XXX_OneofFuncs is for the internal use of the proto package.
|
||||
func (*M_Submessage) 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 _M_Submessage_OneofMarshaler, _M_Submessage_OneofUnmarshaler, _M_Submessage_OneofSizer, []interface{}{
|
||||
(*M_Submessage_SubmessageOneofInt32)(nil),
|
||||
(*M_Submessage_SubmessageOneofInt64)(nil),
|
||||
}
|
||||
}
|
||||
|
||||
func _M_Submessage_OneofMarshaler(msg proto.Message, b *proto.Buffer) error {
|
||||
m := msg.(*M_Submessage)
|
||||
// submessage_oneof_field
|
||||
switch x := m.SubmessageOneofField.(type) {
|
||||
case *M_Submessage_SubmessageOneofInt32:
|
||||
b.EncodeVarint(1<<3 | proto.WireVarint)
|
||||
b.EncodeVarint(uint64(x.SubmessageOneofInt32))
|
||||
case *M_Submessage_SubmessageOneofInt64:
|
||||
b.EncodeVarint(2<<3 | proto.WireVarint)
|
||||
b.EncodeVarint(uint64(x.SubmessageOneofInt64))
|
||||
case nil:
|
||||
default:
|
||||
return fmt.Errorf("M_Submessage.SubmessageOneofField has unexpected type %T", x)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func _M_Submessage_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) {
|
||||
m := msg.(*M_Submessage)
|
||||
switch tag {
|
||||
case 1: // submessage_oneof_field.submessage_oneof_int32
|
||||
if wire != proto.WireVarint {
|
||||
return true, proto.ErrInternalBadWireType
|
||||
}
|
||||
x, err := b.DecodeVarint()
|
||||
m.SubmessageOneofField = &M_Submessage_SubmessageOneofInt32{int32(x)}
|
||||
return true, err
|
||||
case 2: // submessage_oneof_field.submessage_oneof_int64
|
||||
if wire != proto.WireVarint {
|
||||
return true, proto.ErrInternalBadWireType
|
||||
}
|
||||
x, err := b.DecodeVarint()
|
||||
m.SubmessageOneofField = &M_Submessage_SubmessageOneofInt64{int64(x)}
|
||||
return true, err
|
||||
default:
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
func _M_Submessage_OneofSizer(msg proto.Message) (n int) {
|
||||
m := msg.(*M_Submessage)
|
||||
// submessage_oneof_field
|
||||
switch x := m.SubmessageOneofField.(type) {
|
||||
case *M_Submessage_SubmessageOneofInt32:
|
||||
n += 1 // tag and wire
|
||||
n += proto.SizeVarint(uint64(x.SubmessageOneofInt32))
|
||||
case *M_Submessage_SubmessageOneofInt64:
|
||||
n += 1 // tag and wire
|
||||
n += proto.SizeVarint(uint64(x.SubmessageOneofInt64))
|
||||
case nil:
|
||||
default:
|
||||
panic(fmt.Sprintf("proto: unexpected type %T in oneof", x))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
var E_ExtensionField = &proto.ExtensionDesc{
|
||||
ExtendedType: (*M2)(nil),
|
||||
ExtensionType: (*string)(nil),
|
||||
Field: 1,
|
||||
Name: "goproto.test.import_public.sub.extension_field",
|
||||
Tag: "bytes,1,opt,name=extension_field",
|
||||
Filename: "import_public/sub/a.proto",
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterEnum("goproto.test.import_public.sub.E", E_name, E_value)
|
||||
proto.RegisterEnum("goproto.test.import_public.sub.M_Subenum", M_Subenum_name, M_Subenum_value)
|
||||
proto.RegisterEnum("goproto.test.import_public.sub.M_Submessage_Submessage_Subenum", M_Submessage_Submessage_Subenum_name, M_Submessage_Submessage_Subenum_value)
|
||||
proto.RegisterType((*M)(nil), "goproto.test.import_public.sub.M")
|
||||
proto.RegisterType((*M_Grouping)(nil), "goproto.test.import_public.sub.M.Grouping")
|
||||
proto.RegisterType((*M_Submessage)(nil), "goproto.test.import_public.sub.M.Submessage")
|
||||
proto.RegisterExtension(E_ExtensionField)
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("import_public/sub/a.proto", fileDescriptor_382f7805394b5c4e) }
|
||||
|
||||
var fileDescriptor_382f7805394b5c4e = []byte{
|
||||
// 410 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xcf, 0x6e, 0xd3, 0x40,
|
||||
0x10, 0xc6, 0xbb, 0x49, 0x5a, 0xd2, 0x09, 0xe1, 0xcf, 0x8a, 0x22, 0xd3, 0x03, 0x98, 0x9c, 0xac,
|
||||
0x56, 0x5d, 0x4b, 0x26, 0xf2, 0xa1, 0x37, 0x82, 0xdc, 0x82, 0x90, 0x55, 0xc9, 0x16, 0x97, 0x5e,
|
||||
0x2c, 0x6f, 0xbc, 0x5e, 0x2c, 0xd9, 0xbb, 0x56, 0xbc, 0x2b, 0xf1, 0x08, 0xbc, 0x17, 0x2f, 0x86,
|
||||
0xbc, 0xb6, 0x93, 0x46, 0x04, 0xe8, 0x6d, 0x3d, 0xf3, 0xfd, 0xbe, 0xd1, 0x7c, 0x1e, 0x78, 0x53,
|
||||
0x54, 0xb5, 0xdc, 0xa8, 0xa4, 0xd6, 0xb4, 0x2c, 0xd6, 0x6e, 0xa3, 0xa9, 0x9b, 0x92, 0x7a, 0x23,
|
||||
0x95, 0xc4, 0x6f, 0xb9, 0x34, 0x0f, 0xa2, 0x58, 0xa3, 0xc8, 0x9e, 0x8e, 0x34, 0x9a, 0x9e, 0x1f,
|
||||
0x40, 0x69, 0x87, 0x2e, 0x7e, 0x4e, 0x00, 0x85, 0xd8, 0x83, 0x51, 0xe5, 0x59, 0xc8, 0x46, 0xce,
|
||||
0xcc, 0x5b, 0x90, 0x7f, 0xbb, 0x91, 0xd0, 0x8b, 0x46, 0x95, 0x87, 0xdf, 0xc3, 0x4c, 0x0a, 0x26,
|
||||
0xf3, 0xa4, 0x10, 0xea, 0x83, 0x67, 0x8d, 0x6c, 0xe4, 0x1c, 0x7f, 0x3e, 0x8a, 0xc0, 0x14, 0xbf,
|
||||
0xb4, 0xb5, 0x3d, 0x89, 0xbf, 0xb4, 0xc6, 0x36, 0x72, 0xc6, 0x0f, 0x25, 0xfe, 0x12, 0xdf, 0xc0,
|
||||
0x94, 0x6f, 0xa4, 0xae, 0x0b, 0xc1, 0xad, 0x89, 0x8d, 0x1c, 0xf0, 0x2e, 0xfe, 0x3b, 0x9f, 0xdc,
|
||||
0xf6, 0x44, 0xb4, 0x65, 0xb1, 0x03, 0xf3, 0x8c, 0xe5, 0xa9, 0x2e, 0x55, 0x92, 0x17, 0xac, 0xcc,
|
||||
0xac, 0x13, 0x1b, 0x39, 0xa7, 0xd7, 0xe3, 0x8c, 0xe5, 0xd1, 0xd3, 0xbe, 0x73, 0xd3, 0x36, 0xce,
|
||||
0x2f, 0x61, 0x3a, 0xf0, 0xf8, 0x1d, 0xcc, 0x8c, 0x43, 0xcf, 0x1c, 0xb7, 0x4c, 0x04, 0xa6, 0xd4,
|
||||
0x89, 0x7f, 0x21, 0x80, 0x58, 0xd3, 0x8a, 0x35, 0x4d, 0xca, 0x19, 0xf6, 0xe1, 0x75, 0xb3, 0xfd,
|
||||
0x4a, 0x1e, 0xae, 0x8f, 0xfa, 0xf5, 0x5f, 0xed, 0xfa, 0x77, 0xbb, 0x20, 0xfe, 0xc2, 0xf9, 0x4b,
|
||||
0x13, 0xdb, 0xf8, 0x30, 0xe7, 0x2f, 0x17, 0x97, 0x80, 0x77, 0xd3, 0x93, 0x58, 0x53, 0x26, 0x74,
|
||||
0x85, 0xcf, 0xe0, 0x65, 0x98, 0xc4, 0xdf, 0x56, 0x61, 0x10, 0xc7, 0x1f, 0x6f, 0x83, 0xe4, 0x3e,
|
||||
0x88, 0xee, 0x5e, 0x1c, 0xad, 0xac, 0x03, 0x43, 0xcc, 0x5e, 0x8b, 0x33, 0x78, 0x32, 0xb0, 0x00,
|
||||
0x27, 0xe1, 0x00, 0xcc, 0x87, 0xdf, 0x63, 0x54, 0x17, 0x73, 0x40, 0x01, 0x9e, 0xc2, 0xa4, 0xeb,
|
||||
0x5e, 0x7f, 0x85, 0xe7, 0xec, 0x87, 0x62, 0xa2, 0x29, 0xa4, 0xe8, 0x14, 0xf8, 0x11, 0xa7, 0x61,
|
||||
0x82, 0x38, 0x8d, 0x9e, 0x6d, 0x51, 0x93, 0xe3, 0x2a, 0xb8, 0xff, 0xc4, 0x0b, 0xf5, 0x5d, 0x53,
|
||||
0xb2, 0x96, 0x95, 0xcb, 0x65, 0x99, 0x0a, 0xee, 0x1a, 0x2b, 0xaa, 0xf3, 0xee, 0xb1, 0xbe, 0xe2,
|
||||
0x4c, 0x5c, 0x71, 0xe9, 0xb6, 0xde, 0x59, 0xaa, 0x52, 0xf7, 0x8f, 0xab, 0xfd, 0x1d, 0x00, 0x00,
|
||||
0xff, 0xff, 0x13, 0x4f, 0x31, 0x07, 0x04, 0x03, 0x00, 0x00,
|
||||
}
|
77
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub/a.proto
generated
vendored
Normal file
77
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub/a.proto
generated
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
// Go support for Protocol Buffers - Google's data interchange format
|
||||
//
|
||||
// Copyright 2018 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 goproto.test.import_public.sub;
|
||||
|
||||
option go_package = "github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub";
|
||||
|
||||
import "import_public/sub/b.proto";
|
||||
|
||||
message M {
|
||||
// Field using a type in the same Go package, but a different source file.
|
||||
optional M2 m2 = 1;
|
||||
|
||||
oneof oneof_field {
|
||||
int32 oneof_int32 = 2;
|
||||
int64 oneof_int64 = 3;
|
||||
}
|
||||
|
||||
optional group Grouping = 4 {
|
||||
optional string group_field = 5;
|
||||
}
|
||||
|
||||
optional string default_field = 6 [default="def"];
|
||||
|
||||
message Submessage {
|
||||
enum Submessage_Subenum {
|
||||
M_SUBMESSAGE_ZERO = 0;
|
||||
}
|
||||
|
||||
oneof submessage_oneof_field {
|
||||
int32 submessage_oneof_int32 = 1;
|
||||
int64 submessage_oneof_int64 = 2;
|
||||
}
|
||||
}
|
||||
|
||||
enum Subenum {
|
||||
M_ZERO = 0;
|
||||
}
|
||||
}
|
||||
|
||||
enum E {
|
||||
ZERO = 0;
|
||||
}
|
||||
|
||||
extend M2 {
|
||||
optional string extension_field = 1;
|
||||
}
|
80
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub/b.pb.go
generated
vendored
Normal file
80
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub/b.pb.go
generated
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: import_public/sub/b.proto
|
||||
|
||||
package sub
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
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.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
type M2 struct {
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
proto.XXX_InternalExtensions `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *M2) Reset() { *m = M2{} }
|
||||
func (m *M2) String() string { return proto.CompactTextString(m) }
|
||||
func (*M2) ProtoMessage() {}
|
||||
func (*M2) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_fc66afda3d7c2232, []int{0}
|
||||
}
|
||||
|
||||
var extRange_M2 = []proto.ExtensionRange{
|
||||
{Start: 1, End: 536870911},
|
||||
}
|
||||
|
||||
func (*M2) ExtensionRangeArray() []proto.ExtensionRange {
|
||||
return extRange_M2
|
||||
}
|
||||
|
||||
func (m *M2) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_M2.Unmarshal(m, b)
|
||||
}
|
||||
func (m *M2) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_M2.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *M2) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_M2.Merge(m, src)
|
||||
}
|
||||
func (m *M2) XXX_Size() int {
|
||||
return xxx_messageInfo_M2.Size(m)
|
||||
}
|
||||
func (m *M2) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_M2.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_M2 proto.InternalMessageInfo
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*M2)(nil), "goproto.test.import_public.sub.M2")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("import_public/sub/b.proto", fileDescriptor_fc66afda3d7c2232) }
|
||||
|
||||
var fileDescriptor_fc66afda3d7c2232 = []byte{
|
||||
// 132 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcc, 0xcc, 0x2d, 0xc8,
|
||||
0x2f, 0x2a, 0x89, 0x2f, 0x28, 0x4d, 0xca, 0xc9, 0x4c, 0xd6, 0x2f, 0x2e, 0x4d, 0xd2, 0x4f, 0xd2,
|
||||
0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x4b, 0xcf, 0x07, 0x33, 0xf4, 0x4a, 0x52, 0x8b, 0x4b,
|
||||
0xf4, 0x50, 0xd4, 0xe9, 0x15, 0x97, 0x26, 0x29, 0xf1, 0x71, 0x31, 0xf9, 0x1a, 0x69, 0x71, 0x70,
|
||||
0x30, 0x0a, 0x34, 0x34, 0x34, 0x34, 0x30, 0x39, 0xb9, 0x46, 0x39, 0xa7, 0x67, 0x96, 0x64, 0x94,
|
||||
0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0xa7, 0xe7, 0xe7, 0x24, 0xe6, 0xa5, 0xeb, 0x83, 0x4d, 0x48,
|
||||
0x2a, 0x4d, 0x83, 0x30, 0x92, 0x75, 0xd3, 0x53, 0xf3, 0x74, 0xd3, 0xf3, 0xf5, 0x41, 0x46, 0xa6,
|
||||
0x24, 0x96, 0x24, 0xea, 0x63, 0x58, 0x0f, 0x08, 0x00, 0x00, 0xff, 0xff, 0x87, 0x44, 0x22, 0x2d,
|
||||
0x92, 0x00, 0x00, 0x00,
|
||||
}
|
40
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub/b.proto
generated
vendored
Normal file
40
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub/b.proto
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
// Go support for Protocol Buffers - Google's data interchange format
|
||||
//
|
||||
// Copyright 2018 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 goproto.test.import_public.sub;
|
||||
|
||||
option go_package = "github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub";
|
||||
|
||||
message M2 {
|
||||
extensions 1 to max;
|
||||
}
|
@ -29,42 +29,38 @@
|
||||
// (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";
|
||||
// +build go1.9
|
||||
|
||||
package imp;
|
||||
package testdata
|
||||
|
||||
import "imp2.proto";
|
||||
import "imp3.proto";
|
||||
import (
|
||||
"testing"
|
||||
|
||||
message ImportedMessage {
|
||||
required int64 field = 1;
|
||||
mainpb "github.com/golang/protobuf/protoc-gen-go/testdata/import_public"
|
||||
subpb "github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub"
|
||||
)
|
||||
|
||||
// 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<string, ImportedMessage2> 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;
|
||||
func TestImportPublicLink(t *testing.T) {
|
||||
// mainpb.[ME] should be interchangable with subpb.[ME].
|
||||
var _ mainpb.M = subpb.M{}
|
||||
var _ mainpb.E = subpb.E(0)
|
||||
_ = &mainpb.Public{
|
||||
M: &mainpb.M{},
|
||||
E: mainpb.E_ZERO.Enum(),
|
||||
Local: &mainpb.Local{
|
||||
M: &mainpb.M{},
|
||||
E: mainpb.E_ZERO.Enum(),
|
||||
},
|
||||
}
|
||||
_ = &mainpb.Public{
|
||||
M: &subpb.M{},
|
||||
E: subpb.E_ZERO.Enum(),
|
||||
Local: &mainpb.Local{
|
||||
M: &subpb.M{},
|
||||
E: subpb.E_ZERO.Enum(),
|
||||
},
|
||||
}
|
||||
_ = &mainpb.M{
|
||||
M2: &subpb.M2{},
|
||||
}
|
||||
}
|
69
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/imports/fmt/m.pb.go
generated
vendored
Normal file
69
vendor/github.com/golang/protobuf/protoc-gen-go/testdata/imports/fmt/m.pb.go
generated
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: imports/fmt/m.proto
|
||||
|
||||
package fmt
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
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.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
type M struct {
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *M) Reset() { *m = M{} }
|
||||
func (m *M) String() string { return proto.CompactTextString(m) }
|
||||
func (*M) ProtoMessage() {}
|
||||
func (*M) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_72c126fcd452e392, []int{0}
|
||||
}
|
||||
|
||||
func (m *M) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_M.Unmarshal(m, b)
|
||||
}
|
||||
func (m *M) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_M.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *M) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_M.Merge(m, src)
|
||||
}
|
||||
func (m *M) XXX_Size() int {
|
||||
return xxx_messageInfo_M.Size(m)
|
||||
}
|
||||
func (m *M) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_M.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_M proto.InternalMessageInfo
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*M)(nil), "fmt.M")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("imports/fmt/m.proto", fileDescriptor_72c126fcd452e392) }
|
||||
|
||||
var fileDescriptor_72c126fcd452e392 = []byte{
|
||||
// 109 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xce, 0xcc, 0x2d, 0xc8,
|
||||
0x2f, 0x2a, 0x29, 0xd6, 0x4f, 0xcb, 0x2d, 0xd1, 0xcf, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17,
|
||||
0x62, 0x4e, 0xcb, 0x2d, 0x51, 0x62, 0xe6, 0x62, 0xf4, 0x75, 0xb2, 0x8f, 0xb2, 0x4d, 0xcf, 0x2c,
|
||||
0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xcf, 0xcf, 0x49, 0xcc, 0x4b, 0xd7, 0x07,
|
||||
0x2b, 0x4a, 0x2a, 0x4d, 0x83, 0x30, 0x92, 0x75, 0xd3, 0x53, 0xf3, 0x74, 0xd3, 0xf3, 0xf5, 0x4b,
|
||||
0x52, 0x8b, 0x4b, 0x52, 0x12, 0x4b, 0x12, 0xf5, 0x91, 0x8c, 0x4c, 0x62, 0x03, 0xab, 0x31, 0x06,
|
||||
0x04, 0x00, 0x00, 0xff, 0xff, 0xc4, 0xc9, 0xee, 0xbe, 0x68, 0x00, 0x00, 0x00,
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user