Skip to content

Commit d58b92a

Browse files
sergiocampamathomasvl
authored andcommitted
Adds pushLimit: and popLimit: into GPBCodedInputStream (protocolbuffers#2297)
Adds pushLimit: and popLimit: into GPBCodedInputStream
1 parent 795976e commit d58b92a

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

objectivec/GPBCodedInputStream.h

+21
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,27 @@ CF_EXTERN_C_END
217217
**/
218218
- (size_t)position;
219219

220+
/**
221+
* Moves the limit to the given byte offset starting at the current location.
222+
*
223+
* @exception GPBCodedInputStreamException If the requested bytes exceeed the
224+
* current limit.
225+
*
226+
* @param byteLimit The number of bytes to move the limit, offset to the current
227+
* location.
228+
*
229+
* @return The limit offset before moving the new limit.
230+
*/
231+
- (size_t)pushLimit:(size_t)byteLimit;
232+
233+
/**
234+
* Moves the limit back to the offset as it was before calling pushLimit:.
235+
*
236+
* @param oldLimit The number of bytes to move the current limit. Usually this
237+
* is the value returned by the pushLimit: method.
238+
*/
239+
- (void)popLimit:(size_t)oldLimit;
240+
220241
/**
221242
* Verifies that the last call to -readTag returned the given tag value. This
222243
* is used to verify that a nested group ended with the correct end tag.

objectivec/GPBCodedInputStream.m

+8
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,14 @@ - (size_t)position {
400400
return state_.bufferPos;
401401
}
402402

403+
- (size_t)pushLimit:(size_t)byteLimit {
404+
return GPBCodedInputStreamPushLimit(&state_, byteLimit);
405+
}
406+
407+
- (void)popLimit:(size_t)oldLimit {
408+
GPBCodedInputStreamPopLimit(&state_, oldLimit);
409+
}
410+
403411
- (double)readDouble {
404412
return GPBCodedInputStreamReadDouble(&state_);
405413
}

0 commit comments

Comments
 (0)