瀏覽代碼

Add -position and -isAtEnd for use when manually parsing input streams.

Thomas Van Lenten 9 年之前
父節點
當前提交
331cee5022
共有 2 個文件被更改,包括 17 次插入0 次删除
  1. 9 0
      objectivec/GPBCodedInputStream.h
  2. 8 0
      objectivec/GPBCodedInputStream.m

+ 9 - 0
objectivec/GPBCodedInputStream.h

@@ -109,6 +109,15 @@ NS_ASSUME_NONNULL_BEGIN
 /// or until an endgroup tag, whichever comes first.
 /// or until an endgroup tag, whichever comes first.
 - (void)skipMessage;
 - (void)skipMessage;
 
 
+/// Check to see if the logical end of the stream has been reached.
+///
+/// This can return NO when there is no more data, but the current parsing
+/// expected more data.
+- (BOOL)isAtEnd;
+
+/// The offset into the stream.
+- (size_t)position;
+
 /// Verifies that the last call to @c -readTag returned the given tag value.
 /// Verifies that the last call to @c -readTag returned the given tag value.
 /// This is used to verify that a nested group ended with the correct end tag.
 /// This is used to verify that a nested group ended with the correct end tag.
 /// Throws @c NSParseErrorException if value does not match the last tag.
 /// Throws @c NSParseErrorException if value does not match the last tag.

+ 8 - 0
objectivec/GPBCodedInputStream.m

@@ -359,6 +359,14 @@ void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state,
   }
   }
 }
 }
 
 
+- (BOOL)isAtEnd {
+  return GPBCodedInputStreamIsAtEnd(&state_);
+}
+
+- (size_t)position {
+  return state_.bufferPos;
+}
+
 - (double)readDouble {
 - (double)readDouble {
   return GPBCodedInputStreamReadDouble(&state_);
   return GPBCodedInputStreamReadDouble(&state_);
 }
 }