1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 //
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
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
14 #import "GPBDescriptor.h"
15 #import "GPBUnknownFieldSet.h"
16
17 @class GPBUnknownFieldSet;
18
19 typedef struct GPBCodedInputStreamState {
20 const uint8_t *bytes;
21 size_t bufferSize;
22 size_t bufferPos;
23
24 // For parsing subsections of an input stream you can put a hard limit on
25 // how much should be read. Normally the limit is the end of the stream,
26 // but you can adjust it to anywhere, and if you hit it you will be at the
27 // end of the stream, until you adjust the limit.
28 size_t currentLimit;
29 int32_t lastTag;
30 NSUInteger recursionDepth;
31 } GPBCodedInputStreamState;
32
GPBCodedInputStream()33 @interface GPBCodedInputStream () {
34 @package
35 struct GPBCodedInputStreamState state_;
36 NSData *buffer_;
37 }
38
39 // Group support is deprecated, so we hide this interface from users, but
40 // support for older data.
41 - (void)readGroup:(int32_t)fieldNumber
42 message:(GPBMessage *)message
43 extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry;
44
45 // Reads a group field value from the stream and merges it into the given
46 // UnknownFieldSet.
47 #pragma clang diagnostic push
48 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
49 - (void)readUnknownGroup:(int32_t)fieldNumber message:(GPBUnknownFieldSet *)message;
50 #pragma clang diagnostic pop
51
52 // Reads a map entry.
53 - (void)readMapEntry:(id)mapDictionary
54 extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry
55 field:(GPBFieldDescriptor *)field
56 parentMessage:(GPBMessage *)parentMessage;
57 @end
58
59 CF_EXTERN_C_BEGIN
60
61 void GPBRaiseStreamError(NSInteger code, NSString *reason);
62 int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state);
63
64 double GPBCodedInputStreamReadDouble(GPBCodedInputStreamState *state);
65 float GPBCodedInputStreamReadFloat(GPBCodedInputStreamState *state);
66 uint64_t GPBCodedInputStreamReadUInt64(GPBCodedInputStreamState *state);
67 uint32_t GPBCodedInputStreamReadUInt32(GPBCodedInputStreamState *state);
68 int64_t GPBCodedInputStreamReadInt64(GPBCodedInputStreamState *state);
69 int32_t GPBCodedInputStreamReadInt32(GPBCodedInputStreamState *state);
70 uint64_t GPBCodedInputStreamReadFixed64(GPBCodedInputStreamState *state);
71 uint32_t GPBCodedInputStreamReadFixed32(GPBCodedInputStreamState *state);
72 int32_t GPBCodedInputStreamReadEnum(GPBCodedInputStreamState *state);
73 int32_t GPBCodedInputStreamReadSFixed32(GPBCodedInputStreamState *state);
74 int64_t GPBCodedInputStreamReadSFixed64(GPBCodedInputStreamState *state);
75 int32_t GPBCodedInputStreamReadSInt32(GPBCodedInputStreamState *state);
76 int64_t GPBCodedInputStreamReadSInt64(GPBCodedInputStreamState *state);
77 BOOL GPBCodedInputStreamReadBool(GPBCodedInputStreamState *state);
78 NSString *GPBCodedInputStreamReadRetainedString(GPBCodedInputStreamState *state)
79 __attribute((ns_returns_retained));
80 NSData *GPBCodedInputStreamReadRetainedBytes(GPBCodedInputStreamState *state)
81 __attribute((ns_returns_retained));
82 NSData *GPBCodedInputStreamReadRetainedBytesNoCopy(GPBCodedInputStreamState *state)
83 __attribute((ns_returns_retained));
84 NSData *GPBCodedInputStreamReadRetainedBytesToEndGroupNoCopy(GPBCodedInputStreamState *state,
85 int32_t fieldNumber)
86 __attribute((ns_returns_retained));
87
88 size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state, size_t byteLimit);
89 void GPBCodedInputStreamPopLimit(GPBCodedInputStreamState *state, size_t oldLimit);
90 size_t GPBCodedInputStreamBytesUntilLimit(GPBCodedInputStreamState *state);
91 BOOL GPBCodedInputStreamIsAtEnd(GPBCodedInputStreamState *state);
92 void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state, int32_t value);
93
94 CF_EXTERN_C_END
95