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. |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 3 | // |
Joshua Haberman | 44bd65b | 2023-09-08 17:43:14 -0700 | [diff] [blame] | 4 | // Use of this source code is governed by a BSD-style |
| 5 | // license that can be found in the LICENSE file or at |
| 6 | // https://developers.google.com/open-source/licenses/bsd |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 7 | |
| 8 | // This header is private to the ProtobolBuffers library and must NOT be |
| 9 | // included by any sources outside this library. The contents of this file are |
| 10 | // subject to change at any time without notice. |
| 11 | |
| 12 | #import "GPBCodedInputStream.h" |
| 13 | |
Thomas Van Lenten | 231b968 | 2024-09-05 08:21:23 -0700 | [diff] [blame] | 14 | #import "GPBDescriptor.h" |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 15 | |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 16 | typedef struct GPBCodedInputStreamState { |
| 17 | const uint8_t *bytes; |
| 18 | size_t bufferSize; |
| 19 | size_t bufferPos; |
| 20 | |
| 21 | // For parsing subsections of an input stream you can put a hard limit on |
| 22 | // how much should be read. Normally the limit is the end of the stream, |
| 23 | // but you can adjust it to anywhere, and if you hit it you will be at the |
| 24 | // end of the stream, until you adjust the limit. |
| 25 | size_t currentLimit; |
| 26 | int32_t lastTag; |
| 27 | NSUInteger recursionDepth; |
| 28 | } GPBCodedInputStreamState; |
| 29 | |
| 30 | @interface GPBCodedInputStream () { |
| 31 | @package |
| 32 | struct GPBCodedInputStreamState state_; |
| 33 | NSData *buffer_; |
| 34 | } |
| 35 | |
| 36 | // Group support is deprecated, so we hide this interface from users, but |
| 37 | // support for older data. |
| 38 | - (void)readGroup:(int32_t)fieldNumber |
| 39 | message:(GPBMessage *)message |
Thomas Van Lenten | f191ab0 | 2022-09-15 14:40:15 -0400 | [diff] [blame] | 40 | extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 41 | |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 42 | // Reads a map entry. |
| 43 | - (void)readMapEntry:(id)mapDictionary |
Thomas Van Lenten | f191ab0 | 2022-09-15 14:40:15 -0400 | [diff] [blame] | 44 | extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 45 | field:(GPBFieldDescriptor *)field |
| 46 | parentMessage:(GPBMessage *)parentMessage; |
| 47 | @end |
| 48 | |
| 49 | CF_EXTERN_C_BEGIN |
| 50 | |
Thomas Van Lenten | 6ebdc7a | 2024-07-22 11:08:16 -0700 | [diff] [blame] | 51 | void GPBRaiseStreamError(NSInteger code, NSString *reason); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 52 | int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state); |
| 53 | |
| 54 | double GPBCodedInputStreamReadDouble(GPBCodedInputStreamState *state); |
| 55 | float GPBCodedInputStreamReadFloat(GPBCodedInputStreamState *state); |
| 56 | uint64_t GPBCodedInputStreamReadUInt64(GPBCodedInputStreamState *state); |
| 57 | uint32_t GPBCodedInputStreamReadUInt32(GPBCodedInputStreamState *state); |
| 58 | int64_t GPBCodedInputStreamReadInt64(GPBCodedInputStreamState *state); |
| 59 | int32_t GPBCodedInputStreamReadInt32(GPBCodedInputStreamState *state); |
| 60 | uint64_t GPBCodedInputStreamReadFixed64(GPBCodedInputStreamState *state); |
| 61 | uint32_t GPBCodedInputStreamReadFixed32(GPBCodedInputStreamState *state); |
| 62 | int32_t GPBCodedInputStreamReadEnum(GPBCodedInputStreamState *state); |
| 63 | int32_t GPBCodedInputStreamReadSFixed32(GPBCodedInputStreamState *state); |
| 64 | int64_t GPBCodedInputStreamReadSFixed64(GPBCodedInputStreamState *state); |
| 65 | int32_t GPBCodedInputStreamReadSInt32(GPBCodedInputStreamState *state); |
| 66 | int64_t GPBCodedInputStreamReadSInt64(GPBCodedInputStreamState *state); |
| 67 | BOOL GPBCodedInputStreamReadBool(GPBCodedInputStreamState *state); |
| 68 | NSString *GPBCodedInputStreamReadRetainedString(GPBCodedInputStreamState *state) |
| 69 | __attribute((ns_returns_retained)); |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 70 | NSData *GPBCodedInputStreamReadRetainedBytes(GPBCodedInputStreamState *state) |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 71 | __attribute((ns_returns_retained)); |
Thomas Van Lenten | 5d0b217 | 2022-09-19 17:20:35 -0400 | [diff] [blame] | 72 | NSData *GPBCodedInputStreamReadRetainedBytesNoCopy(GPBCodedInputStreamState *state) |
| 73 | __attribute((ns_returns_retained)); |
Thomas Van Lenten | d44c0d5 | 2024-07-22 13:29:17 -0700 | [diff] [blame] | 74 | NSData *GPBCodedInputStreamReadRetainedBytesToEndGroupNoCopy(GPBCodedInputStreamState *state, |
| 75 | int32_t fieldNumber) |
| 76 | __attribute((ns_returns_retained)); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 77 | |
Thomas Van Lenten | 5d0b217 | 2022-09-19 17:20:35 -0400 | [diff] [blame] | 78 | size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state, size_t byteLimit); |
| 79 | void GPBCodedInputStreamPopLimit(GPBCodedInputStreamState *state, size_t oldLimit); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 80 | size_t GPBCodedInputStreamBytesUntilLimit(GPBCodedInputStreamState *state); |
| 81 | BOOL GPBCodedInputStreamIsAtEnd(GPBCodedInputStreamState *state); |
Thomas Van Lenten | 5d0b217 | 2022-09-19 17:20:35 -0400 | [diff] [blame] | 82 | void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state, int32_t value); |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 83 | |
| 84 | CF_EXTERN_C_END |