You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
5.1 KiB

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