Skip to content

Commit

Permalink
ObjC: Document the exceptions on some of the writing apis.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasvl committed Jun 19, 2017
1 parent 72e293a commit 5fd71ce
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
9 changes: 9 additions & 0 deletions objectivec/GPBCodedOutputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,21 @@

NS_ASSUME_NONNULL_BEGIN

/**
* @c GPBCodedOutputStream exception names.
**/
extern NSString *const GPBCodedOutputStreamException_OutOfSpace;
extern NSString *const GPBCodedOutputStreamException_WriteFailed;

/**
* Writes out protocol message fields.
*
* The common uses of protocol buffers shouldn't need to use this class.
* GPBMessage's provide a -data method that will serialize the message for you.
*
* @note Any -write* api can raise the GPBCodedOutputStreamException_*
* exceptions.
*
* @note Subclassing of GPBCodedOutputStream is NOT supported.
**/
@interface GPBCodedOutputStream : NSObject
Expand Down
9 changes: 7 additions & 2 deletions objectivec/GPBCodedOutputStream.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
#import "GPBUnknownFieldSet_PackagePrivate.h"
#import "GPBUtilities_PackagePrivate.h"

// These values are the existing values so as not to break any code that might
// have already been inspecting them when they weren't documented/exposed.
NSString *const GPBCodedOutputStreamException_OutOfSpace = @"OutOfSpace";
NSString *const GPBCodedOutputStreamException_WriteFailed = @"WriteFailed";

// Structure for containing state of a GPBCodedInputStream. Brought out into
// a struct so that we can inline several common functions instead of dealing
// with overhead of ObjC dispatch.
Expand All @@ -59,13 +64,13 @@ @implementation GPBCodedOutputStream {
static void GPBRefreshBuffer(GPBOutputBufferState *state) {
if (state->output == nil) {
// We're writing to a single buffer.
[NSException raise:@"OutOfSpace" format:@""];
[NSException raise:GPBCodedOutputStreamException_OutOfSpace format:@""];
}
if (state->position != 0) {
NSInteger written =
[state->output write:state->bytes maxLength:state->position];
if (written != (NSInteger)state->position) {
[NSException raise:@"WriteFailed" format:@""];
[NSException raise:GPBCodedOutputStreamException_WriteFailed format:@""];
}
state->position = 0;
}
Expand Down
9 changes: 9 additions & 0 deletions objectivec/GPBMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,18 @@ CF_EXTERN_C_END
* Writes out the message to the given coded output stream.
*
* @param output The coded output stream into which to write the message.
*
* @note This can raise the GPBCodedOutputStreamException_* exceptions.
*
**/
- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)output;

/**
* Writes out the message to the given output stream.
*
* @param output The output stream into which to write the message.
*
* @note This can raise the GPBCodedOutputStreamException_* exceptions.
**/
- (void)writeToOutputStream:(NSOutputStream *)output;

Expand All @@ -307,6 +312,8 @@ CF_EXTERN_C_END
* the given output stream.
*
* @param output The coded output stream into which to write the message.
*
* @note This can raise the GPBCodedOutputStreamException_* exceptions.
**/
- (void)writeDelimitedToCodedOutputStream:(GPBCodedOutputStream *)output;

Expand All @@ -315,6 +322,8 @@ CF_EXTERN_C_END
* the given output stream.
*
* @param output The output stream into which to write the message.
*
* @note This can raise the GPBCodedOutputStreamException_* exceptions.
**/
- (void)writeDelimitedToOutputStream:(NSOutputStream *)output;

Expand Down

0 comments on commit 5fd71ce

Please sign in to comment.