OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
(...skipping 10 matching lines...) Expand all Loading... |
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | 30 |
31 #import "GPBCodedOutputStream.h" | 31 #import "GPBCodedOutputStream_PackagePrivate.h" |
32 | 32 |
33 #import <mach/vm_param.h> | 33 #import <mach/vm_param.h> |
34 | 34 |
35 #import "GPBArray.h" | 35 #import "GPBArray.h" |
36 #import "GPBUnknownFieldSet_PackagePrivate.h" | 36 #import "GPBUnknownFieldSet_PackagePrivate.h" |
37 #import "GPBUtilities_PackagePrivate.h" | 37 #import "GPBUtilities_PackagePrivate.h" |
38 | 38 |
39 // Structure for containing state of a GPBCodedInputStream. Brought out into | 39 // Structure for containing state of a GPBCodedInputStream. Brought out into |
40 // a struct so that we can inline several common functions instead of dealing | 40 // a struct so that we can inline several common functions instead of dealing |
41 // with overhead of ObjC dispatch. | 41 // with overhead of ObjC dispatch. |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 171 |
172 - (instancetype)initWithOutputStream:(NSOutputStream *)output { | 172 - (instancetype)initWithOutputStream:(NSOutputStream *)output { |
173 NSMutableData *data = [NSMutableData dataWithLength:PAGE_SIZE]; | 173 NSMutableData *data = [NSMutableData dataWithLength:PAGE_SIZE]; |
174 return [self initWithOutputStream:output data:data]; | 174 return [self initWithOutputStream:output data:data]; |
175 } | 175 } |
176 | 176 |
177 - (instancetype)initWithData:(NSMutableData *)data { | 177 - (instancetype)initWithData:(NSMutableData *)data { |
178 return [self initWithOutputStream:nil data:data]; | 178 return [self initWithOutputStream:nil data:data]; |
179 } | 179 } |
180 | 180 |
181 - (instancetype)initWithOutputStream:(NSOutputStream *)output | |
182 bufferSize:(size_t)bufferSize { | |
183 NSMutableData *data = [NSMutableData dataWithLength:bufferSize]; | |
184 return [self initWithOutputStream:output data:data]; | |
185 } | |
186 | |
187 // This initializer isn't exposed, but it is the designated initializer. | 181 // This initializer isn't exposed, but it is the designated initializer. |
188 // Setting OutputStream and NSData is to control the buffering behavior/size | 182 // Setting OutputStream and NSData is to control the buffering behavior/size |
189 // of the work, but that is more obvious via the bufferSize: version. | 183 // of the work, but that is more obvious via the bufferSize: version. |
190 - (instancetype)initWithOutputStream:(NSOutputStream *)output | 184 - (instancetype)initWithOutputStream:(NSOutputStream *)output |
191 data:(NSMutableData *)data { | 185 data:(NSMutableData *)data { |
192 if ((self = [super init])) { | 186 if ((self = [super init])) { |
193 buffer_ = [data retain]; | 187 buffer_ = [data retain]; |
194 [output open]; | 188 [output open]; |
195 state_.bytes = [data mutableBytes]; | 189 state_.bytes = [data mutableBytes]; |
196 state_.size = [data length]; | 190 state_.size = [data length]; |
197 state_.output = [output retain]; | 191 state_.output = [output retain]; |
198 } | 192 } |
199 return self; | 193 return self; |
200 } | 194 } |
201 | 195 |
202 + (instancetype)streamWithOutputStream:(NSOutputStream *)output | 196 + (instancetype)streamWithOutputStream:(NSOutputStream *)output { |
203 bufferSize:(size_t)bufferSize { | 197 NSMutableData *data = [NSMutableData dataWithLength:PAGE_SIZE]; |
204 return [[[self alloc] initWithOutputStream:output | 198 return [[[self alloc] initWithOutputStream:output |
205 bufferSize:bufferSize] autorelease]; | 199 data:data] autorelease]; |
206 } | |
207 | |
208 + (instancetype)streamWithOutputStream:(NSOutputStream *)output { | |
209 return [[[self alloc] initWithOutputStream:output | |
210 bufferSize:PAGE_SIZE] autorelease]; | |
211 } | 200 } |
212 | 201 |
213 + (instancetype)streamWithData:(NSMutableData *)data { | 202 + (instancetype)streamWithData:(NSMutableData *)data { |
214 return [[[self alloc] initWithData:data] autorelease]; | 203 return [[[self alloc] initWithData:data] autorelease]; |
215 } | 204 } |
216 | 205 |
217 - (void)writeDoubleNoTag:(double)value { | 206 - (void)writeDoubleNoTag:(double)value { |
218 GPBWriteRawLittleEndian64(&state_, GPBConvertDoubleToInt64(value)); | 207 GPBWriteRawLittleEndian64(&state_, GPBConvertDoubleToInt64(value)); |
219 } | 208 } |
220 | 209 |
(...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1223 if ((value & (0xffffffffffffffffL << 14)) == 0) return 2; | 1212 if ((value & (0xffffffffffffffffL << 14)) == 0) return 2; |
1224 if ((value & (0xffffffffffffffffL << 21)) == 0) return 3; | 1213 if ((value & (0xffffffffffffffffL << 21)) == 0) return 3; |
1225 if ((value & (0xffffffffffffffffL << 28)) == 0) return 4; | 1214 if ((value & (0xffffffffffffffffL << 28)) == 0) return 4; |
1226 if ((value & (0xffffffffffffffffL << 35)) == 0) return 5; | 1215 if ((value & (0xffffffffffffffffL << 35)) == 0) return 5; |
1227 if ((value & (0xffffffffffffffffL << 42)) == 0) return 6; | 1216 if ((value & (0xffffffffffffffffL << 42)) == 0) return 6; |
1228 if ((value & (0xffffffffffffffffL << 49)) == 0) return 7; | 1217 if ((value & (0xffffffffffffffffL << 49)) == 0) return 7; |
1229 if ((value & (0xffffffffffffffffL << 56)) == 0) return 8; | 1218 if ((value & (0xffffffffffffffffL << 56)) == 0) return 8; |
1230 if ((value & (0xffffffffffffffffL << 63)) == 0) return 9; | 1219 if ((value & (0xffffffffffffffffL << 63)) == 0) return 9; |
1231 return 10; | 1220 return 10; |
1232 } | 1221 } |
OLD | NEW |