OLD | NEW |
1 #region Copyright notice and license | |
2 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
3 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
4 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
5 // | 4 // |
6 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
7 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
8 // met: | 7 // met: |
9 // | 8 // |
10 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
11 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
12 // * Redistributions in binary form must reproduce the above | 11 // * Redistributions in binary form must reproduce the above |
13 // copyright notice, this list of conditions and the following disclaimer | 12 // copyright notice, this list of conditions and the following disclaimer |
14 // in the documentation and/or other materials provided with the | 13 // in the documentation and/or other materials provided with the |
15 // distribution. | 14 // distribution. |
16 // * Neither the name of Google Inc. nor the names of its | 15 // * Neither the name of Google Inc. nor the names of its |
17 // contributors may be used to endorse or promote products derived from | 16 // contributors may be used to endorse or promote products derived from |
18 // this software without specific prior written permission. | 17 // this software without specific prior written permission. |
19 // | 18 // |
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 // (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. | 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 #endregion | |
32 | 30 |
33 // This file just contains partial classes for any autogenerated classes that ne
ed additional support. | 31 #include <stdbool.h> |
34 namespace Google.Protobuf.Reflection | 32 #include <stdint.h> |
35 { | 33 |
36 internal partial class FieldDescriptorProto | 34 #include "utf8.h" |
37 { | 35 |
38 // We can't tell the difference between "explicitly set to 0" and "not s
et" | 36 static const uint8_t utf8_offset[] = { |
39 // in proto3, but we need to tell the difference for OneofIndex. descrip
tor.proto | 37 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
40 // is really a proto2 file, but the runtime doesn't know about proto2 se
mantics... | 38 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
41 // We fake it by defaulting to -1. | 39 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
42 partial void OnConstruction() | 40 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
43 { | 41 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
44 OneofIndex = -1; | 42 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
45 } | 43 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 44 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 45 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 46 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
| 47 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, |
| 48 }; |
| 49 |
| 50 bool is_structurally_valid_utf8(const char* buf, int len) { |
| 51 int i, j; |
| 52 uint8_t offset; |
| 53 |
| 54 i = 0; |
| 55 while (i < len) { |
| 56 offset = utf8_offset[(uint8_t)buf[i]]; |
| 57 if (offset == 0 || i + offset > len) { |
| 58 return false; |
46 } | 59 } |
47 | 60 for (j = i + 1; j < i + offset; j++) { |
48 internal partial class FieldOptions | 61 if ((buf[j] & 0xc0) != 0x80) { |
49 { | 62 return false; |
50 // We can't tell the difference between "explicitly set to false" and "n
ot set" | 63 } |
51 // in proto3, but we need to tell the difference for FieldDescriptor.IsP
acked. | |
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 } | 64 } |
59 } | 65 i += offset; |
| 66 } |
| 67 return i == len; |
| 68 } |
OLD | NEW |