1ffe3c632Sopenharmony_ci// Protocol Buffers - Google's data interchange format 2ffe3c632Sopenharmony_ci// Copyright 2008 Google Inc. All rights reserved. 3ffe3c632Sopenharmony_ci// https://developers.google.com/protocol-buffers/ 4ffe3c632Sopenharmony_ci// 5ffe3c632Sopenharmony_ci// Redistribution and use in source and binary forms, with or without 6ffe3c632Sopenharmony_ci// modification, are permitted provided that the following conditions are 7ffe3c632Sopenharmony_ci// met: 8ffe3c632Sopenharmony_ci// 9ffe3c632Sopenharmony_ci// * Redistributions of source code must retain the above copyright 10ffe3c632Sopenharmony_ci// notice, this list of conditions and the following disclaimer. 11ffe3c632Sopenharmony_ci// * Redistributions in binary form must reproduce the above 12ffe3c632Sopenharmony_ci// copyright notice, this list of conditions and the following disclaimer 13ffe3c632Sopenharmony_ci// in the documentation and/or other materials provided with the 14ffe3c632Sopenharmony_ci// distribution. 15ffe3c632Sopenharmony_ci// * Neither the name of Google Inc. nor the names of its 16ffe3c632Sopenharmony_ci// contributors may be used to endorse or promote products derived from 17ffe3c632Sopenharmony_ci// this software without specific prior written permission. 18ffe3c632Sopenharmony_ci// 19ffe3c632Sopenharmony_ci// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20ffe3c632Sopenharmony_ci// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21ffe3c632Sopenharmony_ci// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22ffe3c632Sopenharmony_ci// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23ffe3c632Sopenharmony_ci// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24ffe3c632Sopenharmony_ci// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25ffe3c632Sopenharmony_ci// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26ffe3c632Sopenharmony_ci// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27ffe3c632Sopenharmony_ci// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28ffe3c632Sopenharmony_ci// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29ffe3c632Sopenharmony_ci// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30ffe3c632Sopenharmony_ci 31ffe3c632Sopenharmony_ci#import "GPBCodedOutputStream_PackagePrivate.h" 32ffe3c632Sopenharmony_ci 33ffe3c632Sopenharmony_ci#import <mach/vm_param.h> 34ffe3c632Sopenharmony_ci 35ffe3c632Sopenharmony_ci#import "GPBArray.h" 36ffe3c632Sopenharmony_ci#import "GPBUnknownFieldSet_PackagePrivate.h" 37ffe3c632Sopenharmony_ci#import "GPBUtilities_PackagePrivate.h" 38ffe3c632Sopenharmony_ci 39ffe3c632Sopenharmony_ci// These values are the existing values so as not to break any code that might 40ffe3c632Sopenharmony_ci// have already been inspecting them when they weren't documented/exposed. 41ffe3c632Sopenharmony_ciNSString *const GPBCodedOutputStreamException_OutOfSpace = @"OutOfSpace"; 42ffe3c632Sopenharmony_ciNSString *const GPBCodedOutputStreamException_WriteFailed = @"WriteFailed"; 43ffe3c632Sopenharmony_ci 44ffe3c632Sopenharmony_ci// Structure for containing state of a GPBCodedInputStream. Brought out into 45ffe3c632Sopenharmony_ci// a struct so that we can inline several common functions instead of dealing 46ffe3c632Sopenharmony_ci// with overhead of ObjC dispatch. 47ffe3c632Sopenharmony_citypedef struct GPBOutputBufferState { 48ffe3c632Sopenharmony_ci uint8_t *bytes; 49ffe3c632Sopenharmony_ci size_t size; 50ffe3c632Sopenharmony_ci size_t position; 51ffe3c632Sopenharmony_ci NSOutputStream *output; 52ffe3c632Sopenharmony_ci} GPBOutputBufferState; 53ffe3c632Sopenharmony_ci 54ffe3c632Sopenharmony_ci@implementation GPBCodedOutputStream { 55ffe3c632Sopenharmony_ci GPBOutputBufferState state_; 56ffe3c632Sopenharmony_ci NSMutableData *buffer_; 57ffe3c632Sopenharmony_ci} 58ffe3c632Sopenharmony_ci 59ffe3c632Sopenharmony_cistatic const int32_t LITTLE_ENDIAN_32_SIZE = sizeof(uint32_t); 60ffe3c632Sopenharmony_cistatic const int32_t LITTLE_ENDIAN_64_SIZE = sizeof(uint64_t); 61ffe3c632Sopenharmony_ci 62ffe3c632Sopenharmony_ci// Internal helper that writes the current buffer to the output. The 63ffe3c632Sopenharmony_ci// buffer position is reset to its initial value when this returns. 64ffe3c632Sopenharmony_cistatic void GPBRefreshBuffer(GPBOutputBufferState *state) { 65ffe3c632Sopenharmony_ci if (state->output == nil) { 66ffe3c632Sopenharmony_ci // We're writing to a single buffer. 67ffe3c632Sopenharmony_ci [NSException raise:GPBCodedOutputStreamException_OutOfSpace format:@""]; 68ffe3c632Sopenharmony_ci } 69ffe3c632Sopenharmony_ci if (state->position != 0) { 70ffe3c632Sopenharmony_ci NSInteger written = 71ffe3c632Sopenharmony_ci [state->output write:state->bytes maxLength:state->position]; 72ffe3c632Sopenharmony_ci if (written != (NSInteger)state->position) { 73ffe3c632Sopenharmony_ci [NSException raise:GPBCodedOutputStreamException_WriteFailed format:@""]; 74ffe3c632Sopenharmony_ci } 75ffe3c632Sopenharmony_ci state->position = 0; 76ffe3c632Sopenharmony_ci } 77ffe3c632Sopenharmony_ci} 78ffe3c632Sopenharmony_ci 79ffe3c632Sopenharmony_cistatic void GPBWriteRawByte(GPBOutputBufferState *state, uint8_t value) { 80ffe3c632Sopenharmony_ci if (state->position == state->size) { 81ffe3c632Sopenharmony_ci GPBRefreshBuffer(state); 82ffe3c632Sopenharmony_ci } 83ffe3c632Sopenharmony_ci state->bytes[state->position++] = value; 84ffe3c632Sopenharmony_ci} 85ffe3c632Sopenharmony_ci 86ffe3c632Sopenharmony_cistatic void GPBWriteRawVarint32(GPBOutputBufferState *state, int32_t value) { 87ffe3c632Sopenharmony_ci while (YES) { 88ffe3c632Sopenharmony_ci if ((value & ~0x7F) == 0) { 89ffe3c632Sopenharmony_ci uint8_t val = (uint8_t)value; 90ffe3c632Sopenharmony_ci GPBWriteRawByte(state, val); 91ffe3c632Sopenharmony_ci return; 92ffe3c632Sopenharmony_ci } else { 93ffe3c632Sopenharmony_ci GPBWriteRawByte(state, (value & 0x7F) | 0x80); 94ffe3c632Sopenharmony_ci value = GPBLogicalRightShift32(value, 7); 95ffe3c632Sopenharmony_ci } 96ffe3c632Sopenharmony_ci } 97ffe3c632Sopenharmony_ci} 98ffe3c632Sopenharmony_ci 99ffe3c632Sopenharmony_cistatic void GPBWriteRawVarint64(GPBOutputBufferState *state, int64_t value) { 100ffe3c632Sopenharmony_ci while (YES) { 101ffe3c632Sopenharmony_ci if ((value & ~0x7FL) == 0) { 102ffe3c632Sopenharmony_ci uint8_t val = (uint8_t)value; 103ffe3c632Sopenharmony_ci GPBWriteRawByte(state, val); 104ffe3c632Sopenharmony_ci return; 105ffe3c632Sopenharmony_ci } else { 106ffe3c632Sopenharmony_ci GPBWriteRawByte(state, ((int32_t)value & 0x7F) | 0x80); 107ffe3c632Sopenharmony_ci value = GPBLogicalRightShift64(value, 7); 108ffe3c632Sopenharmony_ci } 109ffe3c632Sopenharmony_ci } 110ffe3c632Sopenharmony_ci} 111ffe3c632Sopenharmony_ci 112ffe3c632Sopenharmony_cistatic void GPBWriteInt32NoTag(GPBOutputBufferState *state, int32_t value) { 113ffe3c632Sopenharmony_ci if (value >= 0) { 114ffe3c632Sopenharmony_ci GPBWriteRawVarint32(state, value); 115ffe3c632Sopenharmony_ci } else { 116ffe3c632Sopenharmony_ci // Must sign-extend 117ffe3c632Sopenharmony_ci GPBWriteRawVarint64(state, value); 118ffe3c632Sopenharmony_ci } 119ffe3c632Sopenharmony_ci} 120ffe3c632Sopenharmony_ci 121ffe3c632Sopenharmony_cistatic void GPBWriteUInt32(GPBOutputBufferState *state, int32_t fieldNumber, 122ffe3c632Sopenharmony_ci uint32_t value) { 123ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(state, fieldNumber, GPBWireFormatVarint); 124ffe3c632Sopenharmony_ci GPBWriteRawVarint32(state, value); 125ffe3c632Sopenharmony_ci} 126ffe3c632Sopenharmony_ci 127ffe3c632Sopenharmony_cistatic void GPBWriteTagWithFormat(GPBOutputBufferState *state, 128ffe3c632Sopenharmony_ci uint32_t fieldNumber, GPBWireFormat format) { 129ffe3c632Sopenharmony_ci GPBWriteRawVarint32(state, GPBWireFormatMakeTag(fieldNumber, format)); 130ffe3c632Sopenharmony_ci} 131ffe3c632Sopenharmony_ci 132ffe3c632Sopenharmony_cistatic void GPBWriteRawLittleEndian32(GPBOutputBufferState *state, 133ffe3c632Sopenharmony_ci int32_t value) { 134ffe3c632Sopenharmony_ci GPBWriteRawByte(state, (value)&0xFF); 135ffe3c632Sopenharmony_ci GPBWriteRawByte(state, (value >> 8) & 0xFF); 136ffe3c632Sopenharmony_ci GPBWriteRawByte(state, (value >> 16) & 0xFF); 137ffe3c632Sopenharmony_ci GPBWriteRawByte(state, (value >> 24) & 0xFF); 138ffe3c632Sopenharmony_ci} 139ffe3c632Sopenharmony_ci 140ffe3c632Sopenharmony_cistatic void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, 141ffe3c632Sopenharmony_ci int64_t value) { 142ffe3c632Sopenharmony_ci GPBWriteRawByte(state, (int32_t)(value)&0xFF); 143ffe3c632Sopenharmony_ci GPBWriteRawByte(state, (int32_t)(value >> 8) & 0xFF); 144ffe3c632Sopenharmony_ci GPBWriteRawByte(state, (int32_t)(value >> 16) & 0xFF); 145ffe3c632Sopenharmony_ci GPBWriteRawByte(state, (int32_t)(value >> 24) & 0xFF); 146ffe3c632Sopenharmony_ci GPBWriteRawByte(state, (int32_t)(value >> 32) & 0xFF); 147ffe3c632Sopenharmony_ci GPBWriteRawByte(state, (int32_t)(value >> 40) & 0xFF); 148ffe3c632Sopenharmony_ci GPBWriteRawByte(state, (int32_t)(value >> 48) & 0xFF); 149ffe3c632Sopenharmony_ci GPBWriteRawByte(state, (int32_t)(value >> 56) & 0xFF); 150ffe3c632Sopenharmony_ci} 151ffe3c632Sopenharmony_ci 152ffe3c632Sopenharmony_ci- (void)dealloc { 153ffe3c632Sopenharmony_ci [self flush]; 154ffe3c632Sopenharmony_ci [state_.output close]; 155ffe3c632Sopenharmony_ci [state_.output release]; 156ffe3c632Sopenharmony_ci [buffer_ release]; 157ffe3c632Sopenharmony_ci 158ffe3c632Sopenharmony_ci [super dealloc]; 159ffe3c632Sopenharmony_ci} 160ffe3c632Sopenharmony_ci 161ffe3c632Sopenharmony_ci- (instancetype)initWithOutputStream:(NSOutputStream *)output { 162ffe3c632Sopenharmony_ci NSMutableData *data = [NSMutableData dataWithLength:PAGE_SIZE]; 163ffe3c632Sopenharmony_ci return [self initWithOutputStream:output data:data]; 164ffe3c632Sopenharmony_ci} 165ffe3c632Sopenharmony_ci 166ffe3c632Sopenharmony_ci- (instancetype)initWithData:(NSMutableData *)data { 167ffe3c632Sopenharmony_ci return [self initWithOutputStream:nil data:data]; 168ffe3c632Sopenharmony_ci} 169ffe3c632Sopenharmony_ci 170ffe3c632Sopenharmony_ci// This initializer isn't exposed, but it is the designated initializer. 171ffe3c632Sopenharmony_ci// Setting OutputStream and NSData is to control the buffering behavior/size 172ffe3c632Sopenharmony_ci// of the work, but that is more obvious via the bufferSize: version. 173ffe3c632Sopenharmony_ci- (instancetype)initWithOutputStream:(NSOutputStream *)output 174ffe3c632Sopenharmony_ci data:(NSMutableData *)data { 175ffe3c632Sopenharmony_ci if ((self = [super init])) { 176ffe3c632Sopenharmony_ci buffer_ = [data retain]; 177ffe3c632Sopenharmony_ci state_.bytes = [data mutableBytes]; 178ffe3c632Sopenharmony_ci state_.size = [data length]; 179ffe3c632Sopenharmony_ci state_.output = [output retain]; 180ffe3c632Sopenharmony_ci [state_.output open]; 181ffe3c632Sopenharmony_ci } 182ffe3c632Sopenharmony_ci return self; 183ffe3c632Sopenharmony_ci} 184ffe3c632Sopenharmony_ci 185ffe3c632Sopenharmony_ci+ (instancetype)streamWithOutputStream:(NSOutputStream *)output { 186ffe3c632Sopenharmony_ci NSMutableData *data = [NSMutableData dataWithLength:PAGE_SIZE]; 187ffe3c632Sopenharmony_ci return [[[self alloc] initWithOutputStream:output 188ffe3c632Sopenharmony_ci data:data] autorelease]; 189ffe3c632Sopenharmony_ci} 190ffe3c632Sopenharmony_ci 191ffe3c632Sopenharmony_ci+ (instancetype)streamWithData:(NSMutableData *)data { 192ffe3c632Sopenharmony_ci return [[[self alloc] initWithData:data] autorelease]; 193ffe3c632Sopenharmony_ci} 194ffe3c632Sopenharmony_ci 195ffe3c632Sopenharmony_ci// Direct access is use for speed, to avoid even internally declaring things 196ffe3c632Sopenharmony_ci// read/write, etc. The warning is enabled in the project to ensure code calling 197ffe3c632Sopenharmony_ci// protos can turn on -Wdirect-ivar-access without issues. 198ffe3c632Sopenharmony_ci#pragma clang diagnostic push 199ffe3c632Sopenharmony_ci#pragma clang diagnostic ignored "-Wdirect-ivar-access" 200ffe3c632Sopenharmony_ci 201ffe3c632Sopenharmony_ci- (void)writeDoubleNoTag:(double)value { 202ffe3c632Sopenharmony_ci GPBWriteRawLittleEndian64(&state_, GPBConvertDoubleToInt64(value)); 203ffe3c632Sopenharmony_ci} 204ffe3c632Sopenharmony_ci 205ffe3c632Sopenharmony_ci- (void)writeDouble:(int32_t)fieldNumber value:(double)value { 206ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatFixed64); 207ffe3c632Sopenharmony_ci GPBWriteRawLittleEndian64(&state_, GPBConvertDoubleToInt64(value)); 208ffe3c632Sopenharmony_ci} 209ffe3c632Sopenharmony_ci 210ffe3c632Sopenharmony_ci- (void)writeFloatNoTag:(float)value { 211ffe3c632Sopenharmony_ci GPBWriteRawLittleEndian32(&state_, GPBConvertFloatToInt32(value)); 212ffe3c632Sopenharmony_ci} 213ffe3c632Sopenharmony_ci 214ffe3c632Sopenharmony_ci- (void)writeFloat:(int32_t)fieldNumber value:(float)value { 215ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatFixed32); 216ffe3c632Sopenharmony_ci GPBWriteRawLittleEndian32(&state_, GPBConvertFloatToInt32(value)); 217ffe3c632Sopenharmony_ci} 218ffe3c632Sopenharmony_ci 219ffe3c632Sopenharmony_ci- (void)writeUInt64NoTag:(uint64_t)value { 220ffe3c632Sopenharmony_ci GPBWriteRawVarint64(&state_, value); 221ffe3c632Sopenharmony_ci} 222ffe3c632Sopenharmony_ci 223ffe3c632Sopenharmony_ci- (void)writeUInt64:(int32_t)fieldNumber value:(uint64_t)value { 224ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatVarint); 225ffe3c632Sopenharmony_ci GPBWriteRawVarint64(&state_, value); 226ffe3c632Sopenharmony_ci} 227ffe3c632Sopenharmony_ci 228ffe3c632Sopenharmony_ci- (void)writeInt64NoTag:(int64_t)value { 229ffe3c632Sopenharmony_ci GPBWriteRawVarint64(&state_, value); 230ffe3c632Sopenharmony_ci} 231ffe3c632Sopenharmony_ci 232ffe3c632Sopenharmony_ci- (void)writeInt64:(int32_t)fieldNumber value:(int64_t)value { 233ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatVarint); 234ffe3c632Sopenharmony_ci GPBWriteRawVarint64(&state_, value); 235ffe3c632Sopenharmony_ci} 236ffe3c632Sopenharmony_ci 237ffe3c632Sopenharmony_ci- (void)writeInt32NoTag:(int32_t)value { 238ffe3c632Sopenharmony_ci GPBWriteInt32NoTag(&state_, value); 239ffe3c632Sopenharmony_ci} 240ffe3c632Sopenharmony_ci 241ffe3c632Sopenharmony_ci- (void)writeInt32:(int32_t)fieldNumber value:(int32_t)value { 242ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatVarint); 243ffe3c632Sopenharmony_ci GPBWriteInt32NoTag(&state_, value); 244ffe3c632Sopenharmony_ci} 245ffe3c632Sopenharmony_ci 246ffe3c632Sopenharmony_ci- (void)writeFixed64NoTag:(uint64_t)value { 247ffe3c632Sopenharmony_ci GPBWriteRawLittleEndian64(&state_, value); 248ffe3c632Sopenharmony_ci} 249ffe3c632Sopenharmony_ci 250ffe3c632Sopenharmony_ci- (void)writeFixed64:(int32_t)fieldNumber value:(uint64_t)value { 251ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatFixed64); 252ffe3c632Sopenharmony_ci GPBWriteRawLittleEndian64(&state_, value); 253ffe3c632Sopenharmony_ci} 254ffe3c632Sopenharmony_ci 255ffe3c632Sopenharmony_ci- (void)writeFixed32NoTag:(uint32_t)value { 256ffe3c632Sopenharmony_ci GPBWriteRawLittleEndian32(&state_, value); 257ffe3c632Sopenharmony_ci} 258ffe3c632Sopenharmony_ci 259ffe3c632Sopenharmony_ci- (void)writeFixed32:(int32_t)fieldNumber value:(uint32_t)value { 260ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatFixed32); 261ffe3c632Sopenharmony_ci GPBWriteRawLittleEndian32(&state_, value); 262ffe3c632Sopenharmony_ci} 263ffe3c632Sopenharmony_ci 264ffe3c632Sopenharmony_ci- (void)writeBoolNoTag:(BOOL)value { 265ffe3c632Sopenharmony_ci GPBWriteRawByte(&state_, (value ? 1 : 0)); 266ffe3c632Sopenharmony_ci} 267ffe3c632Sopenharmony_ci 268ffe3c632Sopenharmony_ci- (void)writeBool:(int32_t)fieldNumber value:(BOOL)value { 269ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatVarint); 270ffe3c632Sopenharmony_ci GPBWriteRawByte(&state_, (value ? 1 : 0)); 271ffe3c632Sopenharmony_ci} 272ffe3c632Sopenharmony_ci 273ffe3c632Sopenharmony_ci- (void)writeStringNoTag:(const NSString *)value { 274ffe3c632Sopenharmony_ci size_t length = [value lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; 275ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, (int32_t)length); 276ffe3c632Sopenharmony_ci if (length == 0) { 277ffe3c632Sopenharmony_ci return; 278ffe3c632Sopenharmony_ci } 279ffe3c632Sopenharmony_ci 280ffe3c632Sopenharmony_ci const char *quickString = 281ffe3c632Sopenharmony_ci CFStringGetCStringPtr((CFStringRef)value, kCFStringEncodingUTF8); 282ffe3c632Sopenharmony_ci 283ffe3c632Sopenharmony_ci // Fast path: Most strings are short, if the buffer already has space, 284ffe3c632Sopenharmony_ci // add to it directly. 285ffe3c632Sopenharmony_ci NSUInteger bufferBytesLeft = state_.size - state_.position; 286ffe3c632Sopenharmony_ci if (bufferBytesLeft >= length) { 287ffe3c632Sopenharmony_ci NSUInteger usedBufferLength = 0; 288ffe3c632Sopenharmony_ci BOOL result; 289ffe3c632Sopenharmony_ci if (quickString != NULL) { 290ffe3c632Sopenharmony_ci memcpy(state_.bytes + state_.position, quickString, length); 291ffe3c632Sopenharmony_ci usedBufferLength = length; 292ffe3c632Sopenharmony_ci result = YES; 293ffe3c632Sopenharmony_ci } else { 294ffe3c632Sopenharmony_ci result = [value getBytes:state_.bytes + state_.position 295ffe3c632Sopenharmony_ci maxLength:bufferBytesLeft 296ffe3c632Sopenharmony_ci usedLength:&usedBufferLength 297ffe3c632Sopenharmony_ci encoding:NSUTF8StringEncoding 298ffe3c632Sopenharmony_ci options:(NSStringEncodingConversionOptions)0 299ffe3c632Sopenharmony_ci range:NSMakeRange(0, [value length]) 300ffe3c632Sopenharmony_ci remainingRange:NULL]; 301ffe3c632Sopenharmony_ci } 302ffe3c632Sopenharmony_ci if (result) { 303ffe3c632Sopenharmony_ci NSAssert2((usedBufferLength == length), 304ffe3c632Sopenharmony_ci @"Our UTF8 calc was wrong? %tu vs %zd", usedBufferLength, 305ffe3c632Sopenharmony_ci length); 306ffe3c632Sopenharmony_ci state_.position += usedBufferLength; 307ffe3c632Sopenharmony_ci return; 308ffe3c632Sopenharmony_ci } 309ffe3c632Sopenharmony_ci } else if (quickString != NULL) { 310ffe3c632Sopenharmony_ci [self writeRawPtr:quickString offset:0 length:length]; 311ffe3c632Sopenharmony_ci } else { 312ffe3c632Sopenharmony_ci // Slow path: just get it as data and write it out. 313ffe3c632Sopenharmony_ci NSData *utf8Data = [value dataUsingEncoding:NSUTF8StringEncoding]; 314ffe3c632Sopenharmony_ci NSAssert2(([utf8Data length] == length), 315ffe3c632Sopenharmony_ci @"Strings UTF8 length was wrong? %tu vs %zd", [utf8Data length], 316ffe3c632Sopenharmony_ci length); 317ffe3c632Sopenharmony_ci [self writeRawData:utf8Data]; 318ffe3c632Sopenharmony_ci } 319ffe3c632Sopenharmony_ci} 320ffe3c632Sopenharmony_ci 321ffe3c632Sopenharmony_ci- (void)writeString:(int32_t)fieldNumber value:(NSString *)value { 322ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatLengthDelimited); 323ffe3c632Sopenharmony_ci [self writeStringNoTag:value]; 324ffe3c632Sopenharmony_ci} 325ffe3c632Sopenharmony_ci 326ffe3c632Sopenharmony_ci- (void)writeGroupNoTag:(int32_t)fieldNumber value:(GPBMessage *)value { 327ffe3c632Sopenharmony_ci [value writeToCodedOutputStream:self]; 328ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatEndGroup); 329ffe3c632Sopenharmony_ci} 330ffe3c632Sopenharmony_ci 331ffe3c632Sopenharmony_ci- (void)writeGroup:(int32_t)fieldNumber value:(GPBMessage *)value { 332ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatStartGroup); 333ffe3c632Sopenharmony_ci [self writeGroupNoTag:fieldNumber value:value]; 334ffe3c632Sopenharmony_ci} 335ffe3c632Sopenharmony_ci 336ffe3c632Sopenharmony_ci- (void)writeUnknownGroupNoTag:(int32_t)fieldNumber 337ffe3c632Sopenharmony_ci value:(const GPBUnknownFieldSet *)value { 338ffe3c632Sopenharmony_ci [value writeToCodedOutputStream:self]; 339ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatEndGroup); 340ffe3c632Sopenharmony_ci} 341ffe3c632Sopenharmony_ci 342ffe3c632Sopenharmony_ci- (void)writeUnknownGroup:(int32_t)fieldNumber 343ffe3c632Sopenharmony_ci value:(GPBUnknownFieldSet *)value { 344ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatStartGroup); 345ffe3c632Sopenharmony_ci [self writeUnknownGroupNoTag:fieldNumber value:value]; 346ffe3c632Sopenharmony_ci} 347ffe3c632Sopenharmony_ci 348ffe3c632Sopenharmony_ci- (void)writeMessageNoTag:(GPBMessage *)value { 349ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, (int32_t)[value serializedSize]); 350ffe3c632Sopenharmony_ci [value writeToCodedOutputStream:self]; 351ffe3c632Sopenharmony_ci} 352ffe3c632Sopenharmony_ci 353ffe3c632Sopenharmony_ci- (void)writeMessage:(int32_t)fieldNumber value:(GPBMessage *)value { 354ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatLengthDelimited); 355ffe3c632Sopenharmony_ci [self writeMessageNoTag:value]; 356ffe3c632Sopenharmony_ci} 357ffe3c632Sopenharmony_ci 358ffe3c632Sopenharmony_ci- (void)writeBytesNoTag:(NSData *)value { 359ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, (int32_t)[value length]); 360ffe3c632Sopenharmony_ci [self writeRawData:value]; 361ffe3c632Sopenharmony_ci} 362ffe3c632Sopenharmony_ci 363ffe3c632Sopenharmony_ci- (void)writeBytes:(int32_t)fieldNumber value:(NSData *)value { 364ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatLengthDelimited); 365ffe3c632Sopenharmony_ci [self writeBytesNoTag:value]; 366ffe3c632Sopenharmony_ci} 367ffe3c632Sopenharmony_ci 368ffe3c632Sopenharmony_ci- (void)writeUInt32NoTag:(uint32_t)value { 369ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, value); 370ffe3c632Sopenharmony_ci} 371ffe3c632Sopenharmony_ci 372ffe3c632Sopenharmony_ci- (void)writeUInt32:(int32_t)fieldNumber value:(uint32_t)value { 373ffe3c632Sopenharmony_ci GPBWriteUInt32(&state_, fieldNumber, value); 374ffe3c632Sopenharmony_ci} 375ffe3c632Sopenharmony_ci 376ffe3c632Sopenharmony_ci- (void)writeEnumNoTag:(int32_t)value { 377ffe3c632Sopenharmony_ci GPBWriteInt32NoTag(&state_, value); 378ffe3c632Sopenharmony_ci} 379ffe3c632Sopenharmony_ci 380ffe3c632Sopenharmony_ci- (void)writeEnum:(int32_t)fieldNumber value:(int32_t)value { 381ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatVarint); 382ffe3c632Sopenharmony_ci GPBWriteInt32NoTag(&state_, value); 383ffe3c632Sopenharmony_ci} 384ffe3c632Sopenharmony_ci 385ffe3c632Sopenharmony_ci- (void)writeSFixed32NoTag:(int32_t)value { 386ffe3c632Sopenharmony_ci GPBWriteRawLittleEndian32(&state_, value); 387ffe3c632Sopenharmony_ci} 388ffe3c632Sopenharmony_ci 389ffe3c632Sopenharmony_ci- (void)writeSFixed32:(int32_t)fieldNumber value:(int32_t)value { 390ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatFixed32); 391ffe3c632Sopenharmony_ci GPBWriteRawLittleEndian32(&state_, value); 392ffe3c632Sopenharmony_ci} 393ffe3c632Sopenharmony_ci 394ffe3c632Sopenharmony_ci- (void)writeSFixed64NoTag:(int64_t)value { 395ffe3c632Sopenharmony_ci GPBWriteRawLittleEndian64(&state_, value); 396ffe3c632Sopenharmony_ci} 397ffe3c632Sopenharmony_ci 398ffe3c632Sopenharmony_ci- (void)writeSFixed64:(int32_t)fieldNumber value:(int64_t)value { 399ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatFixed64); 400ffe3c632Sopenharmony_ci GPBWriteRawLittleEndian64(&state_, value); 401ffe3c632Sopenharmony_ci} 402ffe3c632Sopenharmony_ci 403ffe3c632Sopenharmony_ci- (void)writeSInt32NoTag:(int32_t)value { 404ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, GPBEncodeZigZag32(value)); 405ffe3c632Sopenharmony_ci} 406ffe3c632Sopenharmony_ci 407ffe3c632Sopenharmony_ci- (void)writeSInt32:(int32_t)fieldNumber value:(int32_t)value { 408ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatVarint); 409ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, GPBEncodeZigZag32(value)); 410ffe3c632Sopenharmony_ci} 411ffe3c632Sopenharmony_ci 412ffe3c632Sopenharmony_ci- (void)writeSInt64NoTag:(int64_t)value { 413ffe3c632Sopenharmony_ci GPBWriteRawVarint64(&state_, GPBEncodeZigZag64(value)); 414ffe3c632Sopenharmony_ci} 415ffe3c632Sopenharmony_ci 416ffe3c632Sopenharmony_ci- (void)writeSInt64:(int32_t)fieldNumber value:(int64_t)value { 417ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatVarint); 418ffe3c632Sopenharmony_ci GPBWriteRawVarint64(&state_, GPBEncodeZigZag64(value)); 419ffe3c632Sopenharmony_ci} 420ffe3c632Sopenharmony_ci 421ffe3c632Sopenharmony_ci//%PDDM-DEFINE WRITE_PACKABLE_DEFNS(NAME, ARRAY_TYPE, TYPE, ACCESSOR_NAME) 422ffe3c632Sopenharmony_ci//%- (void)write##NAME##Array:(int32_t)fieldNumber 423ffe3c632Sopenharmony_ci//% NAME$S values:(GPB##ARRAY_TYPE##Array *)values 424ffe3c632Sopenharmony_ci//% NAME$S tag:(uint32_t)tag { 425ffe3c632Sopenharmony_ci//% if (tag != 0) { 426ffe3c632Sopenharmony_ci//% if (values.count == 0) return; 427ffe3c632Sopenharmony_ci//% __block size_t dataSize = 0; 428ffe3c632Sopenharmony_ci//% [values enumerate##ACCESSOR_NAME##ValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) { 429ffe3c632Sopenharmony_ci//%#pragma unused(idx, stop) 430ffe3c632Sopenharmony_ci//% dataSize += GPBCompute##NAME##SizeNoTag(value); 431ffe3c632Sopenharmony_ci//% }]; 432ffe3c632Sopenharmony_ci//% GPBWriteRawVarint32(&state_, tag); 433ffe3c632Sopenharmony_ci//% GPBWriteRawVarint32(&state_, (int32_t)dataSize); 434ffe3c632Sopenharmony_ci//% [values enumerate##ACCESSOR_NAME##ValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) { 435ffe3c632Sopenharmony_ci//%#pragma unused(idx, stop) 436ffe3c632Sopenharmony_ci//% [self write##NAME##NoTag:value]; 437ffe3c632Sopenharmony_ci//% }]; 438ffe3c632Sopenharmony_ci//% } else { 439ffe3c632Sopenharmony_ci//% [values enumerate##ACCESSOR_NAME##ValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) { 440ffe3c632Sopenharmony_ci//%#pragma unused(idx, stop) 441ffe3c632Sopenharmony_ci//% [self write##NAME:fieldNumber value:value]; 442ffe3c632Sopenharmony_ci//% }]; 443ffe3c632Sopenharmony_ci//% } 444ffe3c632Sopenharmony_ci//%} 445ffe3c632Sopenharmony_ci//% 446ffe3c632Sopenharmony_ci//%PDDM-DEFINE WRITE_UNPACKABLE_DEFNS(NAME, TYPE) 447ffe3c632Sopenharmony_ci//%- (void)write##NAME##Array:(int32_t)fieldNumber values:(NSArray *)values { 448ffe3c632Sopenharmony_ci//% for (TYPE *value in values) { 449ffe3c632Sopenharmony_ci//% [self write##NAME:fieldNumber value:value]; 450ffe3c632Sopenharmony_ci//% } 451ffe3c632Sopenharmony_ci//%} 452ffe3c632Sopenharmony_ci//% 453ffe3c632Sopenharmony_ci//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Double, Double, double, ) 454ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 455ffe3c632Sopenharmony_ci// clang-format off 456ffe3c632Sopenharmony_ci 457ffe3c632Sopenharmony_ci- (void)writeDoubleArray:(int32_t)fieldNumber 458ffe3c632Sopenharmony_ci values:(GPBDoubleArray *)values 459ffe3c632Sopenharmony_ci tag:(uint32_t)tag { 460ffe3c632Sopenharmony_ci if (tag != 0) { 461ffe3c632Sopenharmony_ci if (values.count == 0) return; 462ffe3c632Sopenharmony_ci __block size_t dataSize = 0; 463ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(double value, NSUInteger idx, BOOL *stop) { 464ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 465ffe3c632Sopenharmony_ci dataSize += GPBComputeDoubleSizeNoTag(value); 466ffe3c632Sopenharmony_ci }]; 467ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, tag); 468ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, (int32_t)dataSize); 469ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(double value, NSUInteger idx, BOOL *stop) { 470ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 471ffe3c632Sopenharmony_ci [self writeDoubleNoTag:value]; 472ffe3c632Sopenharmony_ci }]; 473ffe3c632Sopenharmony_ci } else { 474ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(double value, NSUInteger idx, BOOL *stop) { 475ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 476ffe3c632Sopenharmony_ci [self writeDouble:fieldNumber value:value]; 477ffe3c632Sopenharmony_ci }]; 478ffe3c632Sopenharmony_ci } 479ffe3c632Sopenharmony_ci} 480ffe3c632Sopenharmony_ci 481ffe3c632Sopenharmony_ci// clang-format on 482ffe3c632Sopenharmony_ci//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Float, Float, float, ) 483ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 484ffe3c632Sopenharmony_ci// clang-format off 485ffe3c632Sopenharmony_ci 486ffe3c632Sopenharmony_ci- (void)writeFloatArray:(int32_t)fieldNumber 487ffe3c632Sopenharmony_ci values:(GPBFloatArray *)values 488ffe3c632Sopenharmony_ci tag:(uint32_t)tag { 489ffe3c632Sopenharmony_ci if (tag != 0) { 490ffe3c632Sopenharmony_ci if (values.count == 0) return; 491ffe3c632Sopenharmony_ci __block size_t dataSize = 0; 492ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(float value, NSUInteger idx, BOOL *stop) { 493ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 494ffe3c632Sopenharmony_ci dataSize += GPBComputeFloatSizeNoTag(value); 495ffe3c632Sopenharmony_ci }]; 496ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, tag); 497ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, (int32_t)dataSize); 498ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(float value, NSUInteger idx, BOOL *stop) { 499ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 500ffe3c632Sopenharmony_ci [self writeFloatNoTag:value]; 501ffe3c632Sopenharmony_ci }]; 502ffe3c632Sopenharmony_ci } else { 503ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(float value, NSUInteger idx, BOOL *stop) { 504ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 505ffe3c632Sopenharmony_ci [self writeFloat:fieldNumber value:value]; 506ffe3c632Sopenharmony_ci }]; 507ffe3c632Sopenharmony_ci } 508ffe3c632Sopenharmony_ci} 509ffe3c632Sopenharmony_ci 510ffe3c632Sopenharmony_ci// clang-format on 511ffe3c632Sopenharmony_ci//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(UInt64, UInt64, uint64_t, ) 512ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 513ffe3c632Sopenharmony_ci// clang-format off 514ffe3c632Sopenharmony_ci 515ffe3c632Sopenharmony_ci- (void)writeUInt64Array:(int32_t)fieldNumber 516ffe3c632Sopenharmony_ci values:(GPBUInt64Array *)values 517ffe3c632Sopenharmony_ci tag:(uint32_t)tag { 518ffe3c632Sopenharmony_ci if (tag != 0) { 519ffe3c632Sopenharmony_ci if (values.count == 0) return; 520ffe3c632Sopenharmony_ci __block size_t dataSize = 0; 521ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) { 522ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 523ffe3c632Sopenharmony_ci dataSize += GPBComputeUInt64SizeNoTag(value); 524ffe3c632Sopenharmony_ci }]; 525ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, tag); 526ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, (int32_t)dataSize); 527ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) { 528ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 529ffe3c632Sopenharmony_ci [self writeUInt64NoTag:value]; 530ffe3c632Sopenharmony_ci }]; 531ffe3c632Sopenharmony_ci } else { 532ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) { 533ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 534ffe3c632Sopenharmony_ci [self writeUInt64:fieldNumber value:value]; 535ffe3c632Sopenharmony_ci }]; 536ffe3c632Sopenharmony_ci } 537ffe3c632Sopenharmony_ci} 538ffe3c632Sopenharmony_ci 539ffe3c632Sopenharmony_ci// clang-format on 540ffe3c632Sopenharmony_ci//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Int64, Int64, int64_t, ) 541ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 542ffe3c632Sopenharmony_ci// clang-format off 543ffe3c632Sopenharmony_ci 544ffe3c632Sopenharmony_ci- (void)writeInt64Array:(int32_t)fieldNumber 545ffe3c632Sopenharmony_ci values:(GPBInt64Array *)values 546ffe3c632Sopenharmony_ci tag:(uint32_t)tag { 547ffe3c632Sopenharmony_ci if (tag != 0) { 548ffe3c632Sopenharmony_ci if (values.count == 0) return; 549ffe3c632Sopenharmony_ci __block size_t dataSize = 0; 550ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) { 551ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 552ffe3c632Sopenharmony_ci dataSize += GPBComputeInt64SizeNoTag(value); 553ffe3c632Sopenharmony_ci }]; 554ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, tag); 555ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, (int32_t)dataSize); 556ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) { 557ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 558ffe3c632Sopenharmony_ci [self writeInt64NoTag:value]; 559ffe3c632Sopenharmony_ci }]; 560ffe3c632Sopenharmony_ci } else { 561ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) { 562ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 563ffe3c632Sopenharmony_ci [self writeInt64:fieldNumber value:value]; 564ffe3c632Sopenharmony_ci }]; 565ffe3c632Sopenharmony_ci } 566ffe3c632Sopenharmony_ci} 567ffe3c632Sopenharmony_ci 568ffe3c632Sopenharmony_ci// clang-format on 569ffe3c632Sopenharmony_ci//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Int32, Int32, int32_t, ) 570ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 571ffe3c632Sopenharmony_ci// clang-format off 572ffe3c632Sopenharmony_ci 573ffe3c632Sopenharmony_ci- (void)writeInt32Array:(int32_t)fieldNumber 574ffe3c632Sopenharmony_ci values:(GPBInt32Array *)values 575ffe3c632Sopenharmony_ci tag:(uint32_t)tag { 576ffe3c632Sopenharmony_ci if (tag != 0) { 577ffe3c632Sopenharmony_ci if (values.count == 0) return; 578ffe3c632Sopenharmony_ci __block size_t dataSize = 0; 579ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { 580ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 581ffe3c632Sopenharmony_ci dataSize += GPBComputeInt32SizeNoTag(value); 582ffe3c632Sopenharmony_ci }]; 583ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, tag); 584ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, (int32_t)dataSize); 585ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { 586ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 587ffe3c632Sopenharmony_ci [self writeInt32NoTag:value]; 588ffe3c632Sopenharmony_ci }]; 589ffe3c632Sopenharmony_ci } else { 590ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { 591ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 592ffe3c632Sopenharmony_ci [self writeInt32:fieldNumber value:value]; 593ffe3c632Sopenharmony_ci }]; 594ffe3c632Sopenharmony_ci } 595ffe3c632Sopenharmony_ci} 596ffe3c632Sopenharmony_ci 597ffe3c632Sopenharmony_ci// clang-format on 598ffe3c632Sopenharmony_ci//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(UInt32, UInt32, uint32_t, ) 599ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 600ffe3c632Sopenharmony_ci// clang-format off 601ffe3c632Sopenharmony_ci 602ffe3c632Sopenharmony_ci- (void)writeUInt32Array:(int32_t)fieldNumber 603ffe3c632Sopenharmony_ci values:(GPBUInt32Array *)values 604ffe3c632Sopenharmony_ci tag:(uint32_t)tag { 605ffe3c632Sopenharmony_ci if (tag != 0) { 606ffe3c632Sopenharmony_ci if (values.count == 0) return; 607ffe3c632Sopenharmony_ci __block size_t dataSize = 0; 608ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) { 609ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 610ffe3c632Sopenharmony_ci dataSize += GPBComputeUInt32SizeNoTag(value); 611ffe3c632Sopenharmony_ci }]; 612ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, tag); 613ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, (int32_t)dataSize); 614ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) { 615ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 616ffe3c632Sopenharmony_ci [self writeUInt32NoTag:value]; 617ffe3c632Sopenharmony_ci }]; 618ffe3c632Sopenharmony_ci } else { 619ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) { 620ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 621ffe3c632Sopenharmony_ci [self writeUInt32:fieldNumber value:value]; 622ffe3c632Sopenharmony_ci }]; 623ffe3c632Sopenharmony_ci } 624ffe3c632Sopenharmony_ci} 625ffe3c632Sopenharmony_ci 626ffe3c632Sopenharmony_ci// clang-format on 627ffe3c632Sopenharmony_ci//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Fixed64, UInt64, uint64_t, ) 628ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 629ffe3c632Sopenharmony_ci// clang-format off 630ffe3c632Sopenharmony_ci 631ffe3c632Sopenharmony_ci- (void)writeFixed64Array:(int32_t)fieldNumber 632ffe3c632Sopenharmony_ci values:(GPBUInt64Array *)values 633ffe3c632Sopenharmony_ci tag:(uint32_t)tag { 634ffe3c632Sopenharmony_ci if (tag != 0) { 635ffe3c632Sopenharmony_ci if (values.count == 0) return; 636ffe3c632Sopenharmony_ci __block size_t dataSize = 0; 637ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) { 638ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 639ffe3c632Sopenharmony_ci dataSize += GPBComputeFixed64SizeNoTag(value); 640ffe3c632Sopenharmony_ci }]; 641ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, tag); 642ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, (int32_t)dataSize); 643ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) { 644ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 645ffe3c632Sopenharmony_ci [self writeFixed64NoTag:value]; 646ffe3c632Sopenharmony_ci }]; 647ffe3c632Sopenharmony_ci } else { 648ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) { 649ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 650ffe3c632Sopenharmony_ci [self writeFixed64:fieldNumber value:value]; 651ffe3c632Sopenharmony_ci }]; 652ffe3c632Sopenharmony_ci } 653ffe3c632Sopenharmony_ci} 654ffe3c632Sopenharmony_ci 655ffe3c632Sopenharmony_ci// clang-format on 656ffe3c632Sopenharmony_ci//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Fixed32, UInt32, uint32_t, ) 657ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 658ffe3c632Sopenharmony_ci// clang-format off 659ffe3c632Sopenharmony_ci 660ffe3c632Sopenharmony_ci- (void)writeFixed32Array:(int32_t)fieldNumber 661ffe3c632Sopenharmony_ci values:(GPBUInt32Array *)values 662ffe3c632Sopenharmony_ci tag:(uint32_t)tag { 663ffe3c632Sopenharmony_ci if (tag != 0) { 664ffe3c632Sopenharmony_ci if (values.count == 0) return; 665ffe3c632Sopenharmony_ci __block size_t dataSize = 0; 666ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) { 667ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 668ffe3c632Sopenharmony_ci dataSize += GPBComputeFixed32SizeNoTag(value); 669ffe3c632Sopenharmony_ci }]; 670ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, tag); 671ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, (int32_t)dataSize); 672ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) { 673ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 674ffe3c632Sopenharmony_ci [self writeFixed32NoTag:value]; 675ffe3c632Sopenharmony_ci }]; 676ffe3c632Sopenharmony_ci } else { 677ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) { 678ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 679ffe3c632Sopenharmony_ci [self writeFixed32:fieldNumber value:value]; 680ffe3c632Sopenharmony_ci }]; 681ffe3c632Sopenharmony_ci } 682ffe3c632Sopenharmony_ci} 683ffe3c632Sopenharmony_ci 684ffe3c632Sopenharmony_ci// clang-format on 685ffe3c632Sopenharmony_ci//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(SInt32, Int32, int32_t, ) 686ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 687ffe3c632Sopenharmony_ci// clang-format off 688ffe3c632Sopenharmony_ci 689ffe3c632Sopenharmony_ci- (void)writeSInt32Array:(int32_t)fieldNumber 690ffe3c632Sopenharmony_ci values:(GPBInt32Array *)values 691ffe3c632Sopenharmony_ci tag:(uint32_t)tag { 692ffe3c632Sopenharmony_ci if (tag != 0) { 693ffe3c632Sopenharmony_ci if (values.count == 0) return; 694ffe3c632Sopenharmony_ci __block size_t dataSize = 0; 695ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { 696ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 697ffe3c632Sopenharmony_ci dataSize += GPBComputeSInt32SizeNoTag(value); 698ffe3c632Sopenharmony_ci }]; 699ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, tag); 700ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, (int32_t)dataSize); 701ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { 702ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 703ffe3c632Sopenharmony_ci [self writeSInt32NoTag:value]; 704ffe3c632Sopenharmony_ci }]; 705ffe3c632Sopenharmony_ci } else { 706ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { 707ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 708ffe3c632Sopenharmony_ci [self writeSInt32:fieldNumber value:value]; 709ffe3c632Sopenharmony_ci }]; 710ffe3c632Sopenharmony_ci } 711ffe3c632Sopenharmony_ci} 712ffe3c632Sopenharmony_ci 713ffe3c632Sopenharmony_ci// clang-format on 714ffe3c632Sopenharmony_ci//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(SInt64, Int64, int64_t, ) 715ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 716ffe3c632Sopenharmony_ci// clang-format off 717ffe3c632Sopenharmony_ci 718ffe3c632Sopenharmony_ci- (void)writeSInt64Array:(int32_t)fieldNumber 719ffe3c632Sopenharmony_ci values:(GPBInt64Array *)values 720ffe3c632Sopenharmony_ci tag:(uint32_t)tag { 721ffe3c632Sopenharmony_ci if (tag != 0) { 722ffe3c632Sopenharmony_ci if (values.count == 0) return; 723ffe3c632Sopenharmony_ci __block size_t dataSize = 0; 724ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) { 725ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 726ffe3c632Sopenharmony_ci dataSize += GPBComputeSInt64SizeNoTag(value); 727ffe3c632Sopenharmony_ci }]; 728ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, tag); 729ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, (int32_t)dataSize); 730ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) { 731ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 732ffe3c632Sopenharmony_ci [self writeSInt64NoTag:value]; 733ffe3c632Sopenharmony_ci }]; 734ffe3c632Sopenharmony_ci } else { 735ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) { 736ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 737ffe3c632Sopenharmony_ci [self writeSInt64:fieldNumber value:value]; 738ffe3c632Sopenharmony_ci }]; 739ffe3c632Sopenharmony_ci } 740ffe3c632Sopenharmony_ci} 741ffe3c632Sopenharmony_ci 742ffe3c632Sopenharmony_ci// clang-format on 743ffe3c632Sopenharmony_ci//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(SFixed64, Int64, int64_t, ) 744ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 745ffe3c632Sopenharmony_ci// clang-format off 746ffe3c632Sopenharmony_ci 747ffe3c632Sopenharmony_ci- (void)writeSFixed64Array:(int32_t)fieldNumber 748ffe3c632Sopenharmony_ci values:(GPBInt64Array *)values 749ffe3c632Sopenharmony_ci tag:(uint32_t)tag { 750ffe3c632Sopenharmony_ci if (tag != 0) { 751ffe3c632Sopenharmony_ci if (values.count == 0) return; 752ffe3c632Sopenharmony_ci __block size_t dataSize = 0; 753ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) { 754ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 755ffe3c632Sopenharmony_ci dataSize += GPBComputeSFixed64SizeNoTag(value); 756ffe3c632Sopenharmony_ci }]; 757ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, tag); 758ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, (int32_t)dataSize); 759ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) { 760ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 761ffe3c632Sopenharmony_ci [self writeSFixed64NoTag:value]; 762ffe3c632Sopenharmony_ci }]; 763ffe3c632Sopenharmony_ci } else { 764ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) { 765ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 766ffe3c632Sopenharmony_ci [self writeSFixed64:fieldNumber value:value]; 767ffe3c632Sopenharmony_ci }]; 768ffe3c632Sopenharmony_ci } 769ffe3c632Sopenharmony_ci} 770ffe3c632Sopenharmony_ci 771ffe3c632Sopenharmony_ci// clang-format on 772ffe3c632Sopenharmony_ci//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(SFixed32, Int32, int32_t, ) 773ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 774ffe3c632Sopenharmony_ci// clang-format off 775ffe3c632Sopenharmony_ci 776ffe3c632Sopenharmony_ci- (void)writeSFixed32Array:(int32_t)fieldNumber 777ffe3c632Sopenharmony_ci values:(GPBInt32Array *)values 778ffe3c632Sopenharmony_ci tag:(uint32_t)tag { 779ffe3c632Sopenharmony_ci if (tag != 0) { 780ffe3c632Sopenharmony_ci if (values.count == 0) return; 781ffe3c632Sopenharmony_ci __block size_t dataSize = 0; 782ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { 783ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 784ffe3c632Sopenharmony_ci dataSize += GPBComputeSFixed32SizeNoTag(value); 785ffe3c632Sopenharmony_ci }]; 786ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, tag); 787ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, (int32_t)dataSize); 788ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { 789ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 790ffe3c632Sopenharmony_ci [self writeSFixed32NoTag:value]; 791ffe3c632Sopenharmony_ci }]; 792ffe3c632Sopenharmony_ci } else { 793ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { 794ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 795ffe3c632Sopenharmony_ci [self writeSFixed32:fieldNumber value:value]; 796ffe3c632Sopenharmony_ci }]; 797ffe3c632Sopenharmony_ci } 798ffe3c632Sopenharmony_ci} 799ffe3c632Sopenharmony_ci 800ffe3c632Sopenharmony_ci// clang-format on 801ffe3c632Sopenharmony_ci//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Bool, Bool, BOOL, ) 802ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 803ffe3c632Sopenharmony_ci// clang-format off 804ffe3c632Sopenharmony_ci 805ffe3c632Sopenharmony_ci- (void)writeBoolArray:(int32_t)fieldNumber 806ffe3c632Sopenharmony_ci values:(GPBBoolArray *)values 807ffe3c632Sopenharmony_ci tag:(uint32_t)tag { 808ffe3c632Sopenharmony_ci if (tag != 0) { 809ffe3c632Sopenharmony_ci if (values.count == 0) return; 810ffe3c632Sopenharmony_ci __block size_t dataSize = 0; 811ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(BOOL value, NSUInteger idx, BOOL *stop) { 812ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 813ffe3c632Sopenharmony_ci dataSize += GPBComputeBoolSizeNoTag(value); 814ffe3c632Sopenharmony_ci }]; 815ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, tag); 816ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, (int32_t)dataSize); 817ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(BOOL value, NSUInteger idx, BOOL *stop) { 818ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 819ffe3c632Sopenharmony_ci [self writeBoolNoTag:value]; 820ffe3c632Sopenharmony_ci }]; 821ffe3c632Sopenharmony_ci } else { 822ffe3c632Sopenharmony_ci [values enumerateValuesWithBlock:^(BOOL value, NSUInteger idx, BOOL *stop) { 823ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 824ffe3c632Sopenharmony_ci [self writeBool:fieldNumber value:value]; 825ffe3c632Sopenharmony_ci }]; 826ffe3c632Sopenharmony_ci } 827ffe3c632Sopenharmony_ci} 828ffe3c632Sopenharmony_ci 829ffe3c632Sopenharmony_ci// clang-format on 830ffe3c632Sopenharmony_ci//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Enum, Enum, int32_t, Raw) 831ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 832ffe3c632Sopenharmony_ci// clang-format off 833ffe3c632Sopenharmony_ci 834ffe3c632Sopenharmony_ci- (void)writeEnumArray:(int32_t)fieldNumber 835ffe3c632Sopenharmony_ci values:(GPBEnumArray *)values 836ffe3c632Sopenharmony_ci tag:(uint32_t)tag { 837ffe3c632Sopenharmony_ci if (tag != 0) { 838ffe3c632Sopenharmony_ci if (values.count == 0) return; 839ffe3c632Sopenharmony_ci __block size_t dataSize = 0; 840ffe3c632Sopenharmony_ci [values enumerateRawValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { 841ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 842ffe3c632Sopenharmony_ci dataSize += GPBComputeEnumSizeNoTag(value); 843ffe3c632Sopenharmony_ci }]; 844ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, tag); 845ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, (int32_t)dataSize); 846ffe3c632Sopenharmony_ci [values enumerateRawValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { 847ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 848ffe3c632Sopenharmony_ci [self writeEnumNoTag:value]; 849ffe3c632Sopenharmony_ci }]; 850ffe3c632Sopenharmony_ci } else { 851ffe3c632Sopenharmony_ci [values enumerateRawValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { 852ffe3c632Sopenharmony_ci#pragma unused(idx, stop) 853ffe3c632Sopenharmony_ci [self writeEnum:fieldNumber value:value]; 854ffe3c632Sopenharmony_ci }]; 855ffe3c632Sopenharmony_ci } 856ffe3c632Sopenharmony_ci} 857ffe3c632Sopenharmony_ci 858ffe3c632Sopenharmony_ci// clang-format on 859ffe3c632Sopenharmony_ci//%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(String, NSString) 860ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 861ffe3c632Sopenharmony_ci// clang-format off 862ffe3c632Sopenharmony_ci 863ffe3c632Sopenharmony_ci- (void)writeStringArray:(int32_t)fieldNumber values:(NSArray *)values { 864ffe3c632Sopenharmony_ci for (NSString *value in values) { 865ffe3c632Sopenharmony_ci [self writeString:fieldNumber value:value]; 866ffe3c632Sopenharmony_ci } 867ffe3c632Sopenharmony_ci} 868ffe3c632Sopenharmony_ci 869ffe3c632Sopenharmony_ci// clang-format on 870ffe3c632Sopenharmony_ci//%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(Message, GPBMessage) 871ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 872ffe3c632Sopenharmony_ci// clang-format off 873ffe3c632Sopenharmony_ci 874ffe3c632Sopenharmony_ci- (void)writeMessageArray:(int32_t)fieldNumber values:(NSArray *)values { 875ffe3c632Sopenharmony_ci for (GPBMessage *value in values) { 876ffe3c632Sopenharmony_ci [self writeMessage:fieldNumber value:value]; 877ffe3c632Sopenharmony_ci } 878ffe3c632Sopenharmony_ci} 879ffe3c632Sopenharmony_ci 880ffe3c632Sopenharmony_ci// clang-format on 881ffe3c632Sopenharmony_ci//%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(Bytes, NSData) 882ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 883ffe3c632Sopenharmony_ci// clang-format off 884ffe3c632Sopenharmony_ci 885ffe3c632Sopenharmony_ci- (void)writeBytesArray:(int32_t)fieldNumber values:(NSArray *)values { 886ffe3c632Sopenharmony_ci for (NSData *value in values) { 887ffe3c632Sopenharmony_ci [self writeBytes:fieldNumber value:value]; 888ffe3c632Sopenharmony_ci } 889ffe3c632Sopenharmony_ci} 890ffe3c632Sopenharmony_ci 891ffe3c632Sopenharmony_ci// clang-format on 892ffe3c632Sopenharmony_ci//%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(Group, GPBMessage) 893ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 894ffe3c632Sopenharmony_ci// clang-format off 895ffe3c632Sopenharmony_ci 896ffe3c632Sopenharmony_ci- (void)writeGroupArray:(int32_t)fieldNumber values:(NSArray *)values { 897ffe3c632Sopenharmony_ci for (GPBMessage *value in values) { 898ffe3c632Sopenharmony_ci [self writeGroup:fieldNumber value:value]; 899ffe3c632Sopenharmony_ci } 900ffe3c632Sopenharmony_ci} 901ffe3c632Sopenharmony_ci 902ffe3c632Sopenharmony_ci// clang-format on 903ffe3c632Sopenharmony_ci//%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(UnknownGroup, GPBUnknownFieldSet) 904ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly. 905ffe3c632Sopenharmony_ci// clang-format off 906ffe3c632Sopenharmony_ci 907ffe3c632Sopenharmony_ci- (void)writeUnknownGroupArray:(int32_t)fieldNumber values:(NSArray *)values { 908ffe3c632Sopenharmony_ci for (GPBUnknownFieldSet *value in values) { 909ffe3c632Sopenharmony_ci [self writeUnknownGroup:fieldNumber value:value]; 910ffe3c632Sopenharmony_ci } 911ffe3c632Sopenharmony_ci} 912ffe3c632Sopenharmony_ci 913ffe3c632Sopenharmony_ci// clang-format on 914ffe3c632Sopenharmony_ci//%PDDM-EXPAND-END (19 expansions) 915ffe3c632Sopenharmony_ci 916ffe3c632Sopenharmony_ci- (void)writeMessageSetExtension:(int32_t)fieldNumber 917ffe3c632Sopenharmony_ci value:(GPBMessage *)value { 918ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem, 919ffe3c632Sopenharmony_ci GPBWireFormatStartGroup); 920ffe3c632Sopenharmony_ci GPBWriteUInt32(&state_, GPBWireFormatMessageSetTypeId, fieldNumber); 921ffe3c632Sopenharmony_ci [self writeMessage:GPBWireFormatMessageSetMessage value:value]; 922ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem, 923ffe3c632Sopenharmony_ci GPBWireFormatEndGroup); 924ffe3c632Sopenharmony_ci} 925ffe3c632Sopenharmony_ci 926ffe3c632Sopenharmony_ci- (void)writeRawMessageSetExtension:(int32_t)fieldNumber value:(NSData *)value { 927ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem, 928ffe3c632Sopenharmony_ci GPBWireFormatStartGroup); 929ffe3c632Sopenharmony_ci GPBWriteUInt32(&state_, GPBWireFormatMessageSetTypeId, fieldNumber); 930ffe3c632Sopenharmony_ci [self writeBytes:GPBWireFormatMessageSetMessage value:value]; 931ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem, 932ffe3c632Sopenharmony_ci GPBWireFormatEndGroup); 933ffe3c632Sopenharmony_ci} 934ffe3c632Sopenharmony_ci 935ffe3c632Sopenharmony_ci- (void)flush { 936ffe3c632Sopenharmony_ci if (state_.output != nil) { 937ffe3c632Sopenharmony_ci GPBRefreshBuffer(&state_); 938ffe3c632Sopenharmony_ci } 939ffe3c632Sopenharmony_ci} 940ffe3c632Sopenharmony_ci 941ffe3c632Sopenharmony_ci- (void)writeRawByte:(uint8_t)value { 942ffe3c632Sopenharmony_ci GPBWriteRawByte(&state_, value); 943ffe3c632Sopenharmony_ci} 944ffe3c632Sopenharmony_ci 945ffe3c632Sopenharmony_ci- (void)writeRawData:(const NSData *)data { 946ffe3c632Sopenharmony_ci [self writeRawPtr:[data bytes] offset:0 length:[data length]]; 947ffe3c632Sopenharmony_ci} 948ffe3c632Sopenharmony_ci 949ffe3c632Sopenharmony_ci- (void)writeRawPtr:(const void *)value 950ffe3c632Sopenharmony_ci offset:(size_t)offset 951ffe3c632Sopenharmony_ci length:(size_t)length { 952ffe3c632Sopenharmony_ci if (value == nil || length == 0) { 953ffe3c632Sopenharmony_ci return; 954ffe3c632Sopenharmony_ci } 955ffe3c632Sopenharmony_ci 956ffe3c632Sopenharmony_ci NSUInteger bufferLength = state_.size; 957ffe3c632Sopenharmony_ci NSUInteger bufferBytesLeft = bufferLength - state_.position; 958ffe3c632Sopenharmony_ci if (bufferBytesLeft >= length) { 959ffe3c632Sopenharmony_ci // We have room in the current buffer. 960ffe3c632Sopenharmony_ci memcpy(state_.bytes + state_.position, ((uint8_t *)value) + offset, length); 961ffe3c632Sopenharmony_ci state_.position += length; 962ffe3c632Sopenharmony_ci } else { 963ffe3c632Sopenharmony_ci // Write extends past current buffer. Fill the rest of this buffer and 964ffe3c632Sopenharmony_ci // flush. 965ffe3c632Sopenharmony_ci size_t bytesWritten = bufferBytesLeft; 966ffe3c632Sopenharmony_ci memcpy(state_.bytes + state_.position, ((uint8_t *)value) + offset, 967ffe3c632Sopenharmony_ci bytesWritten); 968ffe3c632Sopenharmony_ci offset += bytesWritten; 969ffe3c632Sopenharmony_ci length -= bytesWritten; 970ffe3c632Sopenharmony_ci state_.position = bufferLength; 971ffe3c632Sopenharmony_ci GPBRefreshBuffer(&state_); 972ffe3c632Sopenharmony_ci bufferLength = state_.size; 973ffe3c632Sopenharmony_ci 974ffe3c632Sopenharmony_ci // Now deal with the rest. 975ffe3c632Sopenharmony_ci // Since we have an output stream, this is our buffer 976ffe3c632Sopenharmony_ci // and buffer offset == 0 977ffe3c632Sopenharmony_ci if (length <= bufferLength) { 978ffe3c632Sopenharmony_ci // Fits in new buffer. 979ffe3c632Sopenharmony_ci memcpy(state_.bytes, ((uint8_t *)value) + offset, length); 980ffe3c632Sopenharmony_ci state_.position = length; 981ffe3c632Sopenharmony_ci } else { 982ffe3c632Sopenharmony_ci // Write is very big. Let's do it all at once. 983ffe3c632Sopenharmony_ci NSInteger written = [state_.output write:((uint8_t *)value) + offset maxLength:length]; 984ffe3c632Sopenharmony_ci if (written != (NSInteger)length) { 985ffe3c632Sopenharmony_ci [NSException raise:GPBCodedOutputStreamException_WriteFailed format:@""]; 986ffe3c632Sopenharmony_ci } 987ffe3c632Sopenharmony_ci } 988ffe3c632Sopenharmony_ci } 989ffe3c632Sopenharmony_ci} 990ffe3c632Sopenharmony_ci 991ffe3c632Sopenharmony_ci- (void)writeTag:(uint32_t)fieldNumber format:(GPBWireFormat)format { 992ffe3c632Sopenharmony_ci GPBWriteTagWithFormat(&state_, fieldNumber, format); 993ffe3c632Sopenharmony_ci} 994ffe3c632Sopenharmony_ci 995ffe3c632Sopenharmony_ci- (void)writeRawVarint32:(int32_t)value { 996ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, value); 997ffe3c632Sopenharmony_ci} 998ffe3c632Sopenharmony_ci 999ffe3c632Sopenharmony_ci- (void)writeRawVarintSizeTAs32:(size_t)value { 1000ffe3c632Sopenharmony_ci // Note the truncation. 1001ffe3c632Sopenharmony_ci GPBWriteRawVarint32(&state_, (int32_t)value); 1002ffe3c632Sopenharmony_ci} 1003ffe3c632Sopenharmony_ci 1004ffe3c632Sopenharmony_ci- (void)writeRawVarint64:(int64_t)value { 1005ffe3c632Sopenharmony_ci GPBWriteRawVarint64(&state_, value); 1006ffe3c632Sopenharmony_ci} 1007ffe3c632Sopenharmony_ci 1008ffe3c632Sopenharmony_ci- (void)writeRawLittleEndian32:(int32_t)value { 1009ffe3c632Sopenharmony_ci GPBWriteRawLittleEndian32(&state_, value); 1010ffe3c632Sopenharmony_ci} 1011ffe3c632Sopenharmony_ci 1012ffe3c632Sopenharmony_ci- (void)writeRawLittleEndian64:(int64_t)value { 1013ffe3c632Sopenharmony_ci GPBWriteRawLittleEndian64(&state_, value); 1014ffe3c632Sopenharmony_ci} 1015ffe3c632Sopenharmony_ci 1016ffe3c632Sopenharmony_ci#pragma clang diagnostic pop 1017ffe3c632Sopenharmony_ci 1018ffe3c632Sopenharmony_ci@end 1019ffe3c632Sopenharmony_ci 1020ffe3c632Sopenharmony_cisize_t GPBComputeDoubleSizeNoTag(Float64 value) { 1021ffe3c632Sopenharmony_ci#pragma unused(value) 1022ffe3c632Sopenharmony_ci return LITTLE_ENDIAN_64_SIZE; 1023ffe3c632Sopenharmony_ci} 1024ffe3c632Sopenharmony_ci 1025ffe3c632Sopenharmony_cisize_t GPBComputeFloatSizeNoTag(Float32 value) { 1026ffe3c632Sopenharmony_ci#pragma unused(value) 1027ffe3c632Sopenharmony_ci return LITTLE_ENDIAN_32_SIZE; 1028ffe3c632Sopenharmony_ci} 1029ffe3c632Sopenharmony_ci 1030ffe3c632Sopenharmony_cisize_t GPBComputeUInt64SizeNoTag(uint64_t value) { 1031ffe3c632Sopenharmony_ci return GPBComputeRawVarint64Size(value); 1032ffe3c632Sopenharmony_ci} 1033ffe3c632Sopenharmony_ci 1034ffe3c632Sopenharmony_cisize_t GPBComputeInt64SizeNoTag(int64_t value) { 1035ffe3c632Sopenharmony_ci return GPBComputeRawVarint64Size(value); 1036ffe3c632Sopenharmony_ci} 1037ffe3c632Sopenharmony_ci 1038ffe3c632Sopenharmony_cisize_t GPBComputeInt32SizeNoTag(int32_t value) { 1039ffe3c632Sopenharmony_ci if (value >= 0) { 1040ffe3c632Sopenharmony_ci return GPBComputeRawVarint32Size(value); 1041ffe3c632Sopenharmony_ci } else { 1042ffe3c632Sopenharmony_ci // Must sign-extend. 1043ffe3c632Sopenharmony_ci return 10; 1044ffe3c632Sopenharmony_ci } 1045ffe3c632Sopenharmony_ci} 1046ffe3c632Sopenharmony_ci 1047ffe3c632Sopenharmony_cisize_t GPBComputeSizeTSizeAsInt32NoTag(size_t value) { 1048ffe3c632Sopenharmony_ci return GPBComputeInt32SizeNoTag((int32_t)value); 1049ffe3c632Sopenharmony_ci} 1050ffe3c632Sopenharmony_ci 1051ffe3c632Sopenharmony_cisize_t GPBComputeFixed64SizeNoTag(uint64_t value) { 1052ffe3c632Sopenharmony_ci#pragma unused(value) 1053ffe3c632Sopenharmony_ci return LITTLE_ENDIAN_64_SIZE; 1054ffe3c632Sopenharmony_ci} 1055ffe3c632Sopenharmony_ci 1056ffe3c632Sopenharmony_cisize_t GPBComputeFixed32SizeNoTag(uint32_t value) { 1057ffe3c632Sopenharmony_ci#pragma unused(value) 1058ffe3c632Sopenharmony_ci return LITTLE_ENDIAN_32_SIZE; 1059ffe3c632Sopenharmony_ci} 1060ffe3c632Sopenharmony_ci 1061ffe3c632Sopenharmony_cisize_t GPBComputeBoolSizeNoTag(BOOL value) { 1062ffe3c632Sopenharmony_ci#pragma unused(value) 1063ffe3c632Sopenharmony_ci return 1; 1064ffe3c632Sopenharmony_ci} 1065ffe3c632Sopenharmony_ci 1066ffe3c632Sopenharmony_cisize_t GPBComputeStringSizeNoTag(NSString *value) { 1067ffe3c632Sopenharmony_ci NSUInteger length = [value lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; 1068ffe3c632Sopenharmony_ci return GPBComputeRawVarint32SizeForInteger(length) + length; 1069ffe3c632Sopenharmony_ci} 1070ffe3c632Sopenharmony_ci 1071ffe3c632Sopenharmony_cisize_t GPBComputeGroupSizeNoTag(GPBMessage *value) { 1072ffe3c632Sopenharmony_ci return [value serializedSize]; 1073ffe3c632Sopenharmony_ci} 1074ffe3c632Sopenharmony_ci 1075ffe3c632Sopenharmony_cisize_t GPBComputeUnknownGroupSizeNoTag(GPBUnknownFieldSet *value) { 1076ffe3c632Sopenharmony_ci return value.serializedSize; 1077ffe3c632Sopenharmony_ci} 1078ffe3c632Sopenharmony_ci 1079ffe3c632Sopenharmony_cisize_t GPBComputeMessageSizeNoTag(GPBMessage *value) { 1080ffe3c632Sopenharmony_ci size_t size = [value serializedSize]; 1081ffe3c632Sopenharmony_ci return GPBComputeRawVarint32SizeForInteger(size) + size; 1082ffe3c632Sopenharmony_ci} 1083ffe3c632Sopenharmony_ci 1084ffe3c632Sopenharmony_cisize_t GPBComputeBytesSizeNoTag(NSData *value) { 1085ffe3c632Sopenharmony_ci NSUInteger valueLength = [value length]; 1086ffe3c632Sopenharmony_ci return GPBComputeRawVarint32SizeForInteger(valueLength) + valueLength; 1087ffe3c632Sopenharmony_ci} 1088ffe3c632Sopenharmony_ci 1089ffe3c632Sopenharmony_cisize_t GPBComputeUInt32SizeNoTag(int32_t value) { 1090ffe3c632Sopenharmony_ci return GPBComputeRawVarint32Size(value); 1091ffe3c632Sopenharmony_ci} 1092ffe3c632Sopenharmony_ci 1093ffe3c632Sopenharmony_cisize_t GPBComputeEnumSizeNoTag(int32_t value) { 1094ffe3c632Sopenharmony_ci return GPBComputeInt32SizeNoTag(value); 1095ffe3c632Sopenharmony_ci} 1096ffe3c632Sopenharmony_ci 1097ffe3c632Sopenharmony_cisize_t GPBComputeSFixed32SizeNoTag(int32_t value) { 1098ffe3c632Sopenharmony_ci#pragma unused(value) 1099ffe3c632Sopenharmony_ci return LITTLE_ENDIAN_32_SIZE; 1100ffe3c632Sopenharmony_ci} 1101ffe3c632Sopenharmony_ci 1102ffe3c632Sopenharmony_cisize_t GPBComputeSFixed64SizeNoTag(int64_t value) { 1103ffe3c632Sopenharmony_ci#pragma unused(value) 1104ffe3c632Sopenharmony_ci return LITTLE_ENDIAN_64_SIZE; 1105ffe3c632Sopenharmony_ci} 1106ffe3c632Sopenharmony_ci 1107ffe3c632Sopenharmony_cisize_t GPBComputeSInt32SizeNoTag(int32_t value) { 1108ffe3c632Sopenharmony_ci return GPBComputeRawVarint32Size(GPBEncodeZigZag32(value)); 1109ffe3c632Sopenharmony_ci} 1110ffe3c632Sopenharmony_ci 1111ffe3c632Sopenharmony_cisize_t GPBComputeSInt64SizeNoTag(int64_t value) { 1112ffe3c632Sopenharmony_ci return GPBComputeRawVarint64Size(GPBEncodeZigZag64(value)); 1113ffe3c632Sopenharmony_ci} 1114ffe3c632Sopenharmony_ci 1115ffe3c632Sopenharmony_cisize_t GPBComputeDoubleSize(int32_t fieldNumber, double value) { 1116ffe3c632Sopenharmony_ci return GPBComputeTagSize(fieldNumber) + GPBComputeDoubleSizeNoTag(value); 1117ffe3c632Sopenharmony_ci} 1118ffe3c632Sopenharmony_ci 1119ffe3c632Sopenharmony_cisize_t GPBComputeFloatSize(int32_t fieldNumber, float value) { 1120ffe3c632Sopenharmony_ci return GPBComputeTagSize(fieldNumber) + GPBComputeFloatSizeNoTag(value); 1121ffe3c632Sopenharmony_ci} 1122ffe3c632Sopenharmony_ci 1123ffe3c632Sopenharmony_cisize_t GPBComputeUInt64Size(int32_t fieldNumber, uint64_t value) { 1124ffe3c632Sopenharmony_ci return GPBComputeTagSize(fieldNumber) + GPBComputeUInt64SizeNoTag(value); 1125ffe3c632Sopenharmony_ci} 1126ffe3c632Sopenharmony_ci 1127ffe3c632Sopenharmony_cisize_t GPBComputeInt64Size(int32_t fieldNumber, int64_t value) { 1128ffe3c632Sopenharmony_ci return GPBComputeTagSize(fieldNumber) + GPBComputeInt64SizeNoTag(value); 1129ffe3c632Sopenharmony_ci} 1130ffe3c632Sopenharmony_ci 1131ffe3c632Sopenharmony_cisize_t GPBComputeInt32Size(int32_t fieldNumber, int32_t value) { 1132ffe3c632Sopenharmony_ci return GPBComputeTagSize(fieldNumber) + GPBComputeInt32SizeNoTag(value); 1133ffe3c632Sopenharmony_ci} 1134ffe3c632Sopenharmony_ci 1135ffe3c632Sopenharmony_cisize_t GPBComputeFixed64Size(int32_t fieldNumber, uint64_t value) { 1136ffe3c632Sopenharmony_ci return GPBComputeTagSize(fieldNumber) + GPBComputeFixed64SizeNoTag(value); 1137ffe3c632Sopenharmony_ci} 1138ffe3c632Sopenharmony_ci 1139ffe3c632Sopenharmony_cisize_t GPBComputeFixed32Size(int32_t fieldNumber, uint32_t value) { 1140ffe3c632Sopenharmony_ci return GPBComputeTagSize(fieldNumber) + GPBComputeFixed32SizeNoTag(value); 1141ffe3c632Sopenharmony_ci} 1142ffe3c632Sopenharmony_ci 1143ffe3c632Sopenharmony_cisize_t GPBComputeBoolSize(int32_t fieldNumber, BOOL value) { 1144ffe3c632Sopenharmony_ci return GPBComputeTagSize(fieldNumber) + GPBComputeBoolSizeNoTag(value); 1145ffe3c632Sopenharmony_ci} 1146ffe3c632Sopenharmony_ci 1147ffe3c632Sopenharmony_cisize_t GPBComputeStringSize(int32_t fieldNumber, NSString *value) { 1148ffe3c632Sopenharmony_ci return GPBComputeTagSize(fieldNumber) + GPBComputeStringSizeNoTag(value); 1149ffe3c632Sopenharmony_ci} 1150ffe3c632Sopenharmony_ci 1151ffe3c632Sopenharmony_cisize_t GPBComputeGroupSize(int32_t fieldNumber, GPBMessage *value) { 1152ffe3c632Sopenharmony_ci return GPBComputeTagSize(fieldNumber) * 2 + GPBComputeGroupSizeNoTag(value); 1153ffe3c632Sopenharmony_ci} 1154ffe3c632Sopenharmony_ci 1155ffe3c632Sopenharmony_cisize_t GPBComputeUnknownGroupSize(int32_t fieldNumber, 1156ffe3c632Sopenharmony_ci GPBUnknownFieldSet *value) { 1157ffe3c632Sopenharmony_ci return GPBComputeTagSize(fieldNumber) * 2 + 1158ffe3c632Sopenharmony_ci GPBComputeUnknownGroupSizeNoTag(value); 1159ffe3c632Sopenharmony_ci} 1160ffe3c632Sopenharmony_ci 1161ffe3c632Sopenharmony_cisize_t GPBComputeMessageSize(int32_t fieldNumber, GPBMessage *value) { 1162ffe3c632Sopenharmony_ci return GPBComputeTagSize(fieldNumber) + GPBComputeMessageSizeNoTag(value); 1163ffe3c632Sopenharmony_ci} 1164ffe3c632Sopenharmony_ci 1165ffe3c632Sopenharmony_cisize_t GPBComputeBytesSize(int32_t fieldNumber, NSData *value) { 1166ffe3c632Sopenharmony_ci return GPBComputeTagSize(fieldNumber) + GPBComputeBytesSizeNoTag(value); 1167ffe3c632Sopenharmony_ci} 1168ffe3c632Sopenharmony_ci 1169ffe3c632Sopenharmony_cisize_t GPBComputeUInt32Size(int32_t fieldNumber, uint32_t value) { 1170ffe3c632Sopenharmony_ci return GPBComputeTagSize(fieldNumber) + GPBComputeUInt32SizeNoTag(value); 1171ffe3c632Sopenharmony_ci} 1172ffe3c632Sopenharmony_ci 1173ffe3c632Sopenharmony_cisize_t GPBComputeEnumSize(int32_t fieldNumber, int32_t value) { 1174ffe3c632Sopenharmony_ci return GPBComputeTagSize(fieldNumber) + GPBComputeEnumSizeNoTag(value); 1175ffe3c632Sopenharmony_ci} 1176ffe3c632Sopenharmony_ci 1177ffe3c632Sopenharmony_cisize_t GPBComputeSFixed32Size(int32_t fieldNumber, int32_t value) { 1178ffe3c632Sopenharmony_ci return GPBComputeTagSize(fieldNumber) + GPBComputeSFixed32SizeNoTag(value); 1179ffe3c632Sopenharmony_ci} 1180ffe3c632Sopenharmony_ci 1181ffe3c632Sopenharmony_cisize_t GPBComputeSFixed64Size(int32_t fieldNumber, int64_t value) { 1182ffe3c632Sopenharmony_ci return GPBComputeTagSize(fieldNumber) + GPBComputeSFixed64SizeNoTag(value); 1183ffe3c632Sopenharmony_ci} 1184ffe3c632Sopenharmony_ci 1185ffe3c632Sopenharmony_cisize_t GPBComputeSInt32Size(int32_t fieldNumber, int32_t value) { 1186ffe3c632Sopenharmony_ci return GPBComputeTagSize(fieldNumber) + GPBComputeSInt32SizeNoTag(value); 1187ffe3c632Sopenharmony_ci} 1188ffe3c632Sopenharmony_ci 1189ffe3c632Sopenharmony_cisize_t GPBComputeSInt64Size(int32_t fieldNumber, int64_t value) { 1190ffe3c632Sopenharmony_ci return GPBComputeTagSize(fieldNumber) + 1191ffe3c632Sopenharmony_ci GPBComputeRawVarint64Size(GPBEncodeZigZag64(value)); 1192ffe3c632Sopenharmony_ci} 1193ffe3c632Sopenharmony_ci 1194ffe3c632Sopenharmony_cisize_t GPBComputeMessageSetExtensionSize(int32_t fieldNumber, 1195ffe3c632Sopenharmony_ci GPBMessage *value) { 1196ffe3c632Sopenharmony_ci return GPBComputeTagSize(GPBWireFormatMessageSetItem) * 2 + 1197ffe3c632Sopenharmony_ci GPBComputeUInt32Size(GPBWireFormatMessageSetTypeId, fieldNumber) + 1198ffe3c632Sopenharmony_ci GPBComputeMessageSize(GPBWireFormatMessageSetMessage, value); 1199ffe3c632Sopenharmony_ci} 1200ffe3c632Sopenharmony_ci 1201ffe3c632Sopenharmony_cisize_t GPBComputeRawMessageSetExtensionSize(int32_t fieldNumber, 1202ffe3c632Sopenharmony_ci NSData *value) { 1203ffe3c632Sopenharmony_ci return GPBComputeTagSize(GPBWireFormatMessageSetItem) * 2 + 1204ffe3c632Sopenharmony_ci GPBComputeUInt32Size(GPBWireFormatMessageSetTypeId, fieldNumber) + 1205ffe3c632Sopenharmony_ci GPBComputeBytesSize(GPBWireFormatMessageSetMessage, value); 1206ffe3c632Sopenharmony_ci} 1207ffe3c632Sopenharmony_ci 1208ffe3c632Sopenharmony_cisize_t GPBComputeTagSize(int32_t fieldNumber) { 1209ffe3c632Sopenharmony_ci return GPBComputeRawVarint32Size( 1210ffe3c632Sopenharmony_ci GPBWireFormatMakeTag(fieldNumber, GPBWireFormatVarint)); 1211ffe3c632Sopenharmony_ci} 1212ffe3c632Sopenharmony_ci 1213ffe3c632Sopenharmony_cisize_t GPBComputeWireFormatTagSize(int field_number, GPBDataType dataType) { 1214ffe3c632Sopenharmony_ci size_t result = GPBComputeTagSize(field_number); 1215ffe3c632Sopenharmony_ci if (dataType == GPBDataTypeGroup) { 1216ffe3c632Sopenharmony_ci // Groups have both a start and an end tag. 1217ffe3c632Sopenharmony_ci return result * 2; 1218ffe3c632Sopenharmony_ci } else { 1219ffe3c632Sopenharmony_ci return result; 1220ffe3c632Sopenharmony_ci } 1221ffe3c632Sopenharmony_ci} 1222ffe3c632Sopenharmony_ci 1223ffe3c632Sopenharmony_cisize_t GPBComputeRawVarint32Size(int32_t value) { 1224ffe3c632Sopenharmony_ci // value is treated as unsigned, so it won't be sign-extended if negative. 1225ffe3c632Sopenharmony_ci if ((value & (0xffffffff << 7)) == 0) return 1; 1226ffe3c632Sopenharmony_ci if ((value & (0xffffffff << 14)) == 0) return 2; 1227ffe3c632Sopenharmony_ci if ((value & (0xffffffff << 21)) == 0) return 3; 1228ffe3c632Sopenharmony_ci if ((value & (0xffffffff << 28)) == 0) return 4; 1229ffe3c632Sopenharmony_ci return 5; 1230ffe3c632Sopenharmony_ci} 1231ffe3c632Sopenharmony_ci 1232ffe3c632Sopenharmony_cisize_t GPBComputeRawVarint32SizeForInteger(NSInteger value) { 1233ffe3c632Sopenharmony_ci // Note the truncation. 1234ffe3c632Sopenharmony_ci return GPBComputeRawVarint32Size((int32_t)value); 1235ffe3c632Sopenharmony_ci} 1236ffe3c632Sopenharmony_ci 1237ffe3c632Sopenharmony_cisize_t GPBComputeRawVarint64Size(int64_t value) { 1238ffe3c632Sopenharmony_ci if ((value & (0xffffffffffffffffL << 7)) == 0) return 1; 1239ffe3c632Sopenharmony_ci if ((value & (0xffffffffffffffffL << 14)) == 0) return 2; 1240ffe3c632Sopenharmony_ci if ((value & (0xffffffffffffffffL << 21)) == 0) return 3; 1241ffe3c632Sopenharmony_ci if ((value & (0xffffffffffffffffL << 28)) == 0) return 4; 1242ffe3c632Sopenharmony_ci if ((value & (0xffffffffffffffffL << 35)) == 0) return 5; 1243ffe3c632Sopenharmony_ci if ((value & (0xffffffffffffffffL << 42)) == 0) return 6; 1244ffe3c632Sopenharmony_ci if ((value & (0xffffffffffffffffL << 49)) == 0) return 7; 1245ffe3c632Sopenharmony_ci if ((value & (0xffffffffffffffffL << 56)) == 0) return 8; 1246ffe3c632Sopenharmony_ci if ((value & (0xffffffffffffffffL << 63)) == 0) return 9; 1247ffe3c632Sopenharmony_ci return 10; 1248ffe3c632Sopenharmony_ci} 1249