Skip to content

Commit 5fd71ce

Browse files
committed
ObjC: Document the exceptions on some of the writing apis.
1 parent 72e293a commit 5fd71ce

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

objectivec/GPBCodedOutputStream.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,21 @@
4646

4747
NS_ASSUME_NONNULL_BEGIN
4848

49+
/**
50+
* @c GPBCodedOutputStream exception names.
51+
**/
52+
extern NSString *const GPBCodedOutputStreamException_OutOfSpace;
53+
extern NSString *const GPBCodedOutputStreamException_WriteFailed;
54+
4955
/**
5056
* Writes out protocol message fields.
5157
*
5258
* The common uses of protocol buffers shouldn't need to use this class.
5359
* GPBMessage's provide a -data method that will serialize the message for you.
5460
*
61+
* @note Any -write* api can raise the GPBCodedOutputStreamException_*
62+
* exceptions.
63+
*
5564
* @note Subclassing of GPBCodedOutputStream is NOT supported.
5665
**/
5766
@interface GPBCodedOutputStream : NSObject

objectivec/GPBCodedOutputStream.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
#import "GPBUnknownFieldSet_PackagePrivate.h"
3737
#import "GPBUtilities_PackagePrivate.h"
3838

39+
// These values are the existing values so as not to break any code that might
40+
// have already been inspecting them when they weren't documented/exposed.
41+
NSString *const GPBCodedOutputStreamException_OutOfSpace = @"OutOfSpace";
42+
NSString *const GPBCodedOutputStreamException_WriteFailed = @"WriteFailed";
43+
3944
// Structure for containing state of a GPBCodedInputStream. Brought out into
4045
// a struct so that we can inline several common functions instead of dealing
4146
// with overhead of ObjC dispatch.
@@ -59,13 +64,13 @@ @implementation GPBCodedOutputStream {
5964
static void GPBRefreshBuffer(GPBOutputBufferState *state) {
6065
if (state->output == nil) {
6166
// We're writing to a single buffer.
62-
[NSException raise:@"OutOfSpace" format:@""];
67+
[NSException raise:GPBCodedOutputStreamException_OutOfSpace format:@""];
6368
}
6469
if (state->position != 0) {
6570
NSInteger written =
6671
[state->output write:state->bytes maxLength:state->position];
6772
if (written != (NSInteger)state->position) {
68-
[NSException raise:@"WriteFailed" format:@""];
73+
[NSException raise:GPBCodedOutputStreamException_WriteFailed format:@""];
6974
}
7075
state->position = 0;
7176
}

objectivec/GPBMessage.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,18 @@ CF_EXTERN_C_END
292292
* Writes out the message to the given coded output stream.
293293
*
294294
* @param output The coded output stream into which to write the message.
295+
*
296+
* @note This can raise the GPBCodedOutputStreamException_* exceptions.
297+
*
295298
**/
296299
- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)output;
297300

298301
/**
299302
* Writes out the message to the given output stream.
300303
*
301304
* @param output The output stream into which to write the message.
305+
*
306+
* @note This can raise the GPBCodedOutputStreamException_* exceptions.
302307
**/
303308
- (void)writeToOutputStream:(NSOutputStream *)output;
304309

@@ -307,6 +312,8 @@ CF_EXTERN_C_END
307312
* the given output stream.
308313
*
309314
* @param output The coded output stream into which to write the message.
315+
*
316+
* @note This can raise the GPBCodedOutputStreamException_* exceptions.
310317
**/
311318
- (void)writeDelimitedToCodedOutputStream:(GPBCodedOutputStream *)output;
312319

@@ -315,6 +322,8 @@ CF_EXTERN_C_END
315322
* the given output stream.
316323
*
317324
* @param output The output stream into which to write the message.
325+
*
326+
* @note This can raise the GPBCodedOutputStreamException_* exceptions.
318327
**/
319328
- (void)writeDelimitedToOutputStream:(NSOutputStream *)output;
320329

0 commit comments

Comments
 (0)