blob: 90bd0c92cece8a2c0b955b3887a769e433d8aad8 [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.
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// This header is private to the ProtobolBuffers library and must NOT be
32// included by any sources outside this library. The contents of this file are
33// subject to change at any time without notice.
34
35#import "GPBCodedInputStream.h"
36
37#import <libkern/OSAtomic.h>
38
39@class GPBUnknownFieldSet;
40@class GPBFieldDescriptor;
41
Thomas Van Lenten30650d82015-05-01 08:57:16 -040042typedef struct GPBCodedInputStreamState {
43 const uint8_t *bytes;
44 size_t bufferSize;
45 size_t bufferPos;
46
47 // For parsing subsections of an input stream you can put a hard limit on
48 // how much should be read. Normally the limit is the end of the stream,
49 // but you can adjust it to anywhere, and if you hit it you will be at the
50 // end of the stream, until you adjust the limit.
51 size_t currentLimit;
52 int32_t lastTag;
53 NSUInteger recursionDepth;
54} GPBCodedInputStreamState;
55
56@interface GPBCodedInputStream () {
57 @package
58 struct GPBCodedInputStreamState state_;
59 NSData *buffer_;
60}
61
62// Group support is deprecated, so we hide this interface from users, but
63// support for older data.
64- (void)readGroup:(int32_t)fieldNumber
65 message:(GPBMessage *)message
66 extensionRegistry:(GPBExtensionRegistry *)extensionRegistry;
67
68// Reads a group field value from the stream and merges it into the given
69// UnknownFieldSet.
70- (void)readUnknownGroup:(int32_t)fieldNumber
71 message:(GPBUnknownFieldSet *)message;
72
73// Reads a map entry.
74- (void)readMapEntry:(id)mapDictionary
75 extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
76 field:(GPBFieldDescriptor *)field
77 parentMessage:(GPBMessage *)parentMessage;
78@end
79
80CF_EXTERN_C_BEGIN
81
Thomas Van Lenten30650d82015-05-01 08:57:16 -040082int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state);
83
84double GPBCodedInputStreamReadDouble(GPBCodedInputStreamState *state);
85float GPBCodedInputStreamReadFloat(GPBCodedInputStreamState *state);
86uint64_t GPBCodedInputStreamReadUInt64(GPBCodedInputStreamState *state);
87uint32_t GPBCodedInputStreamReadUInt32(GPBCodedInputStreamState *state);
88int64_t GPBCodedInputStreamReadInt64(GPBCodedInputStreamState *state);
89int32_t GPBCodedInputStreamReadInt32(GPBCodedInputStreamState *state);
90uint64_t GPBCodedInputStreamReadFixed64(GPBCodedInputStreamState *state);
91uint32_t GPBCodedInputStreamReadFixed32(GPBCodedInputStreamState *state);
92int32_t GPBCodedInputStreamReadEnum(GPBCodedInputStreamState *state);
93int32_t GPBCodedInputStreamReadSFixed32(GPBCodedInputStreamState *state);
94int64_t GPBCodedInputStreamReadSFixed64(GPBCodedInputStreamState *state);
95int32_t GPBCodedInputStreamReadSInt32(GPBCodedInputStreamState *state);
96int64_t GPBCodedInputStreamReadSInt64(GPBCodedInputStreamState *state);
97BOOL GPBCodedInputStreamReadBool(GPBCodedInputStreamState *state);
98NSString *GPBCodedInputStreamReadRetainedString(GPBCodedInputStreamState *state)
99 __attribute((ns_returns_retained));
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400100NSData *GPBCodedInputStreamReadRetainedBytes(GPBCodedInputStreamState *state)
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400101 __attribute((ns_returns_retained));
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400102NSData *GPBCodedInputStreamReadRetainedBytesNoCopy(
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400103 GPBCodedInputStreamState *state) __attribute((ns_returns_retained));
104
105size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state,
106 size_t byteLimit);
107void GPBCodedInputStreamPopLimit(GPBCodedInputStreamState *state,
108 size_t oldLimit);
109size_t GPBCodedInputStreamBytesUntilLimit(GPBCodedInputStreamState *state);
110BOOL GPBCodedInputStreamIsAtEnd(GPBCodedInputStreamState *state);
111void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state,
112 int32_t value);
113
114CF_EXTERN_C_END