1// Copyright 2010 The Go Authors.  All rights reserved.
2// http://github.com/golang/protobuf/
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8//     * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10//     * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14//     * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30package pbutil
31
32import (
33	. "github.com/golang/protobuf/proto"
34	. "github.com/golang/protobuf/proto/testdata"
35)
36
37// FROM https://github.com/golang/protobuf/blob/master/proto/all_test.go.
38
39func initGoTestField() *GoTestField {
40	f := new(GoTestField)
41	f.Label = String("label")
42	f.Type = String("type")
43	return f
44}
45
46// These are all structurally equivalent but the tag numbers differ.
47// (It's remarkable that required, optional, and repeated all have
48// 8 letters.)
49func initGoTest_RequiredGroup() *GoTest_RequiredGroup {
50	return &GoTest_RequiredGroup{
51		RequiredField: String("required"),
52	}
53}
54
55func initGoTest_OptionalGroup() *GoTest_OptionalGroup {
56	return &GoTest_OptionalGroup{
57		RequiredField: String("optional"),
58	}
59}
60
61func initGoTest_RepeatedGroup() *GoTest_RepeatedGroup {
62	return &GoTest_RepeatedGroup{
63		RequiredField: String("repeated"),
64	}
65}
66
67func initGoTest(setdefaults bool) *GoTest {
68	pb := new(GoTest)
69	if setdefaults {
70		pb.F_BoolDefaulted = Bool(Default_GoTest_F_BoolDefaulted)
71		pb.F_Int32Defaulted = Int32(Default_GoTest_F_Int32Defaulted)
72		pb.F_Int64Defaulted = Int64(Default_GoTest_F_Int64Defaulted)
73		pb.F_Fixed32Defaulted = Uint32(Default_GoTest_F_Fixed32Defaulted)
74		pb.F_Fixed64Defaulted = Uint64(Default_GoTest_F_Fixed64Defaulted)
75		pb.F_Uint32Defaulted = Uint32(Default_GoTest_F_Uint32Defaulted)
76		pb.F_Uint64Defaulted = Uint64(Default_GoTest_F_Uint64Defaulted)
77		pb.F_FloatDefaulted = Float32(Default_GoTest_F_FloatDefaulted)
78		pb.F_DoubleDefaulted = Float64(Default_GoTest_F_DoubleDefaulted)
79		pb.F_StringDefaulted = String(Default_GoTest_F_StringDefaulted)
80		pb.F_BytesDefaulted = Default_GoTest_F_BytesDefaulted
81		pb.F_Sint32Defaulted = Int32(Default_GoTest_F_Sint32Defaulted)
82		pb.F_Sint64Defaulted = Int64(Default_GoTest_F_Sint64Defaulted)
83	}
84
85	pb.Kind = GoTest_TIME.Enum()
86	pb.RequiredField = initGoTestField()
87	pb.F_BoolRequired = Bool(true)
88	pb.F_Int32Required = Int32(3)
89	pb.F_Int64Required = Int64(6)
90	pb.F_Fixed32Required = Uint32(32)
91	pb.F_Fixed64Required = Uint64(64)
92	pb.F_Uint32Required = Uint32(3232)
93	pb.F_Uint64Required = Uint64(6464)
94	pb.F_FloatRequired = Float32(3232)
95	pb.F_DoubleRequired = Float64(6464)
96	pb.F_StringRequired = String("string")
97	pb.F_BytesRequired = []byte("bytes")
98	pb.F_Sint32Required = Int32(-32)
99	pb.F_Sint64Required = Int64(-64)
100	pb.Requiredgroup = initGoTest_RequiredGroup()
101
102	return pb
103}
104