blob: 73deb149753345ec66d4a76c0118a181c316623b [file] [log] [blame]
Thomas Van Lenten30650d82015-05-01 08:57:16 -04001// Protocol Buffers - Google's data interchange format
2// Copyright 2008 Google Inc. All rights reserved.
Thomas Van Lenten30650d82015-05-01 08:57:16 -04003//
Joshua Haberman44bd65b2023-09-08 17:43:14 -07004// 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 Lenten30650d82015-05-01 08:57:16 -04007
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 Lenten231b9682024-09-05 08:21:23 -070014#import "GPBDescriptor.h"
Thomas Van Lenten30650d82015-05-01 08:57:16 -040015
Thomas Van Lenten30650d82015-05-01 08:57:16 -040016typedef 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 Lentenf191ab02022-09-15 14:40:15 -040040 extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry;
Thomas Van Lenten30650d82015-05-01 08:57:16 -040041
Thomas Van Lenten30650d82015-05-01 08:57:16 -040042// Reads a map entry.
43- (void)readMapEntry:(id)mapDictionary
Thomas Van Lentenf191ab02022-09-15 14:40:15 -040044 extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry
Thomas Van Lenten30650d82015-05-01 08:57:16 -040045 field:(GPBFieldDescriptor *)field
46 parentMessage:(GPBMessage *)parentMessage;
47@end
48
49CF_EXTERN_C_BEGIN
50
Thomas Van Lenten6ebdc7a2024-07-22 11:08:16 -070051void GPBRaiseStreamError(NSInteger code, NSString *reason);
Thomas Van Lenten30650d82015-05-01 08:57:16 -040052int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state);
53
54double GPBCodedInputStreamReadDouble(GPBCodedInputStreamState *state);
55float GPBCodedInputStreamReadFloat(GPBCodedInputStreamState *state);
56uint64_t GPBCodedInputStreamReadUInt64(GPBCodedInputStreamState *state);
57uint32_t GPBCodedInputStreamReadUInt32(GPBCodedInputStreamState *state);
58int64_t GPBCodedInputStreamReadInt64(GPBCodedInputStreamState *state);
59int32_t GPBCodedInputStreamReadInt32(GPBCodedInputStreamState *state);
60uint64_t GPBCodedInputStreamReadFixed64(GPBCodedInputStreamState *state);
61uint32_t GPBCodedInputStreamReadFixed32(GPBCodedInputStreamState *state);
62int32_t GPBCodedInputStreamReadEnum(GPBCodedInputStreamState *state);
63int32_t GPBCodedInputStreamReadSFixed32(GPBCodedInputStreamState *state);
64int64_t GPBCodedInputStreamReadSFixed64(GPBCodedInputStreamState *state);
65int32_t GPBCodedInputStreamReadSInt32(GPBCodedInputStreamState *state);
66int64_t GPBCodedInputStreamReadSInt64(GPBCodedInputStreamState *state);
67BOOL GPBCodedInputStreamReadBool(GPBCodedInputStreamState *state);
68NSString *GPBCodedInputStreamReadRetainedString(GPBCodedInputStreamState *state)
69 __attribute((ns_returns_retained));
Thomas Van Lentend846b0b2015-06-08 16:24:57 -040070NSData *GPBCodedInputStreamReadRetainedBytes(GPBCodedInputStreamState *state)
Thomas Van Lenten30650d82015-05-01 08:57:16 -040071 __attribute((ns_returns_retained));
Thomas Van Lenten5d0b2172022-09-19 17:20:35 -040072NSData *GPBCodedInputStreamReadRetainedBytesNoCopy(GPBCodedInputStreamState *state)
73 __attribute((ns_returns_retained));
Thomas Van Lentend44c0d52024-07-22 13:29:17 -070074NSData *GPBCodedInputStreamReadRetainedBytesToEndGroupNoCopy(GPBCodedInputStreamState *state,
75 int32_t fieldNumber)
76 __attribute((ns_returns_retained));
Thomas Van Lenten30650d82015-05-01 08:57:16 -040077
Thomas Van Lenten5d0b2172022-09-19 17:20:35 -040078size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state, size_t byteLimit);
79void GPBCodedInputStreamPopLimit(GPBCodedInputStreamState *state, size_t oldLimit);
Thomas Van Lenten30650d82015-05-01 08:57:16 -040080size_t GPBCodedInputStreamBytesUntilLimit(GPBCodedInputStreamState *state);
81BOOL GPBCodedInputStreamIsAtEnd(GPBCodedInputStreamState *state);
Thomas Van Lenten5d0b2172022-09-19 17:20:35 -040082void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state, int32_t value);
Thomas Van Lenten30650d82015-05-01 08:57:16 -040083
84CF_EXTERN_C_END