├── .gitattributes
├── .gitignore
├── Cache
└── CSharp
│ └── Message
│ └── Server
│ └── Register
│ ├── ServerRegister.cs
│ └── ServerRegisterIdGenerator.cs
├── Google.Protobuf
├── ByteArray.cs
├── ByteString.cs
├── CodedInputStream.cs
├── CodedOutputStream.ComputeSize.cs
├── CodedOutputStream.cs
├── Collections
│ ├── Lists.cs
│ ├── MapField.cs
│ ├── ProtobufEqualityComparers.cs
│ ├── ReadOnlyDictionary.cs
│ └── RepeatedField.cs
├── Compatibility
│ ├── MethodInfoExtensions.cs
│ ├── PropertyInfoExtensions.cs
│ ├── StreamExtensions.cs
│ └── TypeExtensions.cs
├── FieldCodec.cs
├── FrameworkPortability.cs
├── Google.Protobuf.csproj
├── Google.Protobuf.snk
├── ICustomDiagnosticMessage.cs
├── IDeepCloneable.cs
├── IMessage.cs
├── InvalidJsonException.cs
├── InvalidProtocolBufferException.cs
├── JsonFormatter.cs
├── JsonParser.cs
├── JsonToken.cs
├── JsonTokenizer.cs
├── LimitedInputStream.cs
├── MessageExtensions.cs
├── MessageParser.cs
├── Properties
│ └── AssemblyInfo.cs
├── ProtoPreconditions.cs
├── Reflection
│ ├── CustomOptions.cs
│ ├── Descriptor.cs
│ ├── DescriptorBase.cs
│ ├── DescriptorPool.cs
│ ├── DescriptorUtil.cs
│ ├── DescriptorValidationException.cs
│ ├── EnumDescriptor.cs
│ ├── EnumValueDescriptor.cs
│ ├── FieldAccessorBase.cs
│ ├── FieldDescriptor.cs
│ ├── FieldType.cs
│ ├── FileDescriptor.cs
│ ├── GeneratedClrTypeInfo.cs
│ ├── IDescriptor.cs
│ ├── IFieldAccessor.cs
│ ├── MapFieldAccessor.cs
│ ├── MessageDescriptor.cs
│ ├── MethodDescriptor.cs
│ ├── OneofAccessor.cs
│ ├── OneofDescriptor.cs
│ ├── OriginalNameAttribute.cs
│ ├── PackageDescriptor.cs
│ ├── PartialClasses.cs
│ ├── ReflectionUtil.cs
│ ├── RepeatedFieldAccessor.cs
│ ├── ServiceDescriptor.cs
│ ├── SingleFieldAccessor.cs
│ └── TypeRegistry.cs
├── UnknownField.cs
├── UnknownFieldSet.cs
├── WellKnownTypes
│ ├── Any.cs
│ ├── AnyPartial.cs
│ ├── Api.cs
│ ├── Duration.cs
│ ├── DurationPartial.cs
│ ├── Empty.cs
│ ├── FieldMask.cs
│ ├── FieldMaskPartial.cs
│ ├── SourceContext.cs
│ ├── Struct.cs
│ ├── TimeExtensions.cs
│ ├── Timestamp.cs
│ ├── TimestampPartial.cs
│ ├── Type.cs
│ ├── ValuePartial.cs
│ ├── Wrappers.cs
│ └── WrappersPartial.cs
└── WireFormat.cs
├── Output
└── net35
│ ├── Generator.exe
│ ├── Google.Protobuf.dll
│ ├── Google.Protobuf.xml
│ ├── ProtocolGenerator.exe
│ └── google_protoc
│ └── protoc.exe
├── ProtobufHelper
├── Properties
│ └── AssemblyInfo.cs
├── ProtobufHelper.cs
└── ProtobufHelper.csproj
├── ProtocolBuilder
├── IdGenerator
│ ├── Id.code
│ └── Id.proto
├── ProtocolBuilder.vcxproj
├── ProtocolBuilder.vcxproj.filters
└── Server
│ ├── ServerRegister.code
│ └── ServerRegister.proto
├── ProtocolGenerator.sln
├── ProtocolGenerator
├── Core
│ ├── AbstractFileModel.cs
│ ├── CSharp
│ │ ├── CSharpClass_Id.cs
│ │ ├── CSharpClass_IdGenerater.cs
│ │ ├── CSharpClass_Proto.cs
│ │ ├── CSharpCodeGenerater.cs
│ │ └── CSharpGenerater.cs
│ ├── Data
│ │ ├── Data.cs
│ │ ├── DataManager.cs
│ │ └── DataParser.cs
│ ├── EnumType.cs
│ ├── GeneraterCache.cs
│ ├── GeneraterManager.cs
│ ├── ICodeGenerater.cs
│ ├── IGenerater.cs
│ ├── Java
│ │ ├── JavaClass_Id.cs
│ │ ├── JavaClass_IdGenerator.cs
│ │ ├── JavaClass_Proto.cs
│ │ ├── JavaCodeGenerator.cs
│ │ └── JavaGenerator.cs
│ ├── Lua
│ │ ├── LuaGenerator.cs
│ │ └── Lua_Proto.cs
│ └── ProtoBuf
│ │ ├── ProtoFileGenerater.cs
│ │ └── ProtoGenerater.cs
├── Program.cs
├── Properties
│ └── launchSettings.json
├── ProtocolGenerator.csproj
└── Utils
│ ├── FileUtil.cs
│ └── StringUtil.cs
├── ProtocolLib
├── IdGenerator
│ └── Id.cs
├── ProtocolLib.csproj
└── Server
│ └── Register
│ ├── ServerRegister.cs
│ └── ServerRegisterIdGenerator.cs
├── README.md
├── UnitTest
├── Properties
│ └── AssemblyInfo.cs
├── UnitTest.cs
├── UnitTest.csproj
└── packages.config
└── keys
├── Google.Protobuf.public.snk
├── Google.Protobuf.snk
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/Cache/CSharp/Message/Server/Register/ServerRegisterIdGenerator.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.(The author is Boiling)
4 | // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
5 | //
6 | //------------------------------------------------------------------------------
7 | namespace Message.Server.Register
8 | {
9 | public class ServerRegisterIdGenerator
10 | {
11 | public static void GenerateId()
12 | {
13 | Message.IdGenerator.Id.Value= 0xff0001;
14 | Message.IdGenerator.Id.Value= 0xff0002;
15 | Message.IdGenerator.Id.Value= 0xff0004;
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Google.Protobuf/ByteArray.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2008 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | using System;
34 |
35 | namespace Google.Protobuf
36 | {
37 | ///
38 | /// Provides a utility routine to copy small arrays much more quickly than Buffer.BlockCopy
39 | ///
40 | internal static class ByteArray
41 | {
42 | ///
43 | /// The threshold above which you should use Buffer.BlockCopy rather than ByteArray.Copy
44 | ///
45 | private const int CopyThreshold = 12;
46 |
47 | ///
48 | /// Determines which copy routine to use based on the number of bytes to be copied.
49 | ///
50 | internal static void Copy(byte[] src, int srcOffset, byte[] dst, int dstOffset, int count)
51 | {
52 | if (count > CopyThreshold)
53 | {
54 | Buffer.BlockCopy(src, srcOffset, dst, dstOffset, count);
55 | }
56 | else
57 | {
58 | int stop = srcOffset + count;
59 | for (int i = srcOffset; i < stop; i++)
60 | {
61 | dst[dstOffset++] = src[i];
62 | }
63 | }
64 | }
65 |
66 | ///
67 | /// Reverses the order of bytes in the array
68 | ///
69 | internal static void Reverse(byte[] bytes)
70 | {
71 | for (int first = 0, last = bytes.Length - 1; first < last; first++, last--)
72 | {
73 | byte temp = bytes[first];
74 | bytes[first] = bytes[last];
75 | bytes[last] = temp;
76 | }
77 | }
78 | }
79 | }
--------------------------------------------------------------------------------
/Google.Protobuf/Collections/Lists.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2017 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | using System.Collections.Generic;
34 | using System.Collections.ObjectModel;
35 |
36 | namespace Google.Protobuf.Collections
37 | {
38 | ///
39 | /// Utility to compare if two Lists are the same, and the hash code
40 | /// of a List.
41 | ///
42 | public static class Lists
43 | {
44 | ///
45 | /// Checks if two lists are equal.
46 | ///
47 | public static bool Equals(List left, List right)
48 | {
49 | if (left == right)
50 | {
51 | return true;
52 | }
53 | if (left == null || right == null)
54 | {
55 | return false;
56 | }
57 | if (left.Count != right.Count)
58 | {
59 | return false;
60 | }
61 | IEqualityComparer comparer = EqualityComparer.Default;
62 | for (int i = 0; i < left.Count; i++)
63 | {
64 | if (!comparer.Equals(left[i], right[i]))
65 | {
66 | return false;
67 | }
68 | }
69 | return true;
70 | }
71 |
72 | ///
73 | /// Gets the list's hash code.
74 | ///
75 | public static int GetHashCode(List list)
76 | {
77 | if (list == null)
78 | {
79 | return 0;
80 | }
81 | int hash = 31;
82 | foreach (T element in list)
83 | {
84 | hash = hash * 29 + element.GetHashCode();
85 | }
86 | return hash;
87 | }
88 | }
89 | }
--------------------------------------------------------------------------------
/Google.Protobuf/Collections/ReadOnlyDictionary.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2008 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | using System;
34 | using System.Collections;
35 | using System.Collections.Generic;
36 |
37 | namespace Google.Protobuf.Collections
38 | {
39 | ///
40 | /// Read-only wrapper around another dictionary.
41 | ///
42 | internal sealed class ReadOnlyDictionary : IDictionary
43 | {
44 | private readonly IDictionary wrapped;
45 |
46 | public ReadOnlyDictionary(IDictionary wrapped)
47 | {
48 | this.wrapped = wrapped;
49 | }
50 |
51 | public void Add(TKey key, TValue value)
52 | {
53 | throw new InvalidOperationException();
54 | }
55 |
56 | public bool ContainsKey(TKey key)
57 | {
58 | return wrapped.ContainsKey(key);
59 | }
60 |
61 | public ICollection Keys
62 | {
63 | get { return wrapped.Keys; }
64 | }
65 |
66 | public bool Remove(TKey key)
67 | {
68 | throw new InvalidOperationException();
69 | }
70 |
71 | public bool TryGetValue(TKey key, out TValue value)
72 | {
73 | return wrapped.TryGetValue(key, out value);
74 | }
75 |
76 | public ICollection Values
77 | {
78 | get { return wrapped.Values; }
79 | }
80 |
81 | public TValue this[TKey key]
82 | {
83 | get { return wrapped[key]; }
84 | set { throw new InvalidOperationException(); }
85 | }
86 |
87 | public void Add(KeyValuePair item)
88 | {
89 | throw new InvalidOperationException();
90 | }
91 |
92 | public void Clear()
93 | {
94 | throw new InvalidOperationException();
95 | }
96 |
97 | public bool Contains(KeyValuePair item)
98 | {
99 | return wrapped.Contains(item);
100 | }
101 |
102 | public void CopyTo(KeyValuePair[] array, int arrayIndex)
103 | {
104 | wrapped.CopyTo(array, arrayIndex);
105 | }
106 |
107 | public int Count
108 | {
109 | get { return wrapped.Count; }
110 | }
111 |
112 | public bool IsReadOnly
113 | {
114 | get { return true; }
115 | }
116 |
117 | public bool Remove(KeyValuePair item)
118 | {
119 | throw new InvalidOperationException();
120 | }
121 |
122 | public IEnumerator> GetEnumerator()
123 | {
124 | return wrapped.GetEnumerator();
125 | }
126 |
127 | IEnumerator IEnumerable.GetEnumerator()
128 | {
129 | return ((IEnumerable) wrapped).GetEnumerator();
130 | }
131 |
132 | public override bool Equals(object obj)
133 | {
134 | return wrapped.Equals(obj);
135 | }
136 |
137 | public override int GetHashCode()
138 | {
139 | return wrapped.GetHashCode();
140 | }
141 |
142 | public override string ToString()
143 | {
144 | return wrapped.ToString();
145 | }
146 | }
147 | }
--------------------------------------------------------------------------------
/Google.Protobuf/Compatibility/MethodInfoExtensions.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2017 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | #if NET35
34 | using System;
35 | using System.Reflection;
36 |
37 | namespace Google.Protobuf.Compatibility
38 | {
39 | // .NET Core (at least netstandard1.0) doesn't have Delegate.CreateDelegate, and .NET 3.5 doesn't have
40 | // MethodInfo.CreateDelegate. Proxy from one to the other on .NET 3.5...
41 | internal static class MethodInfoExtensions
42 | {
43 | internal static Delegate CreateDelegate(this MethodInfo method, Type type) =>
44 | Delegate.CreateDelegate(type, method);
45 | }
46 | }
47 | #endif
48 |
--------------------------------------------------------------------------------
/Google.Protobuf/Compatibility/PropertyInfoExtensions.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2015 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | using System.Reflection;
34 |
35 | namespace Google.Protobuf.Compatibility
36 | {
37 | ///
38 | /// Extension methods for , effectively providing
39 | /// the familiar members from previous desktop framework versions while
40 | /// targeting the newer releases, .NET Core etc.
41 | ///
42 | internal static class PropertyInfoExtensions
43 | {
44 | ///
45 | /// Returns the public getter of a property, or null if there is no such getter
46 | /// (either because it's read-only, or the getter isn't public).
47 | ///
48 | internal static MethodInfo GetGetMethod(this PropertyInfo target)
49 | {
50 | #if NET35
51 | var method = target.GetGetMethod();
52 | #else
53 | var method = target.GetMethod;
54 | #endif
55 | return method != null && method.IsPublic ? method : null;
56 | }
57 |
58 | ///
59 | /// Returns the public setter of a property, or null if there is no such setter
60 | /// (either because it's write-only, or the setter isn't public).
61 | ///
62 | internal static MethodInfo GetSetMethod(this PropertyInfo target)
63 | {
64 | #if NET35
65 | var method = target.GetSetMethod();
66 | #else
67 | var method = target.SetMethod;
68 | #endif
69 | return method != null && method.IsPublic ? method : null;
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Google.Protobuf/Compatibility/StreamExtensions.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2015 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | #if NET35
34 | using System;
35 | using System.IO;
36 |
37 | namespace Google.Protobuf.Compatibility
38 | {
39 | ///
40 | /// Extension methods for in order to provide
41 | /// backwards compatibility with .NET 3.5
42 | ///
43 | public static class StreamExtensions
44 | {
45 | // 81920 seems to be the default buffer size used in .NET 4.5.1
46 | private const int BUFFER_SIZE = 81920;
47 |
48 | ///
49 | /// Write the contents of the current stream to the destination stream
50 | ///
51 | public static void CopyTo(this Stream source, Stream destination)
52 | {
53 | if (destination == null)
54 | {
55 | throw new ArgumentNullException(nameof(destination));
56 | }
57 |
58 | byte[] buffer = new byte[BUFFER_SIZE];
59 | int numBytesRead;
60 | while ((numBytesRead = source.Read(buffer, 0, buffer.Length)) > 0) {
61 | destination.Write(buffer, 0, numBytesRead);
62 | }
63 | }
64 | }
65 | }
66 | #endif
67 |
--------------------------------------------------------------------------------
/Google.Protobuf/Compatibility/TypeExtensions.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2015 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | using System;
34 | using System.Reflection;
35 |
36 | #if !NET35
37 | namespace Google.Protobuf.Compatibility
38 | {
39 | ///
40 | /// Provides extension methods on Type that just proxy to TypeInfo.
41 | /// These are used to support the new type system from .NET 4.5, without
42 | /// having calls to GetTypeInfo all over the place. While the methods here are meant to be
43 | /// broadly compatible with the desktop framework, there are some subtle differences in behaviour - but
44 | /// they're not expected to affect our use cases. While the class is internal, that should be fine: we can
45 | /// evaluate each new use appropriately.
46 | ///
47 | internal static class TypeExtensions
48 | {
49 | ///
50 | /// See https://msdn.microsoft.com/en-us/library/system.type.isassignablefrom
51 | ///
52 | internal static bool IsAssignableFrom(this Type target, Type c)
53 | {
54 | return target.GetTypeInfo().IsAssignableFrom(c.GetTypeInfo());
55 | }
56 |
57 | ///
58 | /// Returns a representation of the public property associated with the given name in the given type,
59 | /// including inherited properties or null if there is no such public property.
60 | /// Here, "public property" means a property where either the getter, or the setter, or both, is public.
61 | ///
62 | internal static PropertyInfo GetProperty(this Type target, string name)
63 | {
64 | // GetDeclaredProperty only returns properties declared in the given type, so we need to recurse.
65 | while (target != null)
66 | {
67 | var typeInfo = target.GetTypeInfo();
68 | var ret = typeInfo.GetDeclaredProperty(name);
69 | if (ret != null && ((ret.CanRead && ret.GetMethod.IsPublic) || (ret.CanWrite && ret.SetMethod.IsPublic)))
70 | {
71 | return ret;
72 | }
73 | target = typeInfo.BaseType;
74 | }
75 | return null;
76 | }
77 |
78 | ///
79 | /// Returns a representation of the public method associated with the given name in the given type,
80 | /// including inherited methods.
81 | ///
82 | ///
83 | /// This has a few differences compared with Type.GetMethod in the desktop framework. It will throw
84 | /// if there is an ambiguous match even between a private method and a public one, but it *won't* throw
85 | /// if there are two overloads at different levels in the type hierarchy (e.g. class Base declares public void Foo(int) and
86 | /// class Child : Base declares public void Foo(long)).
87 | ///
88 | /// One type in the hierarchy declared more than one method with the same name
89 | internal static MethodInfo GetMethod(this Type target, string name)
90 | {
91 | // GetDeclaredMethod only returns methods declared in the given type, so we need to recurse.
92 | while (target != null)
93 | {
94 | var typeInfo = target.GetTypeInfo();
95 | var ret = typeInfo.GetDeclaredMethod(name);
96 | if (ret != null && ret.IsPublic)
97 | {
98 | return ret;
99 | }
100 | target = typeInfo.BaseType;
101 | }
102 | return null;
103 | }
104 | }
105 | }
106 | #endif
107 |
--------------------------------------------------------------------------------
/Google.Protobuf/FrameworkPortability.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2008 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | using System;
34 | using System.Text.RegularExpressions;
35 |
36 | namespace Google.Protobuf
37 | {
38 | ///
39 | /// Class containing helpful workarounds for various platform compatibility
40 | ///
41 | internal static class FrameworkPortability
42 | {
43 | // The value of RegexOptions.Compiled is 8. We can test for the presence at
44 | // execution time using Enum.IsDefined, so a single build will do the right thing
45 | // on each platform. (RegexOptions.Compiled isn't supported by PCLs.)
46 | internal static readonly RegexOptions CompiledRegexWhereAvailable =
47 | Enum.IsDefined(typeof(RegexOptions), 8) ? (RegexOptions)8 : RegexOptions.None;
48 | }
49 | }
--------------------------------------------------------------------------------
/Google.Protobuf/Google.Protobuf.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | C# runtime library for Protocol Buffers - Google's data interchange format.
5 | Copyright 2015, Google Inc.
6 | Google Protocol Buffers
7 | 3.6.0
8 | Google Inc.
9 | net35
10 | true
11 | Google.Protobuf.snk
12 | true
13 | true
14 | Protocol;Buffers;Binary;Serialization;Format;Google;proto;proto3
15 | C# proto3 support
16 | https://github.com/google/protobuf
17 | https://github.com/google/protobuf/blob/master/LICENSE
18 | git
19 | https://github.com/google/protobuf.git
20 | true
21 | true
22 |
23 |
24 |
29 |
30 | netstandard1.0
31 |
32 |
33 | ..\Output
34 |
35 |
36 | ..\Output
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/Google.Protobuf/Google.Protobuf.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FRBoiling/ProtocolGenerator/0e184710b7c43195e5e4e9b3ce384fbe76afbf1e/Google.Protobuf/Google.Protobuf.snk
--------------------------------------------------------------------------------
/Google.Protobuf/ICustomDiagnosticMessage.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2016 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | namespace Google.Protobuf
34 | {
35 | ///
36 | /// A message type that has a custom string format for diagnostic purposes.
37 | ///
38 | ///
39 | ///
40 | /// Calling on a generated message type normally
41 | /// returns the JSON representation. If a message type implements this interface,
42 | /// then the method will be called instead of the regular
43 | /// JSON formatting code, but only when ToString() is called either on the message itself
44 | /// or on another message which contains it. This does not affect the normal JSON formatting of
45 | /// the message.
46 | ///
47 | ///
48 | /// For example, if you create a proto message representing a GUID, the internal
49 | /// representation may be a bytes field or four fixed32 fields. However, when debugging
50 | /// it may be more convenient to see a result in the same format as provides.
51 | ///
52 | /// This interface extends to avoid it accidentally being implemented
53 | /// on types other than messages, where it would not be used by anything in the framework.
54 | ///
55 | public interface ICustomDiagnosticMessage : IMessage
56 | {
57 | ///
58 | /// Returns a string representation of this object, for diagnostic purposes.
59 | ///
60 | ///
61 | /// This method is called when a message is formatted as part of a
62 | /// call. It does not affect the JSON representation used by other than
63 | /// in calls to . While it is recommended
64 | /// that the result is valid JSON, this is never assumed by the Protobuf library.
65 | ///
66 | /// A string representation of this object, for diagnostic purposes.
67 | string ToDiagnosticString();
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/Google.Protobuf/IDeepCloneable.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2015 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | namespace Google.Protobuf
34 | {
35 | ///
36 | /// Generic interface for a deeply cloneable type.
37 | ///
38 | ///
39 | ///
40 | /// All generated messages implement this interface, but so do some non-message types.
41 | /// Additionally, due to the type constraint on T in ,
42 | /// it is simpler to keep this as a separate interface.
43 | ///
44 | ///
45 | /// The type itself, returned by the method.
46 | public interface IDeepCloneable
47 | {
48 | ///
49 | /// Creates a deep clone of this object.
50 | ///
51 | /// A deep clone of this object.
52 | T Clone();
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Google.Protobuf/IMessage.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2008 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | using System;
34 | using Google.Protobuf.Reflection;
35 |
36 | namespace Google.Protobuf
37 | {
38 | ///
39 | /// Interface for a Protocol Buffers message, supporting
40 | /// basic operations required for serialization.
41 | ///
42 | public interface IMessage
43 | {
44 | ///
45 | /// Merges the data from the specified coded input stream with the current message.
46 | ///
47 | /// See the user guide for precise merge semantics.
48 | ///
49 | void MergeFrom(CodedInputStream input);
50 |
51 | ///
52 | /// Writes the data to the given coded output stream.
53 | ///
54 | /// Coded output stream to write the data to. Must not be null.
55 | void WriteTo(CodedOutputStream output);
56 |
57 | ///
58 | /// Calculates the size of this message in Protocol Buffer wire format, in bytes.
59 | ///
60 | /// The number of bytes required to write this message
61 | /// to a coded output stream.
62 | int CalculateSize();
63 |
64 | ///
65 | /// Descriptor for this message. All instances are expected to return the same descriptor,
66 | /// and for generated types this will be an explicitly-implemented member, returning the
67 | /// same value as the static property declared on the type.
68 | ///
69 | MessageDescriptor Descriptor { get; }
70 | }
71 |
72 | ///
73 | /// Generic interface for a Protocol Buffers message,
74 | /// where the type parameter is expected to be the same type as
75 | /// the implementation class.
76 | ///
77 | /// The message type.
78 | public interface IMessage : IMessage, IEquatable, IDeepCloneable where T : IMessage
79 | {
80 | ///
81 | /// Merges the given message into this one.
82 | ///
83 | /// See the user guide for precise merge semantics.
84 | /// The message to merge with this one. Must not be null.
85 | void MergeFrom(T message);
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/Google.Protobuf/InvalidJsonException.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2015 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | using System.IO;
34 |
35 | namespace Google.Protobuf
36 | {
37 | ///
38 | /// Thrown when an attempt is made to parse invalid JSON, e.g. using
39 | /// a non-string property key, or including a redundant comma. Parsing a protocol buffer
40 | /// message represented in JSON using can throw both this
41 | /// exception and depending on the situation. This
42 | /// exception is only thrown for "pure JSON" errors, whereas InvalidProtocolBufferException
43 | /// is thrown when the JSON may be valid in and of itself, but cannot be parsed as a protocol buffer
44 | /// message.
45 | ///
46 | public sealed class InvalidJsonException : IOException
47 | {
48 | internal InvalidJsonException(string message)
49 | : base(message)
50 | {
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/Google.Protobuf/LimitedInputStream.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2015 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | using System;
34 | using System.IO;
35 |
36 | namespace Google.Protobuf
37 | {
38 | ///
39 | /// Stream implementation which proxies another stream, only allowing a certain amount
40 | /// of data to be read. Note that this is only used to read delimited streams, so it
41 | /// doesn't attempt to implement everything.
42 | ///
43 | internal sealed class LimitedInputStream : Stream
44 | {
45 | private readonly Stream proxied;
46 | private int bytesLeft;
47 |
48 | internal LimitedInputStream(Stream proxied, int size)
49 | {
50 | this.proxied = proxied;
51 | bytesLeft = size;
52 | }
53 |
54 | public override bool CanRead
55 | {
56 | get { return true; }
57 | }
58 |
59 | public override bool CanSeek
60 | {
61 | get { return false; }
62 | }
63 |
64 | public override bool CanWrite
65 | {
66 | get { return false; }
67 | }
68 |
69 | public override void Flush()
70 | {
71 | }
72 |
73 | public override long Length
74 | {
75 | get { throw new NotSupportedException(); }
76 | }
77 |
78 | public override long Position
79 | {
80 | get { throw new NotSupportedException(); }
81 | set { throw new NotSupportedException(); }
82 | }
83 |
84 | public override int Read(byte[] buffer, int offset, int count)
85 | {
86 | if (bytesLeft > 0)
87 | {
88 | int bytesRead = proxied.Read(buffer, offset, Math.Min(bytesLeft, count));
89 | bytesLeft -= bytesRead;
90 | return bytesRead;
91 | }
92 | return 0;
93 | }
94 |
95 | public override long Seek(long offset, SeekOrigin origin)
96 | {
97 | throw new NotSupportedException();
98 | }
99 |
100 | public override void SetLength(long value)
101 | {
102 | throw new NotSupportedException();
103 | }
104 |
105 | public override void Write(byte[] buffer, int offset, int count)
106 | {
107 | throw new NotSupportedException();
108 | }
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/Google.Protobuf/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2008 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | using System.Runtime.CompilerServices;
34 | using System.Security;
35 |
36 | // General Information about an assembly is controlled through the following
37 | // set of attributes. Change these attribute values to modify the information
38 | // associated with an assembly.
39 |
40 | #if !NCRUNCH
41 | [assembly: AllowPartiallyTrustedCallers]
42 | #endif
43 |
44 | [assembly: InternalsVisibleTo("Google.Protobuf.Test, PublicKey=" +
45 | "002400000480000094000000060200000024000052534131000400000100010025800fbcfc63a1" +
46 | "7c66b303aae80b03a6beaa176bb6bef883be436f2a1579edd80ce23edf151a1f4ced97af83abcd" +
47 | "981207041fd5b2da3b498346fcfcd94910d52f25537c4a43ce3fbe17dc7d43e6cbdb4d8f1242dc" +
48 | "b6bd9b5906be74da8daa7d7280f97130f318a16c07baf118839b156299a48522f9fae2371c9665" +
49 | "c5ae9cb6")]
50 |
--------------------------------------------------------------------------------
/Google.Protobuf/ProtoPreconditions.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2008 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | using System;
34 |
35 | namespace Google.Protobuf
36 | {
37 | ///
38 | /// Helper methods for throwing exceptions when preconditions are not met.
39 | ///
40 | ///
41 | /// This class is used internally and by generated code; it is not particularly
42 | /// expected to be used from application code, although nothing prevents it
43 | /// from being used that way.
44 | ///
45 | public static class ProtoPreconditions
46 | {
47 | ///
48 | /// Throws an ArgumentNullException if the given value is null, otherwise
49 | /// return the value to the caller.
50 | ///
51 | public static T CheckNotNull(T value, string name) where T : class
52 | {
53 | if (value == null)
54 | {
55 | throw new ArgumentNullException(name);
56 | }
57 | return value;
58 | }
59 |
60 | ///
61 | /// Throws an ArgumentNullException if the given value is null, otherwise
62 | /// return the value to the caller.
63 | ///
64 | ///
65 | /// This is equivalent to but without the type parameter
66 | /// constraint. In most cases, the constraint is useful to prevent you from calling CheckNotNull
67 | /// with a value type - but it gets in the way if either you want to use it with a nullable
68 | /// value type, or you want to use it with an unconstrained type parameter.
69 | ///
70 | internal static T CheckNotNullUnconstrained(T value, string name)
71 | {
72 | if (value == null)
73 | {
74 | throw new ArgumentNullException(name);
75 | }
76 | return value;
77 | }
78 | }
79 | }
--------------------------------------------------------------------------------
/Google.Protobuf/Reflection/DescriptorBase.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2008 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | namespace Google.Protobuf.Reflection
34 | {
35 | ///
36 | /// Base class for nearly all descriptors, providing common functionality.
37 | ///
38 | public abstract class DescriptorBase : IDescriptor
39 | {
40 | private readonly FileDescriptor file;
41 | private readonly string fullName;
42 | private readonly int index;
43 |
44 | internal DescriptorBase(FileDescriptor file, string fullName, int index)
45 | {
46 | this.file = file;
47 | this.fullName = fullName;
48 | this.index = index;
49 | }
50 |
51 | ///
52 | /// The index of this descriptor within its parent descriptor.
53 | ///
54 | ///
55 | /// This returns the index of this descriptor within its parent, for
56 | /// this descriptor's type. (There can be duplicate values for different
57 | /// types, e.g. one enum type with index 0 and one message type with index 0.)
58 | ///
59 | public int Index
60 | {
61 | get { return index; }
62 | }
63 |
64 | ///
65 | /// Returns the name of the entity (field, message etc) being described.
66 | ///
67 | public abstract string Name { get; }
68 |
69 | ///
70 | /// The fully qualified name of the descriptor's target.
71 | ///
72 | public string FullName
73 | {
74 | get { return fullName; }
75 | }
76 |
77 | ///
78 | /// The file this descriptor was declared in.
79 | ///
80 | public FileDescriptor File
81 | {
82 | get { return file; }
83 | }
84 | }
85 | }
--------------------------------------------------------------------------------
/Google.Protobuf/Reflection/DescriptorUtil.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2008 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | using System.Collections.Generic;
34 | using System.Collections.ObjectModel;
35 |
36 | namespace Google.Protobuf.Reflection
37 | {
38 | ///
39 | /// Internal class containing utility methods when working with descriptors.
40 | ///
41 | internal static class DescriptorUtil
42 | {
43 | ///
44 | /// Equivalent to Func[TInput, int, TOutput] but usable in .NET 2.0. Only used to convert
45 | /// arrays.
46 | ///
47 | internal delegate TOutput IndexedConverter(TInput element, int index);
48 |
49 | ///
50 | /// Converts the given array into a read-only list, applying the specified conversion to
51 | /// each input element.
52 | ///
53 | internal static IList ConvertAndMakeReadOnly
54 | (IList input, IndexedConverter converter)
55 | {
56 | TOutput[] array = new TOutput[input.Count];
57 | for (int i = 0; i < array.Length; i++)
58 | {
59 | array[i] = converter(input[i], i);
60 | }
61 | return new ReadOnlyCollection(array);
62 | }
63 | }
64 | }
--------------------------------------------------------------------------------
/Google.Protobuf/Reflection/DescriptorValidationException.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2008 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | using System;
34 |
35 | namespace Google.Protobuf.Reflection
36 | {
37 | ///
38 | /// Thrown when building descriptors fails because the source DescriptorProtos
39 | /// are not valid.
40 | ///
41 | public sealed class DescriptorValidationException : Exception
42 | {
43 | private readonly String name;
44 | private readonly string description;
45 |
46 | ///
47 | /// The full name of the descriptor where the error occurred.
48 | ///
49 | public String ProblemSymbolName
50 | {
51 | get { return name; }
52 | }
53 |
54 | ///
55 | /// A human-readable description of the error. (The Message property
56 | /// is made up of the descriptor's name and this description.)
57 | ///
58 | public string Description
59 | {
60 | get { return description; }
61 | }
62 |
63 | internal DescriptorValidationException(IDescriptor problemDescriptor, string description) :
64 | base(problemDescriptor.FullName + ": " + description)
65 | {
66 | // Note that problemDescriptor may be partially uninitialized, so we
67 | // don't want to expose it directly to the user. So, we only provide
68 | // the name and the original proto.
69 | name = problemDescriptor.FullName;
70 | this.description = description;
71 | }
72 |
73 | internal DescriptorValidationException(IDescriptor problemDescriptor, string description, Exception cause) :
74 | base(problemDescriptor.FullName + ": " + description, cause)
75 | {
76 | name = problemDescriptor.FullName;
77 | this.description = description;
78 | }
79 | }
80 | }
--------------------------------------------------------------------------------
/Google.Protobuf/Reflection/EnumDescriptor.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2008 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | using System;
34 | using System.Collections.Generic;
35 |
36 | namespace Google.Protobuf.Reflection
37 | {
38 | ///
39 | /// Descriptor for an enum type in a .proto file.
40 | ///
41 | public sealed class EnumDescriptor : DescriptorBase
42 | {
43 | private readonly EnumDescriptorProto proto;
44 | private readonly MessageDescriptor containingType;
45 | private readonly IList values;
46 | private readonly Type clrType;
47 |
48 | internal EnumDescriptor(EnumDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index, Type clrType)
49 | : base(file, file.ComputeFullName(parent, proto.Name), index)
50 | {
51 | this.proto = proto;
52 | this.clrType = clrType;
53 | containingType = parent;
54 |
55 | if (proto.Value.Count == 0)
56 | {
57 | // We cannot allow enums with no values because this would mean there
58 | // would be no valid default value for fields of this type.
59 | throw new DescriptorValidationException(this, "Enums must contain at least one value.");
60 | }
61 |
62 | values = DescriptorUtil.ConvertAndMakeReadOnly(proto.Value,
63 | (value, i) => new EnumValueDescriptor(value, file, this, i));
64 |
65 | File.DescriptorPool.AddSymbol(this);
66 | }
67 |
68 | internal EnumDescriptorProto Proto { get { return proto; } }
69 |
70 | ///
71 | /// The brief name of the descriptor's target.
72 | ///
73 | public override string Name { get { return proto.Name; } }
74 |
75 | ///
76 | /// The CLR type for this enum. For generated code, this will be a CLR enum type.
77 | ///
78 | public Type ClrType { get { return clrType; } }
79 |
80 | ///
81 | /// If this is a nested type, get the outer descriptor, otherwise null.
82 | ///
83 | public MessageDescriptor ContainingType
84 | {
85 | get { return containingType; }
86 | }
87 |
88 | ///
89 | /// An unmodifiable list of defined value descriptors for this enum.
90 | ///
91 | public IList Values
92 | {
93 | get { return values; }
94 | }
95 |
96 | ///
97 | /// Finds an enum value by number. If multiple enum values have the
98 | /// same number, this returns the first defined value with that number.
99 | /// If there is no value for the given number, this returns null.
100 | ///
101 | public EnumValueDescriptor FindValueByNumber(int number)
102 | {
103 | return File.DescriptorPool.FindEnumValueByNumber(this, number);
104 | }
105 |
106 | ///
107 | /// Finds an enum value by name.
108 | ///
109 | /// The unqualified name of the value (e.g. "FOO").
110 | /// The value's descriptor, or null if not found.
111 | public EnumValueDescriptor FindValueByName(string name)
112 | {
113 | return File.DescriptorPool.FindSymbol(FullName + "." + name);
114 | }
115 |
116 | ///
117 | /// The (possibly empty) set of custom options for this enum.
118 | ///
119 | public CustomOptions CustomOptions => Proto.Options?.CustomOptions ?? CustomOptions.Empty;
120 | }
121 | }
--------------------------------------------------------------------------------
/Google.Protobuf/Reflection/EnumValueDescriptor.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2008 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | namespace Google.Protobuf.Reflection
34 | {
35 | ///
36 | /// Descriptor for a single enum value within an enum in a .proto file.
37 | ///
38 | public sealed class EnumValueDescriptor : DescriptorBase
39 | {
40 | private readonly EnumDescriptor enumDescriptor;
41 | private readonly EnumValueDescriptorProto proto;
42 |
43 | internal EnumValueDescriptor(EnumValueDescriptorProto proto, FileDescriptor file,
44 | EnumDescriptor parent, int index)
45 | : base(file, parent.FullName + "." + proto.Name, index)
46 | {
47 | this.proto = proto;
48 | enumDescriptor = parent;
49 | file.DescriptorPool.AddSymbol(this);
50 | file.DescriptorPool.AddEnumValueByNumber(this);
51 | }
52 |
53 | internal EnumValueDescriptorProto Proto { get { return proto; } }
54 |
55 | ///
56 | /// Returns the name of the enum value described by this object.
57 | ///
58 | public override string Name { get { return proto.Name; } }
59 |
60 | ///
61 | /// Returns the number associated with this enum value.
62 | ///
63 | public int Number { get { return Proto.Number; } }
64 |
65 | ///
66 | /// Returns the enum descriptor that this value is part of.
67 | ///
68 | public EnumDescriptor EnumDescriptor { get { return enumDescriptor; } }
69 |
70 | ///
71 | /// The (possibly empty) set of custom options for this enum value.
72 | ///
73 | public CustomOptions CustomOptions => Proto.Options?.CustomOptions ?? CustomOptions.Empty;
74 | }
75 | }
--------------------------------------------------------------------------------
/Google.Protobuf/Reflection/FieldAccessorBase.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2015 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | using System;
34 | using System.Reflection;
35 | using Google.Protobuf.Compatibility;
36 |
37 | namespace Google.Protobuf.Reflection
38 | {
39 | ///
40 | /// Base class for field accessors.
41 | ///
42 | internal abstract class FieldAccessorBase : IFieldAccessor
43 | {
44 | private readonly Func getValueDelegate;
45 | private readonly FieldDescriptor descriptor;
46 |
47 | internal FieldAccessorBase(PropertyInfo property, FieldDescriptor descriptor)
48 | {
49 | this.descriptor = descriptor;
50 | getValueDelegate = ReflectionUtil.CreateFuncIMessageObject(property.GetGetMethod());
51 | }
52 |
53 | public FieldDescriptor Descriptor { get { return descriptor; } }
54 |
55 | public object GetValue(IMessage message)
56 | {
57 | return getValueDelegate(message);
58 | }
59 |
60 | public abstract void Clear(IMessage message);
61 | public abstract void SetValue(IMessage message, object value);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/Google.Protobuf/Reflection/FieldType.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2008 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | namespace Google.Protobuf.Reflection
34 | {
35 | ///
36 | /// Enumeration of all the possible field types.
37 | ///
38 | public enum FieldType
39 | {
40 | ///
41 | /// The double field type.
42 | ///
43 | Double,
44 | ///
45 | /// The float field type.
46 | ///
47 | Float,
48 | ///
49 | /// The int64 field type.
50 | ///
51 | Int64,
52 | ///
53 | /// The uint64 field type.
54 | ///
55 | UInt64,
56 | ///
57 | /// The int32 field type.
58 | ///
59 | Int32,
60 | ///
61 | /// The fixed64 field type.
62 | ///
63 | Fixed64,
64 | ///
65 | /// The fixed32 field type.
66 | ///
67 | Fixed32,
68 | ///
69 | /// The bool field type.
70 | ///
71 | Bool,
72 | ///
73 | /// The string field type.
74 | ///
75 | String,
76 | ///
77 | /// The field type used for groups (not supported in this implementation).
78 | ///
79 | Group,
80 | ///
81 | /// The field type used for message fields.
82 | ///
83 | Message,
84 | ///
85 | /// The bytes field type.
86 | ///
87 | Bytes,
88 | ///
89 | /// The uint32 field type.
90 | ///
91 | UInt32,
92 | ///
93 | /// The sfixed32 field type.
94 | ///
95 | SFixed32,
96 | ///
97 | /// The sfixed64 field type.
98 | ///
99 | SFixed64,
100 | ///
101 | /// The sint32 field type.
102 | ///
103 | SInt32,
104 | ///
105 | /// The sint64 field type.
106 | ///
107 | SInt64,
108 | ///
109 | /// The field type used for enum fields.
110 | ///
111 | Enum
112 | }
113 | }
--------------------------------------------------------------------------------
/Google.Protobuf/Reflection/GeneratedClrTypeInfo.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2015 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 | using System;
33 |
34 | namespace Google.Protobuf.Reflection
35 | {
36 | ///
37 | /// Extra information provided by generated code when initializing a message or file descriptor.
38 | /// These are constructed as required, and are not long-lived. Hand-written code should
39 | /// never need to use this type.
40 | ///
41 | public sealed class GeneratedClrTypeInfo
42 | {
43 | private static readonly string[] EmptyNames = new string[0];
44 | private static readonly GeneratedClrTypeInfo[] EmptyCodeInfo = new GeneratedClrTypeInfo[0];
45 |
46 | ///
47 | /// Irrelevant for file descriptors; the CLR type for the message for message descriptors.
48 | ///
49 | public Type ClrType { get; private set; }
50 |
51 | ///
52 | /// Irrelevant for file descriptors; the parser for message descriptors.
53 | ///
54 | public MessageParser Parser { get; }
55 |
56 | ///
57 | /// Irrelevant for file descriptors; the CLR property names (in message descriptor field order)
58 | /// for fields in the message for message descriptors.
59 | ///
60 | public string[] PropertyNames { get; }
61 |
62 | ///
63 | /// Irrelevant for file descriptors; the CLR property "base" names (in message descriptor oneof order)
64 | /// for oneofs in the message for message descriptors. It is expected that for a oneof name of "Foo",
65 | /// there will be a "FooCase" property and a "ClearFoo" method.
66 | ///
67 | public string[] OneofNames { get; }
68 |
69 | ///
70 | /// The reflection information for types within this file/message descriptor. Elements may be null
71 | /// if there is no corresponding generated type, e.g. for map entry types.
72 | ///
73 | public GeneratedClrTypeInfo[] NestedTypes { get; }
74 |
75 | ///
76 | /// The CLR types for enums within this file/message descriptor.
77 | ///
78 | public Type[] NestedEnums { get; }
79 |
80 | ///
81 | /// Creates a GeneratedClrTypeInfo for a message descriptor, with nested types, nested enums, the CLR type, property names and oneof names.
82 | /// Each array parameter may be null, to indicate a lack of values.
83 | /// The parameter order is designed to make it feasible to format the generated code readably.
84 | ///
85 | public GeneratedClrTypeInfo(Type clrType, MessageParser parser, string[] propertyNames, string[] oneofNames, Type[] nestedEnums, GeneratedClrTypeInfo[] nestedTypes)
86 | {
87 | NestedTypes = nestedTypes ?? EmptyCodeInfo;
88 | NestedEnums = nestedEnums ?? ReflectionUtil.EmptyTypes;
89 | ClrType = clrType;
90 | Parser = parser;
91 | PropertyNames = propertyNames ?? EmptyNames;
92 | OneofNames = oneofNames ?? EmptyNames;
93 | }
94 |
95 | ///
96 | /// Creates a GeneratedClrTypeInfo for a file descriptor, with only types and enums.
97 | ///
98 | public GeneratedClrTypeInfo(Type[] nestedEnums, GeneratedClrTypeInfo[] nestedTypes)
99 | : this(null, null, null, null, nestedEnums, nestedTypes)
100 | {
101 | }
102 | }
103 | }
--------------------------------------------------------------------------------
/Google.Protobuf/Reflection/IDescriptor.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2008 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | namespace Google.Protobuf.Reflection
34 | {
35 | ///
36 | /// Interface implemented by all descriptor types.
37 | ///
38 | public interface IDescriptor
39 | {
40 | ///
41 | /// Returns the name of the entity (message, field etc) being described.
42 | ///
43 | string Name { get; }
44 |
45 | ///
46 | /// Returns the fully-qualified name of the entity being described.
47 | ///
48 | string FullName { get; }
49 |
50 | ///
51 | /// Returns the descriptor for the .proto file that this entity is part of.
52 | ///
53 | FileDescriptor File { get; }
54 | }
55 | }
--------------------------------------------------------------------------------
/Google.Protobuf/Reflection/IFieldAccessor.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2008 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | using System;
34 | using System.Collections;
35 |
36 | namespace Google.Protobuf.Reflection
37 | {
38 | ///
39 | /// Allows fields to be reflectively accessed.
40 | ///
41 | public interface IFieldAccessor
42 | {
43 | ///
44 | /// Returns the descriptor associated with this field.
45 | ///
46 | FieldDescriptor Descriptor { get; }
47 |
48 | ///
49 | /// Clears the field in the specified message. (For repeated fields,
50 | /// this clears the list.)
51 | ///
52 | void Clear(IMessage message);
53 |
54 | ///
55 | /// Fetches the field value. For repeated values, this will be an
56 | /// implementation. For map values, this will be an
57 | /// implementation.
58 | ///
59 | object GetValue(IMessage message);
60 |
61 | ///
62 | /// Mutator for single "simple" fields only.
63 | ///
64 | ///
65 | /// Repeated fields are mutated by fetching the value and manipulating it as a list.
66 | /// Map fields are mutated by fetching the value and manipulating it as a dictionary.
67 | ///
68 | /// The field is not a "simple" field.
69 | void SetValue(IMessage message, object value);
70 | }
71 | }
--------------------------------------------------------------------------------
/Google.Protobuf/Reflection/MapFieldAccessor.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2015 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | using System;
34 | using System.Collections;
35 | using System.Reflection;
36 |
37 | namespace Google.Protobuf.Reflection
38 | {
39 | ///
40 | /// Accessor for map fields.
41 | ///
42 | internal sealed class MapFieldAccessor : FieldAccessorBase
43 | {
44 | internal MapFieldAccessor(PropertyInfo property, FieldDescriptor descriptor) : base(property, descriptor)
45 | {
46 | }
47 |
48 | public override void Clear(IMessage message)
49 | {
50 | IDictionary list = (IDictionary) GetValue(message);
51 | list.Clear();
52 | }
53 |
54 | public override void SetValue(IMessage message, object value)
55 | {
56 | throw new InvalidOperationException("SetValue is not implemented for map fields");
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/Google.Protobuf/Reflection/MethodDescriptor.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2008 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | namespace Google.Protobuf.Reflection
34 | {
35 | ///
36 | /// Describes a single method in a service.
37 | ///
38 | public sealed class MethodDescriptor : DescriptorBase
39 | {
40 | private readonly MethodDescriptorProto proto;
41 | private readonly ServiceDescriptor service;
42 | private MessageDescriptor inputType;
43 | private MessageDescriptor outputType;
44 |
45 | ///
46 | /// The service this method belongs to.
47 | ///
48 | public ServiceDescriptor Service { get { return service; } }
49 |
50 | ///
51 | /// The method's input type.
52 | ///
53 | public MessageDescriptor InputType { get { return inputType; } }
54 |
55 | ///
56 | /// The method's input type.
57 | ///
58 | public MessageDescriptor OutputType { get { return outputType; } }
59 |
60 | ///
61 | /// Indicates if client streams multiple requests.
62 | ///
63 | public bool IsClientStreaming { get { return proto.ClientStreaming; } }
64 |
65 | ///
66 | /// Indicates if server streams multiple responses.
67 | ///
68 | public bool IsServerStreaming { get { return proto.ServerStreaming; } }
69 |
70 | ///
71 | /// The (possibly empty) set of custom options for this method.
72 | ///
73 | public CustomOptions CustomOptions => Proto.Options?.CustomOptions ?? CustomOptions.Empty;
74 |
75 | internal MethodDescriptor(MethodDescriptorProto proto, FileDescriptor file,
76 | ServiceDescriptor parent, int index)
77 | : base(file, parent.FullName + "." + proto.Name, index)
78 | {
79 | this.proto = proto;
80 | service = parent;
81 | file.DescriptorPool.AddSymbol(this);
82 | }
83 |
84 | internal MethodDescriptorProto Proto { get { return proto; } }
85 |
86 | ///
87 | /// The brief name of the descriptor's target.
88 | ///
89 | public override string Name { get { return proto.Name; } }
90 |
91 | internal void CrossLink()
92 | {
93 | IDescriptor lookup = File.DescriptorPool.LookupSymbol(Proto.InputType, this);
94 | if (!(lookup is MessageDescriptor))
95 | {
96 | throw new DescriptorValidationException(this, "\"" + Proto.InputType + "\" is not a message type.");
97 | }
98 | inputType = (MessageDescriptor) lookup;
99 |
100 | lookup = File.DescriptorPool.LookupSymbol(Proto.OutputType, this);
101 | if (!(lookup is MessageDescriptor))
102 | {
103 | throw new DescriptorValidationException(this, "\"" + Proto.OutputType + "\" is not a message type.");
104 | }
105 | outputType = (MessageDescriptor) lookup;
106 | }
107 | }
108 | }
--------------------------------------------------------------------------------
/Google.Protobuf/Reflection/OneofAccessor.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2015 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | using System;
34 | using System.Reflection;
35 | using Google.Protobuf.Compatibility;
36 |
37 | namespace Google.Protobuf.Reflection
38 | {
39 | ///
40 | /// Reflection access for a oneof, allowing clear and "get case" actions.
41 | ///
42 | public sealed class OneofAccessor
43 | {
44 | private readonly Func caseDelegate;
45 | private readonly Action clearDelegate;
46 | private OneofDescriptor descriptor;
47 |
48 | internal OneofAccessor(PropertyInfo caseProperty, MethodInfo clearMethod, OneofDescriptor descriptor)
49 | {
50 | if (!caseProperty.CanRead)
51 | {
52 | throw new ArgumentException("Cannot read from property");
53 | }
54 | this.descriptor = descriptor;
55 | caseDelegate = ReflectionUtil.CreateFuncIMessageInt32(caseProperty.GetGetMethod());
56 |
57 | this.descriptor = descriptor;
58 | clearDelegate = ReflectionUtil.CreateActionIMessage(clearMethod);
59 | }
60 |
61 | ///
62 | /// Gets the descriptor for this oneof.
63 | ///
64 | ///
65 | /// The descriptor of the oneof.
66 | ///
67 | public OneofDescriptor Descriptor { get { return descriptor; } }
68 |
69 | ///
70 | /// Clears the oneof in the specified message.
71 | ///
72 | public void Clear(IMessage message)
73 | {
74 | clearDelegate(message);
75 | }
76 |
77 | ///
78 | /// Indicates which field in the oneof is set for specified message
79 | ///
80 | public FieldDescriptor GetCaseFieldDescriptor(IMessage message)
81 | {
82 | int fieldNumber = caseDelegate(message);
83 | if (fieldNumber > 0)
84 | {
85 | return descriptor.ContainingType.FindFieldByNumber(fieldNumber);
86 | }
87 | return null;
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/Google.Protobuf/Reflection/OriginalNameAttribute.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2008 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | using System;
34 |
35 | namespace Google.Protobuf.Reflection
36 | {
37 | ///
38 | /// Specifies the original name (in the .proto file) of a named element,
39 | /// such as an enum value.
40 | ///
41 | [AttributeUsage(AttributeTargets.Field)]
42 | public class OriginalNameAttribute : Attribute
43 | {
44 | ///
45 | /// The name of the element in the .proto file.
46 | ///
47 | public string Name { get; set; }
48 |
49 | ///
50 | /// If the name is preferred in the .proto file.
51 | ///
52 | public bool PreferredAlias { get; set; }
53 |
54 | ///
55 | /// Constructs a new attribute instance for the given name.
56 | ///
57 | /// The name of the element in the .proto file.
58 | public OriginalNameAttribute(string name)
59 | {
60 | Name = ProtoPreconditions.CheckNotNull(name, nameof(name));
61 | PreferredAlias = true;
62 | }
63 |
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/Google.Protobuf/Reflection/PackageDescriptor.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2008 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | namespace Google.Protobuf.Reflection
34 | {
35 | ///
36 | /// Represents a package in the symbol table. We use PackageDescriptors
37 | /// just as placeholders so that someone cannot define, say, a message type
38 | /// that has the same name as an existing package.
39 | ///
40 | internal sealed class PackageDescriptor : IDescriptor
41 | {
42 | private readonly string name;
43 | private readonly string fullName;
44 | private readonly FileDescriptor file;
45 |
46 | internal PackageDescriptor(string name, string fullName, FileDescriptor file)
47 | {
48 | this.file = file;
49 | this.fullName = fullName;
50 | this.name = name;
51 | }
52 |
53 | public string Name
54 | {
55 | get { return name; }
56 | }
57 |
58 | public string FullName
59 | {
60 | get { return fullName; }
61 | }
62 |
63 | public FileDescriptor File
64 | {
65 | get { return file; }
66 | }
67 | }
68 | }
--------------------------------------------------------------------------------
/Google.Protobuf/Reflection/PartialClasses.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2008 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | // This file just contains partial classes for any autogenerated classes that need additional support.
34 | namespace Google.Protobuf.Reflection
35 | {
36 | internal partial class FieldDescriptorProto
37 | {
38 | // We can't tell the difference between "explicitly set to 0" and "not set"
39 | // in proto3, but we need to tell the difference for OneofIndex. descriptor.proto
40 | // is really a proto2 file, but the runtime doesn't know about proto2 semantics...
41 | // We fake it by defaulting to -1.
42 | partial void OnConstruction()
43 | {
44 | OneofIndex = -1;
45 | }
46 | }
47 |
48 | internal partial class FieldOptions
49 | {
50 | // We can't tell the difference between "explicitly set to false" and "not set"
51 | // in proto3, but we need to tell the difference for FieldDescriptor.IsPacked.
52 | // This won't work if we ever need to support proto2, but at that point we'll be
53 | // able to remove this hack and use field presence instead.
54 | partial void OnConstruction()
55 | {
56 | Packed = true;
57 | }
58 | }
59 | }
--------------------------------------------------------------------------------
/Google.Protobuf/Reflection/RepeatedFieldAccessor.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2015 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | using System;
34 | using System.Collections;
35 | using System.Reflection;
36 |
37 | namespace Google.Protobuf.Reflection
38 | {
39 | ///
40 | /// Accessor for repeated fields.
41 | ///
42 | internal sealed class RepeatedFieldAccessor : FieldAccessorBase
43 | {
44 | internal RepeatedFieldAccessor(PropertyInfo property, FieldDescriptor descriptor) : base(property, descriptor)
45 | {
46 | }
47 |
48 | public override void Clear(IMessage message)
49 | {
50 | IList list = (IList) GetValue(message);
51 | list.Clear();
52 | }
53 |
54 | public override void SetValue(IMessage message, object value)
55 | {
56 | throw new InvalidOperationException("SetValue is not implemented for repeated fields");
57 | }
58 |
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/Google.Protobuf/Reflection/ServiceDescriptor.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2008 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | using System;
34 | using System.Collections.Generic;
35 |
36 | namespace Google.Protobuf.Reflection
37 | {
38 | ///
39 | /// Describes a service type.
40 | ///
41 | public sealed class ServiceDescriptor : DescriptorBase
42 | {
43 | private readonly ServiceDescriptorProto proto;
44 | private readonly IList methods;
45 |
46 | internal ServiceDescriptor(ServiceDescriptorProto proto, FileDescriptor file, int index)
47 | : base(file, file.ComputeFullName(null, proto.Name), index)
48 | {
49 | this.proto = proto;
50 | methods = DescriptorUtil.ConvertAndMakeReadOnly(proto.Method,
51 | (method, i) => new MethodDescriptor(method, file, this, i));
52 |
53 | file.DescriptorPool.AddSymbol(this);
54 | }
55 |
56 | ///
57 | /// The brief name of the descriptor's target.
58 | ///
59 | public override string Name { get { return proto.Name; } }
60 |
61 | internal ServiceDescriptorProto Proto { get { return proto; } }
62 |
63 | ///
64 | /// An unmodifiable list of methods in this service.
65 | ///
66 | public IList Methods
67 | {
68 | get { return methods; }
69 | }
70 |
71 | ///
72 | /// Finds a method by name.
73 | ///
74 | /// The unqualified name of the method (e.g. "Foo").
75 | /// The method's decsriptor, or null if not found.
76 | public MethodDescriptor FindMethodByName(String name)
77 | {
78 | return File.DescriptorPool.FindSymbol(FullName + "." + name);
79 | }
80 |
81 | ///
82 | /// The (possibly empty) set of custom options for this service.
83 | ///
84 | public CustomOptions CustomOptions => Proto.Options?.CustomOptions ?? CustomOptions.Empty;
85 |
86 | internal void CrossLink()
87 | {
88 | foreach (MethodDescriptor method in methods)
89 | {
90 | method.CrossLink();
91 | }
92 | }
93 | }
94 | }
--------------------------------------------------------------------------------
/Google.Protobuf/Reflection/SingleFieldAccessor.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2015 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | using System;
34 | using System.Reflection;
35 | using Google.Protobuf.Compatibility;
36 |
37 | namespace Google.Protobuf.Reflection
38 | {
39 | ///
40 | /// Accessor for single fields.
41 | ///
42 | internal sealed class SingleFieldAccessor : FieldAccessorBase
43 | {
44 | // All the work here is actually done in the constructor - it creates the appropriate delegates.
45 | // There are various cases to consider, based on the property type (message, string/bytes, or "genuine" primitive)
46 | // and proto2 vs proto3 for non-message types, as proto3 doesn't support "full" presence detection or default
47 | // values.
48 |
49 | private readonly Action setValueDelegate;
50 | private readonly Action clearDelegate;
51 |
52 | internal SingleFieldAccessor(PropertyInfo property, FieldDescriptor descriptor) : base(property, descriptor)
53 | {
54 | if (!property.CanWrite)
55 | {
56 | throw new ArgumentException("Not all required properties/methods available");
57 | }
58 | setValueDelegate = ReflectionUtil.CreateActionIMessageObject(property.GetSetMethod());
59 |
60 | var clrType = property.PropertyType;
61 |
62 | // TODO: Validate that this is a reasonable single field? (Should be a value type, a message type, or string/ByteString.)
63 | object defaultValue =
64 | descriptor.FieldType == FieldType.Message ? null
65 | : clrType == typeof(string) ? ""
66 | : clrType == typeof(ByteString) ? ByteString.Empty
67 | : Activator.CreateInstance(clrType);
68 | clearDelegate = message => SetValue(message, defaultValue);
69 | }
70 |
71 | public override void Clear(IMessage message)
72 | {
73 | clearDelegate(message);
74 | }
75 |
76 | public override void SetValue(IMessage message, object value)
77 | {
78 | setValueDelegate(message, value);
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/Google.Protobuf/WellKnownTypes/TimeExtensions.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2015 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | using System;
34 |
35 | namespace Google.Protobuf.WellKnownTypes
36 | {
37 | ///
38 | /// Extension methods on BCL time-related types, converting to protobuf types.
39 | ///
40 | public static class TimeExtensions
41 | {
42 | ///
43 | /// Converts the given to a .
44 | ///
45 | /// The date and time to convert to a timestamp.
46 | /// The value has a other than Utc.
47 | /// The converted timestamp.
48 | public static Timestamp ToTimestamp(this DateTime dateTime)
49 | {
50 | return Timestamp.FromDateTime(dateTime);
51 | }
52 |
53 | ///
54 | /// Converts the given to a
55 | ///
56 | /// The offset is taken into consideration when converting the value (so the same instant in time
57 | /// is represented) but is not a separate part of the resulting value. In other words, there is no
58 | /// roundtrip operation to retrieve the original DateTimeOffset.
59 | /// The date and time (with UTC offset) to convert to a timestamp.
60 | /// The converted timestamp.
61 | public static Timestamp ToTimestamp(this DateTimeOffset dateTimeOffset)
62 | {
63 | return Timestamp.FromDateTimeOffset(dateTimeOffset);
64 | }
65 |
66 | ///
67 | /// Converts the given to a .
68 | ///
69 | /// The time span to convert.
70 | /// The converted duration.
71 | public static Duration ToDuration(this TimeSpan timeSpan)
72 | {
73 | return Duration.FromTimeSpan(timeSpan);
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/Google.Protobuf/WellKnownTypes/ValuePartial.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2008 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | namespace Google.Protobuf.WellKnownTypes
34 | {
35 | public partial class Value
36 | {
37 | ///
38 | /// Convenience method to create a Value message with a string value.
39 | ///
40 | /// Value to set for the StringValue property.
41 | /// A newly-created Value message with the given value.
42 | public static Value ForString(string value)
43 | {
44 | ProtoPreconditions.CheckNotNull(value, "value");
45 | return new Value { StringValue = value };
46 | }
47 |
48 | ///
49 | /// Convenience method to create a Value message with a number value.
50 | ///
51 | /// Value to set for the NumberValue property.
52 | /// A newly-created Value message with the given value.
53 | public static Value ForNumber(double value)
54 | {
55 | return new Value { NumberValue = value };
56 | }
57 |
58 | ///
59 | /// Convenience method to create a Value message with a Boolean value.
60 | ///
61 | /// Value to set for the BoolValue property.
62 | /// A newly-created Value message with the given value.
63 | public static Value ForBool(bool value)
64 | {
65 | return new Value { BoolValue = value };
66 | }
67 |
68 | ///
69 | /// Convenience method to create a Value message with a null initial value.
70 | ///
71 | /// A newly-created Value message a null initial value.
72 | public static Value ForNull()
73 | {
74 | return new Value { NullValue = 0 };
75 | }
76 |
77 | ///
78 | /// Convenience method to create a Value message with an initial list of values.
79 | ///
80 | /// The values provided are not cloned; the references are copied directly.
81 | /// A newly-created Value message an initial list value.
82 | public static Value ForList(params Value[] values)
83 | {
84 | ProtoPreconditions.CheckNotNull(values, "values");
85 | return new Value { ListValue = new ListValue { Values = { values } } };
86 | }
87 |
88 | ///
89 | /// Convenience method to create a Value message with an initial struct value
90 | ///
91 | /// The value provided is not cloned; the reference is copied directly.
92 | /// A newly-created Value message an initial struct value.
93 | public static Value ForStruct(Struct value)
94 | {
95 | ProtoPreconditions.CheckNotNull(value, "value");
96 | return new Value { StructValue = value };
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/Google.Protobuf/WellKnownTypes/WrappersPartial.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2008 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | namespace Google.Protobuf.WellKnownTypes
34 | {
35 | public static partial class WrappersReflection
36 | {
37 | ///
38 | /// Field number for the single "value" field in all wrapper types.
39 | ///
40 | internal const int WrapperValueFieldNumber = Int32Value.ValueFieldNumber;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Google.Protobuf/WireFormat.cs:
--------------------------------------------------------------------------------
1 | #region Copyright notice and license
2 | // Protocol Buffers - Google's data interchange format
3 | // Copyright 2008 Google Inc. All rights reserved.
4 | // https://developers.google.com/protocol-buffers/
5 | //
6 | // Redistribution and use in source and binary forms, with or without
7 | // modification, are permitted provided that the following conditions are
8 | // met:
9 | //
10 | // * Redistributions of source code must retain the above copyright
11 | // notice, this list of conditions and the following disclaimer.
12 | // * Redistributions in binary form must reproduce the above
13 | // copyright notice, this list of conditions and the following disclaimer
14 | // in the documentation and/or other materials provided with the
15 | // distribution.
16 | // * Neither the name of Google Inc. nor the names of its
17 | // contributors may be used to endorse or promote products derived from
18 | // this software without specific prior written permission.
19 | //
20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | #endregion
32 |
33 | namespace Google.Protobuf
34 | {
35 | ///
36 | /// This class is used internally by the Protocol Buffer Library and generated
37 | /// message implementations. It is public only for the sake of those generated
38 | /// messages. Others should not use this class directly.
39 | ///
40 | /// This class contains constants and helper functions useful for dealing with
41 | /// the Protocol Buffer wire format.
42 | ///
43 | ///
44 | public static class WireFormat
45 | {
46 | ///
47 | /// Wire types within protobuf encoding.
48 | ///
49 | public enum WireType : uint
50 | {
51 | ///
52 | /// Variable-length integer.
53 | ///
54 | Varint = 0,
55 | ///
56 | /// A fixed-length 64-bit value.
57 | ///
58 | Fixed64 = 1,
59 | ///
60 | /// A length-delimited value, i.e. a length followed by that many bytes of data.
61 | ///
62 | LengthDelimited = 2,
63 | ///
64 | /// A "start group" value - not supported by this implementation.
65 | ///
66 | StartGroup = 3,
67 | ///
68 | /// An "end group" value - not supported by this implementation.
69 | ///
70 | EndGroup = 4,
71 | ///
72 | /// A fixed-length 32-bit value.
73 | ///
74 | Fixed32 = 5
75 | }
76 |
77 | private const int TagTypeBits = 3;
78 | private const uint TagTypeMask = (1 << TagTypeBits) - 1;
79 |
80 | ///
81 | /// Given a tag value, determines the wire type (lower 3 bits).
82 | ///
83 | public static WireType GetTagWireType(uint tag)
84 | {
85 | return (WireType) (tag & TagTypeMask);
86 | }
87 |
88 | ///
89 | /// Given a tag value, determines the field number (the upper 29 bits).
90 | ///
91 | public static int GetTagFieldNumber(uint tag)
92 | {
93 | return (int) tag >> TagTypeBits;
94 | }
95 |
96 | ///
97 | /// Makes a tag value given a field number and wire type.
98 | ///
99 | public static uint MakeTag(int fieldNumber, WireType wireType)
100 | {
101 | return (uint) (fieldNumber << TagTypeBits) | (uint) wireType;
102 | }
103 | }
104 | }
--------------------------------------------------------------------------------
/Output/net35/Generator.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FRBoiling/ProtocolGenerator/0e184710b7c43195e5e4e9b3ce384fbe76afbf1e/Output/net35/Generator.exe
--------------------------------------------------------------------------------
/Output/net35/Google.Protobuf.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FRBoiling/ProtocolGenerator/0e184710b7c43195e5e4e9b3ce384fbe76afbf1e/Output/net35/Google.Protobuf.dll
--------------------------------------------------------------------------------
/Output/net35/ProtocolGenerator.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FRBoiling/ProtocolGenerator/0e184710b7c43195e5e4e9b3ce384fbe76afbf1e/Output/net35/ProtocolGenerator.exe
--------------------------------------------------------------------------------
/Output/net35/google_protoc/protoc.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FRBoiling/ProtocolGenerator/0e184710b7c43195e5e4e9b3ce384fbe76afbf1e/Output/net35/google_protoc/protoc.exe
--------------------------------------------------------------------------------
/ProtobufHelper/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的一般信息由以下
6 | // 控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("ProtobufHelper")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("ProtobufHelper")]
13 | [assembly: AssemblyCopyright("Copyright © 2019")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 会使此程序集中的类型
18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
19 | //请将此类型的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("16d07577-3170-4992-bd12-70750fa4bcda")]
24 |
25 | // 程序集的版本信息由下列四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
33 | //通过使用 "*",如下所示:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/ProtobufHelper/ProtobufHelper.cs:
--------------------------------------------------------------------------------
1 | using Google.Protobuf;
2 | using System;
3 | using System.IO;
4 |
5 | namespace ProtobufHelper
6 | {
7 | public class ProtobufHelper
8 | {
9 | ///
10 | /// 序列化
11 | ///
12 | ///
13 | ///
14 | ///
15 | public static void Serialize(T message, MemoryStream outStream) where T : Google.Protobuf.IMessage
16 | {
17 | message.WriteTo(outStream);
18 | }
19 |
20 | ///
21 | /// 反序列化
22 | ///
23 | ///
24 | ///
25 | ///
26 | public static T Deserialize(MemoryStream inStream) where T : Google.Protobuf.IMessage
27 | {
28 | T msg = Activator.CreateInstance();
29 | msg.MergeFrom(inStream.GetBuffer(), (int)inStream.Position, (int)inStream.Length);
30 | return msg;
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/ProtobufHelper/ProtobufHelper.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {16D07577-3170-4992-BD12-70750FA4BCDA}
8 | Library
9 | Properties
10 | ProtobufHelper
11 | ProtobufHelper
12 | v3.5
13 | 512
14 | true
15 |
16 |
17 |
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 |
26 |
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | {b42db28b-4e30-48d1-9610-98004938d3de}
49 | Google.Protobuf
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/ProtocolBuilder/IdGenerator/Id.code:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/ProtocolBuilder/IdGenerator/Id.proto:
--------------------------------------------------------------------------------
1 | 'syntax = "proto3"
2 |
3 |
--------------------------------------------------------------------------------
/ProtocolBuilder/ProtocolBuilder.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {afb189d0-be59-481b-a74f-a1efa7f611de}
6 |
7 |
8 | {be7a6a9c-8bf5-4f6c-8168-380f48c22f94}
9 |
10 |
11 |
12 |
13 | IdGenerator
14 |
15 |
16 | Server
17 |
18 |
19 |
--------------------------------------------------------------------------------
/ProtocolBuilder/Server/ServerRegister.code:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package Message.Server.Register;
3 |
4 | message Server_Tag
5 | {
6 | int32 serverType= 1;
7 | int32 groupId = 2;
8 | int32 subId = 3;
9 | }
10 |
11 | message MSG_Server_Register 0xff0001
12 | {
13 | Server_Tag tag =1;
14 | }
15 |
16 | message MSG_Server_Register_Return 0xff0002
17 | {
18 | uint32 Result =1;
19 | Server_Tag tag =2;
20 | }
21 |
22 | message Connect_Info
23 | {
24 | int32 port = 1;
25 | string ip = 2;
26 | }
27 |
28 | message MSG_Server_Connect_Command 0xff0004
29 | {
30 | Server_Tag tag = 1;
31 | Connect_Info info= 2;
32 | int32 connectType = 4;
33 | int32 connectType1 = 5;
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/ProtocolBuilder/Server/ServerRegister.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 | package Message.Server.Register;
3 |
4 | message Server_Tag
5 | {
6 | int32 serverType= 1;
7 | int32 groupId = 2;
8 | int32 subId = 3;
9 | }
10 |
11 | message MSG_Server_Register
12 | {
13 | Server_Tag tag =1;
14 | }
15 |
16 | message MSG_Server_Register_Return
17 | {
18 | uint32 Result =1;
19 | Server_Tag tag =2;
20 | }
21 |
22 | message Connect_Info
23 | {
24 | int32 port = 1;
25 | string ip = 2;
26 | }
27 |
28 | message MSG_Server_Connect_Command
29 | {
30 | Server_Tag tag = 1;
31 | Connect_Info info= 2;
32 | int32 connectType = 4;
33 | int32 connectType1 = 5;
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/ProtocolGenerator/Core/AbstractFileModel.cs:
--------------------------------------------------------------------------------
1 | /************************************************************************
2 | * 项目名称 : ProtocolGenerator
3 | * 类 名 称 : AbstratFileModel
4 | * 类 描 述 :
5 | * 版 本 号 : v1.0.0.0
6 | * 说 明 :
7 | * 作 者 : FReedom
8 | * 创建时间 : 2018/4/20 星期五 18:58:29
9 | * 更新时间 : 2018/4/20 星期五 18:58:29
10 | ************************************************************************
11 | * Copyright @ BoilingBlood 2018. All rights reserved.
12 | ************************************************************************/
13 | using System;
14 | using System.Text;
15 |
16 | namespace ProtocolGenerator
17 | {
18 | public abstract class AbstractFileModel
19 | {
20 | protected string m_filePath = string.Empty;
21 | protected string m_fileName = string.Empty;
22 | protected string m_fileSuffix = string.Empty;
23 | public string FileFullName { get => m_filePath+ m_fileName+ m_fileSuffix;}
24 | public string FileSimpleName { get => m_fileName + m_fileSuffix; }
25 | protected abstract StringBuilder GenerateClassCode();
26 |
27 | public bool Generate()
28 | {
29 | StringBuilder fileContent = GenerateClassCode();
30 | if (FileUtil.WriteToFile(fileContent, m_filePath, m_fileName, m_fileSuffix))
31 | {
32 | //Console.WriteLine("{0} generate sucess", FileSimpleName);
33 | //Console.WriteLine(">>{0}", FileFullName);
34 | return true;
35 | }
36 | else
37 | {
38 | Console.WriteLine("{0} generate fail", FileSimpleName);
39 | return false;
40 | }
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/ProtocolGenerator/Core/CSharp/CSharpClass_Id.cs:
--------------------------------------------------------------------------------
1 | /************************************************************************
2 | * 项目名称 : ProtocolGenerator.CSharp
3 | * 类 名 称 : CSharpClass_Id
4 | * 类 描 述 : 生成静态字段Id类
5 | * 版 本 号 : v1.0.0.0
6 | * 说 明 :
7 | * 作 者 : FReedom
8 | * 创建时间 : 2018/4/20 星期五 17:44:03
9 | * 更新时间 : 2018/4/20 星期五 17:44:03
10 | ************************************************************************
11 | * Copyright @ BoilingBlood 2018. All rights reserved.
12 | ************************************************************************/
13 | using System.Collections.Generic;
14 | using System.Text;
15 |
16 | namespace ProtocolGenerator.Core.CSharp
17 | {
18 | class CSharpClass_Id:AbstractFileModel
19 | {
20 | CSharpCodeGenerator _generater = new CSharpCodeGenerator();
21 | public const string msgIdPackageName = "Message.IdGenerator";
22 | public const string className = "Id";
23 |
24 | public CSharpClass_Id()
25 | {
26 | string tempPath = msgIdPackageName.Replace('.', '\\');
27 | m_filePath = Program.OutputPath + @"\CSharp\"+ tempPath+@"\";
28 | m_fileName = "Id";
29 | m_fileSuffix = ".cs";
30 | }
31 |
32 | protected override StringBuilder GenerateClassCode()
33 | {
34 | StringBuilder fileContent = new StringBuilder();
35 | StringBuilder fileComments = _generater.ClassCommentsFrame();
36 | StringBuilder fileIncludeHeads = _generater.IncludeHeadFrame(null);
37 | StringBuilder classAttr = _generater.AttrFrame("public static uint", "Value");
38 | List attrs = new List();
39 | attrs.Add(classAttr);
40 | List methods = new List();
41 | StringBuilder classFrame = _generater.ClassFrame("static class " + className + "", attrs, methods);
42 | StringBuilder nameSpaceFrame = _generater.NameSpaceFrame(msgIdPackageName, classFrame);
43 |
44 | fileContent.Append(fileComments);
45 | fileContent.Append(fileIncludeHeads);
46 | fileContent.Append(nameSpaceFrame);
47 |
48 | return fileContent;
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/ProtocolGenerator/Core/CSharp/CSharpClass_IdGenerater.cs:
--------------------------------------------------------------------------------
1 | /************************************************************************
2 | * 项目名称 : ProtocolGenerator.CSharp
3 | * 类 名 称 : CSharpClass_IdGenerator
4 | * 类 描 述 : 生成协议Id的.cs文件
5 | * 版 本 号 : v1.0.0.0
6 | * 说 明 :
7 | * 作 者 : FReedom
8 | * 创建时间 : 2018/4/20 星期五 17:45:39
9 | * 更新时间 : 2018/4/20 星期五 17:45:39
10 | ************************************************************************
11 | * Copyright @ BoilingBlood 2018. All rights reserved.
12 | ************************************************************************/
13 | using System.Collections.Generic;
14 | using System.Text;
15 |
16 | namespace ProtocolGenerator.Core.CSharp
17 | {
18 | public class CSharpClass_IdGenerator: AbstractFileModel
19 | {
20 | CSharpCodeGenerator _generater = new CSharpCodeGenerator();
21 | string className = "IdGenerator";
22 | Data _data = null;
23 | public CSharpClass_IdGenerator(Data data)
24 | {
25 | _data = data;
26 | string tempPath = _data.ProtoPackageName.Replace('.', '\\');
27 | m_filePath = Program.OutputPath + @"\CSharp\"+ tempPath+@"\";
28 | m_fileName = _data.ProtoFileKey;
29 | m_fileSuffix = "IdGenerator.cs";
30 | className = m_fileName + className;
31 | }
32 |
33 | private StringBuilder GenerateIdKey(string key)
34 | {
35 | StringBuilder sb = new StringBuilder();
36 | sb.Append(CSharpClass_Id.msgIdPackageName);
37 | sb.Append(".Id<");
38 | sb.Append(key);
39 | sb.Append(">.Value=");
40 | return sb;
41 | }
42 |
43 | private StringBuilder GenerateIdValue(string value)
44 | {
45 | StringBuilder sb = new StringBuilder();
46 | sb.Append(value);
47 | return sb;
48 | }
49 |
50 | protected override StringBuilder GenerateClassCode()
51 | {
52 | StringBuilder fileContent = new StringBuilder();
53 | StringBuilder fileComments = _generater.ClassCommentsFrame();
54 | StringBuilder fileIncludeHeads = _generater.IncludeHeadFrame(null);
55 |
56 | List attrs = new List();
57 | foreach (var item in _data.DicName2Id)
58 | {
59 | StringBuilder sbClassAttrFrame = _generater.AttrFrame(GenerateIdKey(item.Key).ToString(), GenerateIdValue(item.Value).ToString());
60 | attrs.Add(sbClassAttrFrame);
61 | }
62 |
63 | StringBuilder sbClassMethodFrame = _generater.MethodFrame("static void", "GenerateId()", attrs);
64 | List methods = new List();
65 | methods.Add(sbClassMethodFrame);
66 |
67 | StringBuilder sbClassBodyFrame = _generater.ClassFrame("class " + className, null, methods);
68 | StringBuilder sbNameSpaceFrame = _generater.NameSpaceFrame(_data.ProtoPackageName, sbClassBodyFrame);
69 |
70 | fileContent.Append(fileComments);
71 | fileContent.Append(fileIncludeHeads);
72 | fileContent.Append(sbNameSpaceFrame);
73 | return fileContent;
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/ProtocolGenerator/Core/CSharp/CSharpGenerater.cs:
--------------------------------------------------------------------------------
1 | /************************************************************************
2 | * 项目名称 : ProtocolGenerator.CSharp
3 | * 类 名 称 : CSharpGenerator
4 | * 类 描 述 :
5 | * 版 本 号 : v1.0.0.0
6 | * 说 明 :
7 | * 作 者 : FReedom
8 | * 创建时间 : 2018/4/20 星期五 19:28:28
9 | * 更新时间 : 2018/4/20 星期五 19:28:28
10 | ************************************************************************
11 | * Copyright @ BoilingBlood 2018. All rights reserved.
12 | ************************************************************************/
13 |
14 | namespace ProtocolGenerator.Core.CSharp
15 | {
16 | public class CSharpGenerator : IGenerator
17 | {
18 | public void Generate()
19 | {
20 | CSharpClass_Id classGen = new CSharpClass_Id();
21 | classGen.Generate();
22 | }
23 | public void Generate(Data data)
24 | {
25 | CSharpClass_IdGenerator classGen = new CSharpClass_IdGenerator(data);
26 | classGen.Generate();
27 | CSharpClass_Proto protoGen = new CSharpClass_Proto(data);
28 | //protoGen.GenerateProto_Old();
29 | //protoGen.GenerateProto_Net400();
30 | protoGen.GenerateProto();
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/ProtocolGenerator/Core/Data/Data.cs:
--------------------------------------------------------------------------------
1 | /************************************************************************
2 | * 项目名称 : ProtocolGenerator
3 | * 项目描述 :
4 | * 类 名 称 : Data
5 | * 版 本 号 : v1.0.0.0
6 | * 说 明 :
7 | * 作 者 : FReedom
8 | * 创建时间 : 2018/4/20 星期五 16:48:51
9 | * 更新时间 : 2018/4/20 星期五 16:48:51
10 | ************************************************************************
11 | * Copyright @ BoilingBlood 2018. All rights reserved.
12 | ************************************************************************/
13 | using System.Collections.Generic;
14 | using System.Text;
15 |
16 | namespace ProtocolGenerator
17 | {
18 | public class Data
19 | {
20 | string protoFullPath = string.Empty;
21 |
22 | ///
23 | ///"protoModel.code" just the "protoModel"
24 | ///
25 | string protoFileKey = string.Empty;
26 | ///
27 | /// package
28 | ///
29 | string protoPackageName = string.Empty;
30 | ///
31 | /// .proto content
32 | ///
33 | StringBuilder protoCode = new StringBuilder();
34 | ///
35 | /// Key is msgName,Value is msgId
36 | ///
37 | Dictionary dicName2Id = new Dictionary();
38 | ///
39 | /// Key is msgId,Value is msgName
40 | ///
41 | Dictionary dicId2Name = new Dictionary();
42 |
43 |
44 | public string ProtoFileKey { get => protoFileKey; set => protoFileKey = value; }
45 | public string ProtoPackageName { get => protoPackageName; set => protoPackageName = value; }
46 | public StringBuilder ProtoCode { get => protoCode; set => protoCode = value; }
47 | public Dictionary DicName2Id { get => dicName2Id; set => dicName2Id = value; }
48 | public Dictionary DicId2Name { get => dicId2Name; set => dicId2Name = value; }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/ProtocolGenerator/Core/Data/DataManager.cs:
--------------------------------------------------------------------------------
1 | /************************************************************************
2 | * 项目名称 : ProtocolGenerator
3 | * 项目描述 :
4 | * 类 名 称 : DataManager
5 | * 版 本 号 : v1.0.0.0
6 | * 说 明 :
7 | * 作 者 : Boiling
8 | * 创建时间 : 2018/4/20 星期五 16:46:38
9 | * 更新时间 : 2018/4/20 星期五 16:46:38
10 | ************************************************************************
11 | * Copyright @ BoilingBlood 2018. All rights reserved.
12 | ************************************************************************/
13 | using ProtocolBuffersGenerator.Core;
14 | using System;
15 | using System.Collections.Generic;
16 |
17 | namespace ProtocolGenerator
18 | {
19 | public class DataManager
20 | {
21 |
22 | private static DataManager _inst;
23 |
24 | // 定义私有构造函数,使外界不能创建该类实例
25 | private DataManager()
26 | {
27 | }
28 | ///
29 | /// 定义公有方法提供一个全局访问点,同时你也可以定义公有属性来提供全局访问点
30 | ///
31 | ///
32 | public static DataManager GetInstance()
33 | {
34 | // 如果类的实例不存在则创建,否则直接返回
35 | if (_inst == null)
36 | {
37 | _inst = new DataManager();
38 | }
39 | return _inst;
40 | }
41 |
42 | ///
43 | /// proto datas
44 | ///
45 | Dictionary _dataDic = new Dictionary();
46 |
47 | public Dictionary DataDic { get => _dataDic; set => _dataDic = value; }
48 |
49 | ///
50 | /// load proto.code file
51 | ///
52 | ///
53 | public void Load(string fileName)
54 | {
55 | Data data = DataParser.ParseCodeFile(fileName);
56 | if (data == null)
57 | {
58 | Console.WriteLine("please check your file :{0}", fileName);
59 | return;
60 | }
61 | if (_dataDic.ContainsKey(data.ProtoFileKey))
62 | {
63 | Console.WriteLine("Load an repeated file {0}",data.ProtoFileKey);
64 | }
65 | else
66 | {
67 | _dataDic.Add(data.ProtoFileKey, data);
68 | }
69 | }
70 |
71 | ///
72 | /// 检查文件是否失效
73 | ///
74 | ///
75 | ///
76 | public bool CheckFilePast(string fileFullName)
77 | {
78 | GeneratorCache cache = new GeneratorCache();
79 | return cache.CheckCache(fileFullName);
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/ProtocolGenerator/Core/EnumType.cs:
--------------------------------------------------------------------------------
1 | /************************************************************************
2 | * 项目名称 : ProtocolGenerator.Core
3 | * 类 名 称 : Type
4 | * 类 描 述 :
5 | * 版 本 号 : v1.0.0.0
6 | * 说 明 :
7 | * 作 者 : FReedom
8 | * 创建时间 : 2018/4/20 星期五 19:43:33
9 | * 更新时间 : 2018/4/20 星期五 19:43:33
10 | ************************************************************************
11 | * Copyright @ BoilingBlood 2018. All rights reserved.
12 | ************************************************************************/
13 |
14 | namespace ProtocolGenerator.Core
15 | {
16 | public enum GeneratorType
17 | {
18 | Proto,
19 | CSharp,
20 | Java,
21 | Lua,
22 | CPlusPlus
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/ProtocolGenerator/Core/GeneraterCache.cs:
--------------------------------------------------------------------------------
1 | using ProtocolGenerator;
2 | using System;
3 | using System.IO;
4 |
5 | namespace ProtocolBuffersGenerator.Core
6 | {
7 | public class GeneratorCache
8 | {
9 | string cacheFileName = "tmp";
10 | string cacheFilePostfix = ".tmp";
11 | string cacheFilePath = Program.OutputPath+@"tmp\";
12 |
13 | string cacheFileFullName = "";
14 |
15 | ///
16 | /// 缓存是否有效
17 | ///
18 | /// true 存在, false 不存在
19 | public bool CheckCache(string fileFullName)
20 | {
21 | int index = fileFullName.LastIndexOf("\\");
22 | if (index < 0)
23 | {
24 | Console.WriteLine("CheckFileChange error : fileFullName format wrong .({0})", fileFullName);
25 | return false;
26 | }
27 | bool isPast = true; //缓存失效
28 |
29 | cacheFileName = fileFullName.Substring(index + 1);
30 | index = cacheFileName.LastIndexOf(".");
31 | cacheFileName = cacheFileName.Substring(0, index);
32 |
33 | string newHashValue = FileUtil.GetFileHashValue(fileFullName);
34 |
35 | //cacheFileFullName = cacheFilePath + fileFullName.Replace(Program.InputPath, "").Replace(".code",cacheFilePostfix);
36 | cacheFileFullName = cacheFilePath + cacheFileName+ cacheFilePostfix;
37 |
38 | if (string.IsNullOrEmpty(newHashValue))
39 | {
40 | Console.WriteLine("CheckFileChange error : {0} is null", fileFullName);
41 | return false;
42 | }
43 | try
44 | {
45 | FileInfo fi = new FileInfo(cacheFileFullName);
46 | if (fi.Exists)
47 | {
48 | FileStream fsRead = fi.OpenRead();
49 | StreamReader sr = new StreamReader(fsRead);
50 | string oldHashValue = sr.ReadLine();
51 | bool isSame = CompareHashValue(oldHashValue, newHashValue);
52 |
53 | DateTime lastWriteTime = fi.LastWriteTime; //缓存文件上次写入时间
54 | sr.Close();
55 | fsRead.Close();
56 |
57 | if (isSame)
58 | {
59 | isPast = CompareCacheTime(fi.LastWriteTime);
60 | }
61 | else
62 | {
63 | isPast = true;
64 | }
65 | }
66 | else
67 | {
68 | isPast = true;
69 | }
70 | }
71 | catch (Exception e)
72 | {
73 | Console.WriteLine(e.Message);
74 | return false;
75 | }
76 |
77 | if (isPast)
78 | {
79 | //Console.WriteLine( "{0} write success", fileFullName);
80 | FileUtil.WriteToFile(newHashValue, cacheFilePath, cacheFileName, cacheFilePostfix);
81 | }
82 | else
83 | {
84 |
85 | }
86 | return isPast;
87 | }
88 |
89 |
90 | ///
91 | /// 比较hash值
92 | ///
93 | ///
94 | ///
95 | /// true 表示不需要生成
96 | private bool CompareHashValue(string oldHash, string newHash)
97 | {
98 | if (string.IsNullOrEmpty(newHash))
99 | {
100 | return true;
101 | }
102 | //比较两个哈希值
103 | if (oldHash == newHash)
104 | {
105 | //Console.WriteLine("两个文件相等");
106 | return true;
107 | }
108 | else
109 | {
110 | //Console.WriteLine("两个文件不等");
111 | return false;
112 | }
113 | }
114 |
115 | ///
116 | /// 比较缓存时间
117 | ///
118 | ///
119 | ///
120 | ///
121 | private bool CompareCacheTime(DateTime time)
122 | {
123 | ///十分钟失效
124 | if ((DateTime.Now - time).TotalMinutes > 10)
125 | {
126 | return true;
127 | }
128 | else
129 | {
130 | return false;
131 | }
132 | }
133 |
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/ProtocolGenerator/Core/GeneraterManager.cs:
--------------------------------------------------------------------------------
1 | /************************************************************************
2 | * 项目名称 : ProtocolGenerator
3 | * 项目描述 :
4 | * 类 名 称 : GeneratorManager
5 | * 版 本 号 : v1.0.0.0
6 | * 说 明 :
7 | * 作 者 : Boiling
8 | * 创建时间 : 2018/4/20 星期五 15:55:08
9 | * 更新时间 : 2018/4/20 星期五 15:55:08
10 | ************************************************************************
11 | * Copyright @ BoilingBlood 2018. All rights reserved.
12 | ************************************************************************/
13 | using ProtocolGenerator.Core;
14 | using ProtocolGenerator.Core.CSharp;
15 | using ProtocolGenerator.Core.Java;
16 | using ProtocolGenerator.Core.Lua;
17 | using ProtocolGenerator.ProtoBuf;
18 | using System.Collections.Generic;
19 |
20 | namespace ProtocolGenerator
21 | {
22 | public class GeneratorManager
23 | {
24 | private static GeneratorManager _inst;
25 | private GeneratorManager()
26 | {
27 | }
28 | public static GeneratorManager GetInstance()
29 | {
30 | if (_inst == null)
31 | {
32 | _inst = new GeneratorManager();
33 | }
34 | return _inst;
35 | }
36 |
37 | private Dictionary _generaters = new Dictionary();
38 |
39 | public void Init(string type)
40 | {
41 | switch (type)
42 | {
43 | case "all":
44 | Add(GeneratorType.Proto,new ProtoGenerator());
45 | Add(GeneratorType.CSharp, new CSharpGenerator());
46 | Add(GeneratorType.Java, new JavaGenerator());
47 | //Add(GeneratorType.Lua,new LuaGenerator());
48 | break;
49 | case "java":
50 | Add(GeneratorType.Proto, new ProtoGenerator());
51 | Add(GeneratorType.Java, new JavaGenerator());
52 | break;
53 | case "CSharp":
54 | Add(GeneratorType.Proto, new ProtoGenerator());
55 | Add(GeneratorType.CSharp, new CSharpGenerator());
56 | break;
57 | case "Lua":
58 | Add(GeneratorType.Proto, new ProtoGenerator());
59 | Add(GeneratorType.Lua,new LuaGenerator());
60 | break;
61 | case "default":
62 | Add(GeneratorType.Proto,new ProtoGenerator());
63 | Add(GeneratorType.CSharp, new CSharpGenerator());
64 | break;
65 | case "CSharpId":
66 | Add(GeneratorType.CSharp, new CSharpGenerator());
67 | break;
68 | case "JavaId":
69 | Add(GeneratorType.Java, new JavaGenerator());
70 | break;
71 | case "id":
72 | Add(GeneratorType.CSharp, new CSharpGenerator());
73 | Add(GeneratorType.Java, new JavaGenerator());
74 | break;
75 | default:
76 | break;
77 | }
78 | }
79 |
80 | private void Add(GeneratorType type, IGenerator Generator)
81 | {
82 | if (_generaters.ContainsKey(type))
83 | {
84 |
85 | }
86 | else
87 | {
88 | _generaters.Add(type, Generator);
89 | }
90 | }
91 |
92 | public void GenerateId()
93 | {
94 | foreach (var gen in _generaters)
95 | {
96 | gen.Value.Generate();
97 | }
98 | }
99 |
100 | public void Run()
101 | {
102 | Dictionary dates = DataManager.GetInstance().DataDic;
103 | if (dates == null)
104 | {
105 | return;
106 | }
107 |
108 | foreach (var item in dates)
109 | {
110 | foreach (var gen in _generaters)
111 | {
112 | gen.Value.Generate(item.Value);
113 | }
114 | }
115 | }
116 |
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/ProtocolGenerator/Core/ICodeGenerater.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Text;
3 |
4 | namespace ProtocolGenerator
5 | {
6 | public interface ICodeGenerator
7 | {
8 | ///
9 | /// 变量框架
10 | ///
11 | ///
12 | ///
13 | ///
14 | ///
15 | StringBuilder AttrFrame(string attrType, string attrName, int spaceCount = 2);
16 | ///
17 | /// 类框架
18 | ///
19 | ///
20 | ///
21 | ///
22 | ///
23 | ///
24 | StringBuilder ClassFrame(string className, List attrs = null, List methods = null, int spaceCount = 1);
25 | ///
26 | /// 文件开头说明文字框架
27 | ///
28 | ///
29 | StringBuilder ClassCommentsFrame();
30 | ///
31 | /// 包含头文件框架
32 | ///
33 | ///
34 | StringBuilder IncludeHeadFrame(List includes);
35 | ///
36 | /// 函数框架
37 | ///
38 | ///
39 | ///
40 | ///
41 | ///
42 | ///
43 | StringBuilder MethodFrame(string methodType, string methodName, List methodValue, int spaceCount = 2);
44 | ///
45 | /// namespace框架
46 | ///
47 | ///
48 | ///
49 | ///
50 | StringBuilder NameSpaceFrame(string nameSpace, StringBuilder classBody);
51 | }
52 | }
--------------------------------------------------------------------------------
/ProtocolGenerator/Core/IGenerater.cs:
--------------------------------------------------------------------------------
1 | /************************************************************************
2 | * 项目名称 : ProtocolGenerator
3 | * 项目描述 :
4 | * 类 名 称 : IGenerator
5 | * 版 本 号 : v1.0.0.0
6 | * 说 明 :
7 | * 作 者 : Boiling
8 | * 创建时间 : 2018/4/20 星期五 15:55:08
9 | * 更新时间 : 2018/4/20 星期五 15:55:08
10 | ************************************************************************
11 | * Copyright @ BoilingBlood 2018. All rights reserved.
12 | ************************************************************************/
13 | namespace ProtocolGenerator
14 | {
15 | public interface IGenerator
16 | {
17 | void Generate();
18 | void Generate(Data data);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/ProtocolGenerator/Core/Java/JavaClass_Id.cs:
--------------------------------------------------------------------------------
1 | /************************************************************************
2 | * 项目名称 : ProtocolGenerator.Core.Java
3 | * 类 名 称 : JavaClass_Id
4 | * 类 描 述 :
5 | * 版 本 号 : v1.0.0.0
6 | * 说 明 :
7 | * 作 者 : FReedom
8 | * 创建时间 : 2018/4/21 星期六 11:28:25
9 | * 更新时间 : 2018/4/21 星期六 11:28:25
10 | ************************************************************************
11 | * Copyright @ BoilingBlood 2018. All rights reserved.
12 | ************************************************************************/
13 | using System.Collections.Generic;
14 | using System.Text;
15 |
16 | namespace ProtocolGenerator.Core.Java
17 | {
18 | public class JavaClass_Id : AbstractFileModel
19 | {
20 | JavaCodeGenerator _generater = new JavaCodeGenerator();
21 | public const string msgIdPackageName = "message.idgenerator";
22 | public const string className = "Id";
23 |
24 | public JavaClass_Id()
25 | {
26 | string tempPath = msgIdPackageName.Replace('.', '\\');
27 | m_filePath = Program.OutputPath + @"\Java\" + tempPath + @"\";
28 | m_fileName = "Id";
29 | m_fileSuffix = ".java";
30 | }
31 |
32 | protected override StringBuilder GenerateClassCode()
33 | {
34 | StringBuilder fileContent = new StringBuilder();
35 | StringBuilder fileComments = _generater.ClassCommentsFrame();
36 | StringBuilder fileIncludeHeads = _generater.IncludeHeadFrame(getInclude());
37 | StringBuilder classFrame = _generater.ClassFrame("class " + className, getAttrs(), getMethods(),0);
38 | fileContent.Append(fileComments);
39 | fileContent.Append(fileIncludeHeads);
40 | fileContent.Append(classFrame);
41 | return fileContent;
42 | }
43 |
44 | private List getInclude()
45 | {
46 | //package Protocol;
47 | //import java.util.HashMap;
48 | //import com.google.protobuf.MessageLite;
49 | List list = new List();
50 | list.Add("package " + msgIdPackageName + ";");
51 | list.Add("import java.util.HashMap;");
52 | list.Add("import com.google.protobuf.MessageLite;");
53 | return list;
54 | }
55 |
56 | private List getMethods()
57 | {
58 | List attrs = new List();
59 | attrs.Add(_generater.AttrFrame("return", "inst", 1));
60 | List methods = new List();
61 | //public static final Id getInst()
62 | //{
63 | // return inst;
64 | //}
65 | StringBuilder classMethod = _generater.MethodFrame("static final Id", "getInst()", attrs,1);
66 | //public int getMessageId(Class> clazz)
67 | //{
68 | // return clazzIdMap.get(clazz);
69 | //}
70 | attrs = new List();
71 | attrs.Add(_generater.AttrFrame("return", "clazzIdMap.get(clazz)", 1));
72 | methods.Add(classMethod);
73 | classMethod = _generater.MethodFrame("int", "getMessageId(Class> clazz)", attrs,1);
74 | methods.Add(classMethod);
75 | //public int SetMessage(Class extends MessageLite> msgClass, int messageId)
76 | //{
77 | // return clazzIdMap.put(msgClass, messageId);
78 | //}
79 | attrs = new List();
80 | attrs.Add(_generater.AttrFrame("", "clazzIdMap.put(msgClass, messageId)", 1));
81 | classMethod = _generater.MethodFrame("void", "SetMessage(Class extends MessageLite> msgClass, int messageId)", attrs,1);
82 |
83 | methods.Add(classMethod);
84 | return methods;
85 | }
86 |
87 | public List getAttrs()
88 | {
89 | List attrs = new List();
90 |
91 | //private static final Id inst = new Id();
92 | StringBuilder classAttr = _generater.AttrFrame("private static final Id", "inst = new Id()",1);
93 | attrs.Add(classAttr);
94 | //private HashMap, Integer> clazzIdMap = new HashMap, Integer>();
95 | classAttr = _generater.AttrFrame("private HashMap, Integer>", "clazzIdMap = new HashMap, Integer>()",1);
96 | attrs.Add(classAttr);
97 | return attrs;
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/ProtocolGenerator/Core/Java/JavaClass_IdGenerator.cs:
--------------------------------------------------------------------------------
1 | /************************************************************************
2 | * 项目名称 : ProtocolGenerator.Core.Java
3 | * 类 名 称 : JavaClass_IdGenerator
4 | * 类 描 述 :
5 | * 版 本 号 : v1.0.0.0
6 | * 说 明 :
7 | * 作 者 : FReedom
8 | * 创建时间 : 2018/4/21 星期六 12:32:13
9 | * 更新时间 : 2018/4/21 星期六 12:32:13
10 | ************************************************************************
11 | * Copyright @ BoilingBlood 2018. All rights reserved.
12 | ************************************************************************/
13 | using System.Collections.Generic;
14 | using System.Text;
15 |
16 | namespace ProtocolGenerator.Core.Java
17 | {
18 | public class JavaClass_IdGenerator : AbstractFileModel
19 | {
20 | JavaCodeGenerator _generater = new JavaCodeGenerator();
21 | string className = "IdGenerator";
22 | Data _data = null;
23 | public JavaClass_IdGenerator(Data data)
24 | {
25 | _data = data;
26 | string tempPath = _data.ProtoPackageName.Replace('.', '\\');
27 | m_filePath = Program.OutputPath + @"\Java\" + tempPath + @"\";
28 | m_fileName = _data.ProtoFileKey;
29 | m_fileSuffix = "IdGenerator.java";
30 | className = m_fileName + className;
31 | }
32 | private StringBuilder GenerateIdKey(string key)
33 | {
34 | StringBuilder sb = new StringBuilder();
35 | sb.Append("Id.getInst().SetMessage(");
36 | sb.Append(_data.ProtoPackageName+"."+_data.ProtoFileKey+".");
37 | sb.Append(key);
38 | sb.Append(".class,");
39 | return sb;
40 | }
41 |
42 | private StringBuilder GenerateIdValue(string value)
43 | {
44 | StringBuilder sb = new StringBuilder();
45 | sb.Append(value+")");
46 | return sb;
47 | }
48 |
49 | private List getInclude()
50 | {
51 | //package Protocol.Client.C2G;
52 | //import Protocol.Id;
53 | //import Protocol.Client.C2G.CGCode.MSG_C2G_Heartbeat;
54 | List list = new List();
55 | list.Add("package " + _data.ProtoPackageName + ";");
56 | list.Add("import "+ JavaClass_Id.msgIdPackageName + "." + JavaClass_Id.className + ";");
57 | //list.Add("import com.google.protobuf.MessageLite;");
58 | return list;
59 | }
60 |
61 | protected override StringBuilder GenerateClassCode()
62 | {
63 | StringBuilder fileContent = new StringBuilder();
64 | StringBuilder fileComments = _generater.ClassCommentsFrame();
65 | StringBuilder fileIncludeHeads = _generater.IncludeHeadFrame(getInclude());
66 |
67 | List attrs = new List();
68 | foreach (var item in _data.DicName2Id)
69 | {
70 | StringBuilder classAttrFrame = _generater.AttrFrame(GenerateIdKey(item.Key).ToString(), GenerateIdValue(item.Value).ToString(), 1);
71 | attrs.Add(classAttrFrame);
72 | }
73 |
74 | StringBuilder classMethodFrame = _generater.MethodFrame("static void", "GenerateId()", attrs, 1);
75 | List methods = new List();
76 | methods.Add(classMethodFrame);
77 |
78 | StringBuilder classFrame = _generater.ClassFrame("class " + className, null, methods,0);
79 |
80 | fileContent.Append(fileComments);
81 | fileContent.Append(fileIncludeHeads);
82 | fileContent.Append(classFrame);
83 | return fileContent;
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/ProtocolGenerator/Core/Java/JavaClass_Proto.cs:
--------------------------------------------------------------------------------
1 | /************************************************************************
2 | * 项目名称 : ProtocolGenerator.Core.Java
3 | * 类 名 称 : JavaClass_Proto
4 | * 类 描 述 :
5 | * 版 本 号 : v1.0.0.0
6 | * 说 明 :
7 | * 作 者 : FReedom
8 | * 创建时间 : 2018/4/21 星期六 12:32:44
9 | * 更新时间 : 2018/4/21 星期六 12:32:44
10 | ************************************************************************
11 | * Copyright @ BoilingBlood 2018. All rights reserved.
12 | ************************************************************************/
13 | using System.Diagnostics;
14 | using System.Windows.Forms;
15 |
16 | namespace ProtocolGenerator.Core.Java
17 | {
18 | public class JavaClass_Proto
19 | {
20 | private string m_InputfilePath;
21 | private string m_OutputfilePath;
22 | private string m_InputfileName;
23 | private string m_InpufileSuffix;
24 | private string m_InputfileSimpleName;
25 |
26 | Data _data = null;
27 |
28 | public JavaClass_Proto(Data data)
29 | {
30 | _data = data;
31 | string tempPath = _data.ProtoPackageName.Replace('.', '\\');
32 | m_OutputfilePath = Program.OutputPath + @"\Java\";
33 | m_InputfileName = data.ProtoFileKey;
34 | m_InpufileSuffix = ".proto";
35 | m_InputfileSimpleName = m_InputfileName + m_InpufileSuffix;
36 |
37 | #region 指定路径
38 | //m_InputfilePath = Program.OutputPath + @"Proto\" + tempPath + @"\";
39 | #endregion
40 | #region 当前路径与code同路径
41 | string tempfilename = m_InputfileName + ".code";
42 | m_InputfilePath = Program.Filename.Replace(tempfilename, "");
43 | #endregion
44 |
45 | }
46 |
47 | public void GenerateProto()
48 | {
49 | //调用外部程序protogen.exe
50 | Process p = new Process();
51 | //p.StartInfo.FileName = "cmd.exe";
52 | p.StartInfo.FileName = Application.StartupPath + @"\google_protoc\protoc.exe";
53 | //p.StartInfo.WorkingDirectory = Application.StartupPath;
54 | p.StartInfo.UseShellExecute = false;
55 | p.StartInfo.CreateNoWindow = false;
56 | p.StartInfo.RedirectStandardInput = true;
57 | p.StartInfo.RedirectStandardOutput = false;
58 | //protoc D:\a\userinfo.proto -ID:\a --java_out = D:\a
59 | p.StartInfo.Arguments = m_InputfileSimpleName + @" -I" + m_InputfilePath + @" --java_out=" + m_OutputfilePath;
60 | //Console.WriteLine("{0} {1}", p.StartInfo.FileName, p.StartInfo.Arguments);
61 |
62 | p.Start();
63 | p.StandardInput.WriteLine("exit");
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/ProtocolGenerator/Core/Java/JavaCodeGenerator.cs:
--------------------------------------------------------------------------------
1 | /************************************************************************
2 | * 项目名称 : ProtocolGenerator.Core.Java
3 | * 类 名 称 : JavaCodeGenerator
4 | * 类 描 述 :
5 | * 版 本 号 : v1.0.0.0
6 | * 说 明 :
7 | * 作 者 : FReedom
8 | * 创建时间 : 2018/4/21 星期六 11:32:14
9 | * 更新时间 : 2018/4/21 星期六 11:32:14
10 | ************************************************************************
11 | * Copyright @ BoilingBlood 2018. All rights reserved.
12 | ************************************************************************/
13 | using System;
14 | using System.Collections.Generic;
15 | using System.Text;
16 |
17 | namespace ProtocolGenerator.Core.Java
18 | {
19 | public class JavaCodeGenerator : ICodeGenerator
20 | {
21 | string spaceStr = " ";
22 | private string SetSpace(int spaceCount)
23 | {
24 | StringBuilder space = new StringBuilder();
25 | for (int i = 0; i < spaceCount; i++)
26 | {
27 | space.Append(spaceStr);
28 | }
29 | return space.ToString();
30 | }
31 | public StringBuilder ClassCommentsFrame()
32 | {
33 | //------------------------------------------------------------------------------
34 | //
35 | // This code was generated by a tool.(The author is Boiling)
36 | // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
37 | //
38 | //------------------------------------------------------------------------------
39 |
40 | StringBuilder sb = new StringBuilder();
41 | sb.Append(" //------------------------------------------------------------------------------");
42 | sb.Append(Environment.NewLine);
43 | sb.Append(" // ");
44 | sb.Append(Environment.NewLine);
45 | sb.Append(" // This code was generated by a tool.(The author is Boiling)");
46 | sb.Append(Environment.NewLine);
47 | sb.Append(" // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.");
48 | sb.Append(Environment.NewLine);
49 | sb.Append(" // ");
50 | sb.Append(Environment.NewLine);
51 | sb.Append(" //------------------------------------------------------------------------------");
52 | sb.Append(Environment.NewLine);
53 | return sb;
54 | }
55 |
56 | public StringBuilder IncludeHeadFrame( List imports)
57 | {
58 | StringBuilder sb = new StringBuilder();
59 | foreach (var item in imports)
60 | {
61 | sb.Append(item);
62 | sb.Append(Environment.NewLine);
63 | }
64 | return sb;
65 | }
66 |
67 |
68 | public StringBuilder AttrFrame(string attrType, string attrName, int spaceCount = 2)
69 | {
70 | StringBuilder sb = new StringBuilder();
71 | sb.Append(SetSpace(spaceCount));
72 | sb.Append(attrType);
73 | sb.Append(" ");
74 | sb.Append(attrName);
75 | sb.Append(";");
76 | sb.Append(Environment.NewLine);
77 | return sb;
78 | }
79 |
80 | public StringBuilder ClassFrame(string className, List attrs = null, List methods = null, int spaceCount = 1)
81 | {
82 | StringBuilder sb = new StringBuilder();
83 | sb.Append(SetSpace(spaceCount));
84 | sb.Append("public ");
85 | sb.Append(className);
86 | sb.Append("{");
87 | sb.Append(Environment.NewLine);
88 | if (attrs != null)
89 | {
90 | foreach (var item in attrs)
91 | {
92 | sb.Append(item.ToString());
93 | }
94 | }
95 | if (methods != null)
96 | {
97 | foreach (var item in methods)
98 | {
99 | sb.Append(item.ToString());
100 | }
101 | }
102 | sb.Append(SetSpace(spaceCount));
103 | sb.Append("}");
104 | return sb;
105 | }
106 |
107 | public StringBuilder MethodFrame(string methodType, string methodName, List methodValue, int spaceCount = 2)
108 | {
109 | StringBuilder sb = new StringBuilder();
110 | sb.Append(SetSpace(spaceCount));
111 | sb.Append("public ");
112 | sb.Append(methodType);
113 | sb.Append(" ");
114 | sb.Append(methodName);
115 | sb.Append("{");
116 | sb.Append(Environment.NewLine);
117 | foreach (var item in methodValue)
118 | {
119 | sb.Append(SetSpace(1));
120 | sb.Append(item.ToString());
121 | }
122 | sb.Append(SetSpace(spaceCount));
123 | sb.Append("}");
124 | sb.Append(Environment.NewLine);
125 | return sb;
126 | }
127 |
128 | public StringBuilder NameSpaceFrame(string nameSpace, StringBuilder classBody)
129 | {
130 | return null;
131 | }
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/ProtocolGenerator/Core/Java/JavaGenerator.cs:
--------------------------------------------------------------------------------
1 | /************************************************************************
2 | * 项目名称 : ProtocolGenerator.CSharp
3 | * 类 名 称 : CSharpGenerator
4 | * 类 描 述 :
5 | * 版 本 号 : v1.0.0.0
6 | * 说 明 :
7 | * 作 者 : FReedom
8 | * 创建时间 : 2018/4/21 星期五 12:28:28
9 | * 更新时间 : 2018/4/21 星期五 12:28:28
10 | ************************************************************************
11 | * Copyright @ BoilingBlood 2018. All rights reserved.
12 | ************************************************************************/
13 |
14 | namespace ProtocolGenerator.Core.Java
15 | {
16 | public class JavaGenerator : IGenerator
17 | {
18 | public void Generate()
19 | {
20 | JavaClass_Id classGen = new JavaClass_Id();
21 | classGen.Generate();
22 | }
23 | public void Generate(Data data)
24 | {
25 | JavaClass_IdGenerator classGen = new JavaClass_IdGenerator(data);
26 | classGen.Generate();
27 | JavaClass_Proto protoGen = new JavaClass_Proto(data);
28 | protoGen.GenerateProto();
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/ProtocolGenerator/Core/Lua/LuaGenerator.cs:
--------------------------------------------------------------------------------
1 |
2 | using System;
3 |
4 | namespace ProtocolGenerator.Core.Lua
5 | {
6 | public class LuaGenerator : IGenerator
7 | {
8 | public void Generate()
9 | {
10 | //JavaClass_Id classGen = new JavaClass_Id();
11 | //classGen.Generate();
12 | Console.WriteLine("LuaGenerater Generate()");
13 | }
14 | public void Generate(Data data)
15 | {
16 | //JavaClass_IdGenerater classGen = new JavaClass_IdGenerater(data);
17 | //classGen.Generate();
18 | Lua_Proto protoGen = new Lua_Proto(data);
19 | protoGen.GenerateProto();
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/ProtocolGenerator/Core/Lua/Lua_Proto.cs:
--------------------------------------------------------------------------------
1 | /************************************************************************
2 | * 项目名称 : ProtocolGenerater.Core.Lua
3 | * 类 名 称 : Lua_Proto
4 | * 类 描 述 :
5 | * 版 本 号 : v1.0.0.0
6 | * 说 明 :
7 | * 作 者 : FReedom
8 | * 创建时间 : 2019/3/21 星期三 12:32:44
9 | * 更新时间 : 2019/3/21 星期三 12:32:44
10 | ************************************************************************
11 | * Copyright @ BoilingBlood 2018. All rights reserved.
12 | ************************************************************************/
13 | using System.Diagnostics;
14 | using System.Windows.Forms;
15 |
16 | namespace ProtocolGenerator.Core.Lua
17 | {
18 | public class Lua_Proto
19 | {
20 | private string m_InputfilePath;
21 | private string m_OutputfilePath;
22 | private string m_InputfileName;
23 | private string m_InpufileSuffix;
24 | private string m_InputfileSimpleName;
25 |
26 | Data _data = null;
27 |
28 | public Lua_Proto(Data data)
29 | {
30 | _data = data;
31 | string tempPath = _data.ProtoPackageName.Replace('.', '\\');
32 | m_OutputfilePath = Program.OutputPath + @"Lua\";
33 | m_InputfileName = data.ProtoFileKey;
34 | m_InpufileSuffix = ".proto";
35 | m_InputfileSimpleName = m_InputfileName + m_InpufileSuffix;
36 |
37 | #region 指定路径
38 | //m_InputfilePath = Program.OutputPath + @"Proto\" + tempPath + @"\";
39 | #endregion
40 | #region 当前路径与code同路径
41 | string tempfilename = m_InputfileName + ".code";
42 | m_InputfilePath = Program.Filename.Replace(tempfilename, "");
43 | #endregion
44 |
45 | }
46 |
47 | public void GenerateProto()
48 | {
49 | //调用外部程序protogen.exe
50 | Process p = new Process();
51 | //p.StartInfo.FileName = "cmd.exe";
52 | p.StartInfo.FileName = Application.StartupPath + @"\google_protoc\protoc.exe";
53 | //p.StartInfo.WorkingDirectory = Application.StartupPath;
54 | p.StartInfo.UseShellExecute = false;
55 | p.StartInfo.CreateNoWindow = false;
56 | p.StartInfo.RedirectStandardInput = true;
57 | p.StartInfo.RedirectStandardOutput = false;
58 | //protoc D:\a\userinfo.proto -ID:\a --java_out = D:\a
59 | //p.StartInfo.Arguments = m_InputfileSimpleName + @" -I" + m_InputfilePath + @" --lua_out=" + m_OutputfilePath;
60 | //string aa = @"C:\Users\WanXin\source\repos\ProtocolGenerater\ProtocolBuffers\google_protoc\protoc-gen-lua-master\plugin\protoc-gen-lua.bat";
61 | string plugin = Application.StartupPath + @"\google_protoc\protoc-gen-lua-master\plugin\protoc-gen-lua.bat";
62 | p.StartInfo.Arguments = m_InputfileSimpleName + @" -I" + m_InputfilePath + " --plugin=protoc-gen-lua="+ plugin + @" --lua_out=" + m_OutputfilePath;
63 | //Console.WriteLine("{0} {1}", p.StartInfo.FileName, p.StartInfo.Arguments);
64 | p.Start();
65 | p.StandardInput.WriteLine("exit");
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/ProtocolGenerator/Core/ProtoBuf/ProtoFileGenerater.cs:
--------------------------------------------------------------------------------
1 | /************************************************************************
2 | * 项目名称 : ProtocolGenerator.ProtoBuf
3 | * 类 名 称 : ProtoFileGenerator
4 | * 类 描 述 : 生成.proto文件
5 | * 版 本 号 : v1.0.0.0
6 | * 说 明 :
7 | * 作 者 : FReedom
8 | * 创建时间 : 2018/4/20 星期五 18:53:05
9 | * 更新时间 : 2018/4/20 星期五 18:53:05
10 | ************************************************************************
11 | * Copyright @ BoilingBlood 2018. All rights reserved.
12 | ************************************************************************/
13 | using System;
14 | using System.Text;
15 |
16 | namespace ProtocolGenerator.ProtoBuf
17 | {
18 | public class ProtoFileGenerator : AbstractFileModel
19 | {
20 | public string fileName = string.Empty;
21 | public string fileSuffix = ".proto";
22 | Data _data = null;
23 |
24 | public ProtoFileGenerator(Data data)
25 | {
26 | _data = data;
27 | m_fileName = data.ProtoFileKey;
28 | m_fileSuffix = ".proto";
29 |
30 | string tempPath = _data.ProtoPackageName.Replace('.', '\\');
31 | #region 指定路径
32 | //m_filePath = Program.OutputPath + @"Proto\" + tempPath + @"\";
33 | #endregion
34 | #region 当前路径与code同路径
35 | string tempfilename = m_fileName + ".code";
36 | m_filePath = Program.Filename.Replace(tempfilename, "");
37 | #endregion
38 |
39 | // Console.WriteLine("!!!m_filePath {0} m_fileName {1} tempfilename{2}", m_filePath, m_fileName, tempfilename);
40 | }
41 |
42 | protected override StringBuilder GenerateClassCode()
43 | {
44 | return _data.ProtoCode;
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/ProtocolGenerator/Core/ProtoBuf/ProtoGenerater.cs:
--------------------------------------------------------------------------------
1 | /************************************************************************
2 | * 项目名称 : ProtocolGenerator.ProtoBuf
3 | * 类 名 称 : ProtoBufGenerator
4 | * 类 描 述 : 生成.proto文件
5 | * 版 本 号 : v1.0.0.0
6 | * 说 明 :
7 | * 作 者 : FReedom
8 | * 创建时间 : 2018/4/20 星期五 18:49:43
9 | * 更新时间 : 2018/4/20 星期五 18:49:43
10 | ************************************************************************
11 | * Copyright @ BoilingBlood 2018. All rights reserved.
12 | ************************************************************************/
13 |
14 | namespace ProtocolGenerator.ProtoBuf
15 | {
16 | public class ProtoGenerator : IGenerator
17 | {
18 | public void Generate(Data data)
19 | {
20 | ProtoFileGenerator fileGenerator = new ProtoFileGenerator(data);
21 | fileGenerator.Generate();
22 | }
23 |
24 | public void Generate()
25 | {
26 | return;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/ProtocolGenerator/Program.cs:
--------------------------------------------------------------------------------
1 | /************************************************************************
2 | * 项目名称 : ProtocolGenerator
3 | * 项目描述 :
4 | * 类 名 称 : Program
5 | * 版 本 号 : v1.0.0.0
6 | * 说 明 :
7 | * 作 者 : Boiling
8 | * 创建时间 : 2018/4/20 星期五 15:55:08
9 | * 更新时间 : 2018/4/20 星期五 15:55:08
10 | ************************************************************************
11 | * Copyright @ BoilingBlood 2018. All rights reserved.
12 | ************************************************************************/
13 | using System;
14 | using System.IO;
15 |
16 | namespace ProtocolGenerator
17 | {
18 | class Program
19 | {
20 | public static string InputPath = null;
21 | public static string OutputPath = null;
22 | public static string Filename = null;
23 |
24 |
25 | static void Main(string[] args)
26 | {
27 | //1 >>> --input_path = D:\GitHub\ProtocolGenerator\ProtocolForClient\
28 | //1 >>> --output_path = D:\GitHub\ProtocolGenerator\Bin\
29 | //1 >>> --filename = D:\GitHub\ProtocolGenerator\ProtocolForClient\Client\C2G.code
30 | string operationType = "default";
31 |
32 | foreach (string arg in args)
33 | {
34 | //Console.WriteLine(">>>{0} ", arg);
35 | string lhs = arg, rhs = "";
36 | int index = arg.IndexOf('=');
37 | if (index > 0)
38 | {
39 | lhs = arg.Substring(0, index);
40 | rhs = arg.Substring(index + 1);
41 | }
42 |
43 | switch (lhs)
44 | {
45 | case "":
46 | break;
47 | case "--operate_type":
48 | operationType = rhs;
49 | break;
50 | case "--input_path":
51 | InputPath = rhs;
52 | break;
53 | case "--output_path":
54 | OutputPath = rhs;
55 | break;
56 | case "--filename":
57 | if (rhs.ToLower().EndsWith(".code".ToLower()))
58 | {
59 | Filename = rhs;
60 | }
61 | else
62 | {
63 | Console.WriteLine("File type error :{0} ( mast ends with .code ) ", rhs);
64 | return;
65 | }
66 | break;
67 | default:
68 | break;
69 | }
70 | }
71 |
72 | if (!DataManager.GetInstance().CheckFilePast(Filename))
73 | {
74 | #if DEBUG
75 | Console.WriteLine("File no change: {0}", Filename);
76 | #else
77 | return;
78 | #endif
79 | }
80 |
81 | GeneratorManager.GetInstance().Init(operationType);
82 |
83 | if (operationType == "all")
84 | {
85 | DataManager.GetInstance().Load(Filename);
86 | }
87 | else if (operationType == "CSharpId" || operationType == "JavaId" || operationType == "id")
88 | {
89 | GeneratorManager.GetInstance().GenerateId();
90 | }
91 | else if (operationType == "default")
92 | {
93 | GeneratorManager.GetInstance().GenerateId();
94 | if (InputPath == null)
95 | {
96 | Console.WriteLine("operationType got an error. InputPath = null");
97 | return;
98 | }
99 | else
100 | {
101 | try
102 | {
103 | string[] files = FileUtil.FindFiles(InputPath, "*.code");
104 | foreach (var file in files)
105 | {
106 | DataManager.GetInstance().Load(file);
107 | }
108 | }
109 | catch (Exception e)
110 | {
111 | Console.WriteLine("operationType got an error. {0}", e.Message);
112 | return;
113 | }
114 | }
115 | }
116 | else
117 | {
118 | DataManager.GetInstance().Load(Filename);
119 | }
120 | GeneratorManager.GetInstance().Run();
121 | }
122 | }
123 | }
--------------------------------------------------------------------------------
/ProtocolGenerator/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "profiles": {
3 | "ProtocolGenerator": {
4 | "commandName": "Project",
5 | "commandLineArgs": "--operate_type=CSharp --input_path=D:\\GitHub\\ProtocolGenerator\\ProtocolBuilder --output_path=D:\\GitHub\\ProtocolGenerator\\Cache\\ --filename=D:\\GitHub\\ProtocolGenerator\\ProtocolBuilder\\Server\\ServerRegister.code"
6 | }
7 | }
8 | }
--------------------------------------------------------------------------------
/ProtocolGenerator/ProtocolGenerator.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net35
6 |
7 |
8 |
9 | ../Output
10 | TRACE
11 |
12 |
13 |
14 | ../Output
15 | DEBUG;TRACE
16 | x86
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/ProtocolGenerator/Utils/StringUtil.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text.RegularExpressions;
3 |
4 | namespace ProtocolBuffersGenerator.Utils
5 | {
6 | public class StringUtil
7 | {
8 | ///
9 | /// 判断是否十六进制格式 的ID串
10 | ///
11 | ///
12 | //public static bool IsHexadecimal(string str)
13 | public static bool IsHexadecimalId(string str)
14 | {
15 | string head = str.Substring(0, 2);
16 | if (!head.Equals("0x"))
17 | {
18 | return false;
19 | }
20 | else
21 | {
22 | string body = str.Substring(2);
23 | body = body.TrimStart('0');
24 | //考虑到32位去掉符号位为31位。作为协议Id索性取7位16进制
25 | if (body.Length > 7 ||body.Length<1)
26 | {
27 | Console.WriteLine("error id {0} ,maximum number must not exceed 7-bit hexadecimal!", str);
28 | return false;
29 | }
30 | const string PATTERN = @"[A-Fa-f0-9]+$";
31 | return Regex.IsMatch(str, PATTERN);
32 | }
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/ProtocolLib/IdGenerator/Id.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.(The author is Boiling)
4 | // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
5 | //
6 | //------------------------------------------------------------------------------
7 | namespace Message.IdGenerator
8 | {
9 | public static class Id
10 | {
11 | public static uint Value;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ProtocolLib/ProtocolLib.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net35
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/ProtocolLib/Server/Register/ServerRegisterIdGenerator.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.(The author is Boiling)
4 | // Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
5 | //
6 | //------------------------------------------------------------------------------
7 | namespace Message.Server.Register
8 | {
9 | public class ServerRegisterIdGenerator
10 | {
11 | public static void GenerateId()
12 | {
13 | Message.IdGenerator.Id.Value= 0xff0001;
14 | Message.IdGenerator.Id.Value= 0xff0002;
15 | Message.IdGenerator.Id.Value= 0xff0004;
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ProtocolGenerator
2 |
3 | Protobuf批量管理自动生成方案(2019/03/20)
4 | ================================================
5 | 简介
6 | -------------------------------------------
7 | 这是一个批量管理生成协议文件的方式。
8 |
9 | 如子目录ProtocolBuilder项目,是一个协议管理项目的例子
10 |
11 | 将协议模型内容写入项目中的.code文件内,可以写入多个,然后,通过生成项目的方式,一键生成相应语言环境下的protobuf相关代码
12 |
13 | 目前
14 | -----------------------------------------
15 | 手游主流客户端开发,多为Unity3D,要用到c#
16 |
17 | 服务端开发多用c++、java,同样也有用c#的,
18 |
19 | 所以,这里主要实现c#,java,c++这3种语言(下文中各个语言)的protobuf协议的自动批量生成。
20 |
21 | 谷歌protobuf分两个版本,proto2和proto3,
22 |
23 | 其中,版本syntax="proto3",Google/protobuf原生全面支持各个语言 https://github.com/google/protobuf
24 | 注:我这里不再维护proto2相关内容。
25 |
26 | 所以,我用官方protoc.exe来生成代码: https://github.com/protocolbuffers/protobuf/releases/download/v3.6.0/protoc-3.6.0-win32.zip
27 |
28 | 截止目前为止,依然只实现了java和c#代码(c++的后续跟进)
29 |
30 | 具体需求和实现思路
31 | --------------------------------------
32 | 我定义的协议格式为:
33 | ```c
34 | length + msgId + msgData
35 | ```
36 | length为short型的数据长度,msgId为int32的协议编号,msgData为标准protobuf数据。
37 |
38 | 其中,msgId和msgData的描述模型,是以如下格式写在.code后缀的文件中的:
39 | ```c
40 | message A2BTest 0xff00001
41 | {
42 | required int32 testInt = 1;
43 | required string testString = 2;
44 | }
45 | ```
46 | A2BTest为协议名msgName, 0xff00001为协议编号msgId,testInt为int32类型字段,testString为string类型字段
47 |
48 | 可以看出,这个模型是在标准.proto结构的msgName后面加了一个msgId ,形成列一个新的协议描述模型
49 |
50 | 我这里做的就是:
51 | ---------------------------------------------
52 | 1 将这个模型,拆分成msgId和标准的.proto协议
53 |
54 | 2 通过标准的.proto协议,生成对应语言的protobuf协议代码。
55 |
56 | 3 生成相应语言的msgId与msgName之间的映射
57 |
58 | 4 实现批量完成上述操作。
59 |
60 | 大致使用方式:
61 | ----------------------------------------
62 | 1 生成ProtocolGenerator.exe文件,如已经生成过了会在Output目录下
63 |
64 | 2 将如上msgId和msgValue描述模型的协议写入ProtocolBuilder项目中的.code文件。
65 |
66 | 3 生成ProtocolBuilder项目
67 |
68 | 4 会在Cache目录下找到生成好的相应语言的文件。
69 |
70 | 目前只实现了c# 和 java 的生成。
71 |
72 | 测试例子
73 | --------------------------------------
74 | 项目例子主要用c#实现,用到谷歌的protobuf源码:https://github.com/protocolbuffers/protobuf/releases/download/v3.6.0/protobuf-csharp-3.6.0.zip
75 |
76 | protobuf-csharp-3.6.0官方默认为.net4.x,但是,我这里出于unity客户端版本原因,仅支持到.net3.5。所以我选择自己编译.net35的dll。Google.Protobuf的net35项目,在子目录Google.Protobuf下面
77 |
--------------------------------------------------------------------------------
/UnitTest/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | [assembly: AssemblyTitle("UnitTest")]
6 | [assembly: AssemblyDescription("")]
7 | [assembly: AssemblyConfiguration("")]
8 | [assembly: AssemblyCompany("")]
9 | [assembly: AssemblyProduct("UnitTest")]
10 | [assembly: AssemblyCopyright("Copyright © 2019")]
11 | [assembly: AssemblyTrademark("")]
12 | [assembly: AssemblyCulture("")]
13 |
14 | [assembly: ComVisible(false)]
15 |
16 | [assembly: Guid("4469d510-4f6b-499e-9b21-825fdce48cc0")]
17 |
18 | // [assembly: AssemblyVersion("1.0.*")]
19 | [assembly: AssemblyVersion("1.0.0.0")]
20 | [assembly: AssemblyFileVersion("1.0.0.0")]
21 |
--------------------------------------------------------------------------------
/UnitTest/UnitTest.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using Message.Server.Register;
3 | using Microsoft.VisualStudio.TestTools.UnitTesting;
4 |
5 | namespace UnitTest
6 | {
7 | [TestClass]
8 | public class UnitTest
9 | {
10 | [TestMethod]
11 | public void TestProtobuf()
12 | {
13 | MSG_Server_Register fromMsg = new MSG_Server_Register();
14 | fromMsg.Tag = new Server_Tag();
15 | fromMsg.Tag.GroupId = 1;
16 | fromMsg.Tag.SubId = 11;
17 | fromMsg.Tag.ServerType = 2;
18 |
19 | MemoryStream outputstream = new MemoryStream();
20 | ProtobufHelper.ProtobufHelper.Serialize(fromMsg, outputstream);
21 |
22 | outputstream.Seek(0, SeekOrigin.Begin);
23 |
24 | MSG_Server_Register toMsg = MSG_Server_Register.Parser.ParseFrom(outputstream);
25 | }
26 |
27 | [TestMethod]
28 | public void TestProtobufHelper()
29 | {
30 | MSG_Server_Register fromMsg = new MSG_Server_Register();
31 | fromMsg.Tag = new Server_Tag();
32 | fromMsg.Tag.GroupId = 1;
33 | fromMsg.Tag.SubId = 11;
34 | fromMsg.Tag.ServerType = 2;
35 |
36 | MemoryStream outputstream = new MemoryStream();
37 | ProtobufHelper.ProtobufHelper.Serialize(fromMsg,outputstream);
38 |
39 | outputstream.Seek(0, SeekOrigin.Begin);
40 | //MSG_Server_Register toMsg = MSG_Server_Register.Parser.ParseFrom(outputstream);
41 |
42 | MSG_Server_Register toMsg = new MSG_Server_Register();
43 | toMsg =ProtobufHelper.ProtobufHelper.Deserialize(outputstream);
44 | }
45 |
46 |
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/UnitTest/UnitTest.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Debug
7 | AnyCPU
8 | {4469D510-4F6B-499E-9B21-825FDCE48CC0}
9 | Library
10 | Properties
11 | UnitTest
12 | UnitTest
13 | v4.5
14 | 512
15 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
16 | 15.0
17 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
18 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages
19 | False
20 | UnitTest
21 |
22 |
23 |
24 |
25 | true
26 | full
27 | false
28 | bin\Debug\
29 | DEBUG;TRACE
30 | prompt
31 | 4
32 |
33 |
34 | pdbonly
35 | true
36 | bin\Release\
37 | TRACE
38 | prompt
39 | 4
40 |
41 |
42 |
43 | ..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll
44 |
45 |
46 | ..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | {b42db28b-4e30-48d1-9610-98004938d3de}
61 | Google.Protobuf
62 |
63 |
64 | {16d07577-3170-4992-bd12-70750fa4bcda}
65 | ProtobufHelper
66 |
67 |
68 | {6d409e03-b2fc-4560-b81e-f0941f56d4f2}
69 | ProtocolLib
70 |
71 |
72 |
73 |
74 |
75 |
76 | 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。
77 |
78 |
79 |
80 |
81 |
82 |
--------------------------------------------------------------------------------
/UnitTest/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/keys/Google.Protobuf.public.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FRBoiling/ProtocolGenerator/0e184710b7c43195e5e4e9b3ce384fbe76afbf1e/keys/Google.Protobuf.public.snk
--------------------------------------------------------------------------------
/keys/Google.Protobuf.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FRBoiling/ProtocolGenerator/0e184710b7c43195e5e4e9b3ce384fbe76afbf1e/keys/Google.Protobuf.snk
--------------------------------------------------------------------------------
/keys/README.md:
--------------------------------------------------------------------------------
1 | Contents
2 | --------
3 |
4 | - Google.Protobuf.public.snk:
5 | Public key to verify strong name of Google.Protobuf assemblies.
6 | - Google.Protobuf.snk:
7 | Signing key to provide strong name of Google.Protobuf assemblies.
8 | As per [Microsoft guidance](https://msdn.microsoft.com/en-us/library/wd40t7ad(v=vs.110).aspx)
9 | signing key should be checked into the repository.
10 |
--------------------------------------------------------------------------------