Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 1 | // Protocol Buffers - Google's data interchange format |
| 2 | // Copyright 2008 Google Inc. All rights reserved. |
| 3 | // https://developers.google.com/protocol-buffers/ |
| 4 | // |
| 5 | // Redistribution and use in source and binary forms, with or without |
| 6 | // modification, are permitted provided that the following conditions are |
| 7 | // met: |
| 8 | // |
| 9 | // * Redistributions of source code must retain the above copyright |
| 10 | // notice, this list of conditions and the following disclaimer. |
| 11 | // * Redistributions in binary form must reproduce the above |
| 12 | // copyright notice, this list of conditions and the following disclaimer |
| 13 | // in the documentation and/or other materials provided with the |
| 14 | // distribution. |
| 15 | // * Neither the name of Google Inc. nor the names of its |
| 16 | // contributors may be used to endorse or promote products derived from |
| 17 | // this software without specific prior written permission. |
| 18 | // |
| 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | |
| 31 | #import <Foundation/Foundation.h> |
| 32 | |
| 33 | #import "GPBBootstrap.h" |
| 34 | |
| 35 | @class GPBEnumDescriptor; |
| 36 | @class GPBMessage; |
| 37 | @class GPBInt32Array; |
| 38 | |
| 39 | // Function used to verify that a given value can be represented by an |
| 40 | // enum type. |
| 41 | typedef BOOL (*GPBEnumValidationFunc)(int32_t); |
| 42 | |
| 43 | // Function used to fetch an EnumDescriptor. |
| 44 | typedef GPBEnumDescriptor *(*GPBEnumDescriptorFunc)(void); |
| 45 | |
| 46 | // Magic values used for when an the at runtime to indicate an enum value |
| 47 | // that wasn't know at compile time. |
| 48 | enum { |
| 49 | kGPBUnrecognizedEnumeratorValue = (int32_t)0xFBADBEEF, |
| 50 | }; |
| 51 | |
| 52 | // A union for storing all possible Protobuf values. |
| 53 | // Note that owner is responsible for memory management of object types. |
| 54 | typedef union { |
| 55 | BOOL valueBool; |
| 56 | int32_t valueInt32; |
| 57 | int64_t valueInt64; |
| 58 | uint32_t valueUInt32; |
| 59 | uint64_t valueUInt64; |
| 60 | float valueFloat; |
| 61 | double valueDouble; |
| 62 | GPB_UNSAFE_UNRETAINED NSData *valueData; |
| 63 | GPB_UNSAFE_UNRETAINED NSString *valueString; |
| 64 | GPB_UNSAFE_UNRETAINED GPBMessage *valueMessage; |
| 65 | int32_t valueEnum; |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 66 | } GPBGenericValue; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 67 | |
| 68 | // Do not change the order of this enum (or add things to it) without thinking |
| 69 | // about it very carefully. There are several things that depend on the order. |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 70 | typedef NS_ENUM(uint8_t, GPBDataType) { |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 71 | GPBDataTypeBool = 0, |
| 72 | GPBDataTypeFixed32, |
| 73 | GPBDataTypeSFixed32, |
| 74 | GPBDataTypeFloat, |
| 75 | GPBDataTypeFixed64, |
| 76 | GPBDataTypeSFixed64, |
| 77 | GPBDataTypeDouble, |
| 78 | GPBDataTypeInt32, |
| 79 | GPBDataTypeInt64, |
| 80 | GPBDataTypeSInt32, |
| 81 | GPBDataTypeSInt64, |
| 82 | GPBDataTypeUInt32, |
| 83 | GPBDataTypeUInt64, |
| 84 | GPBDataTypeBytes, |
| 85 | GPBDataTypeString, |
| 86 | GPBDataTypeMessage, |
| 87 | GPBDataTypeGroup, |
| 88 | GPBDataTypeEnum, |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 89 | }; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 90 | |
| 91 | enum { |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 92 | // A count of the number of types in GPBDataType. Separated out from the |
| 93 | // GPBDataType enum to avoid warnings regarding not handling |
| 94 | // GPBDataType_Count in switch statements. |
| 95 | GPBDataType_Count = GPBDataTypeEnum + 1 |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | // An extension range. |
| 99 | typedef struct GPBExtensionRange { |
| 100 | uint32_t start; // inclusive |
| 101 | uint32_t end; // exclusive |
| 102 | } GPBExtensionRange; |