title: Google Protocol Buffers Objective-C
body: <p>I have the following method:</p>
  
  <pre><code>- (void)sendProtoToServer:(SampleMessage *)protoToSend {
     NSData *d = [protoToSend data];
     int s = [protoToSend serializedSize]; 
  
     if(s&lt;128){
        NSLog(@"&lt;128");
        NSData *size = [NSData dataWithBytes:&amp;s length:1]; 
        [socket writeData:size withTimeout:TIME_OUT tag:100];
        [socket writeData:d withTimeout:TIME_OUT tag:101];
     } else {
       NSLog(@"&gt;= 128");
       NSData *size = [NSData dataWithBytes:&amp;s length:2]; 
       [socket writeData:size withTimeout:TIME_OUT tag:100];
       [socket writeData:d withTimeout:TIME_OUT tag:101];
     }
  }
  </code></pre>
  
  <p>I know the above is very wrong (just my hack attempt at understanding it all).  I don't know how to get <code>NSData *size</code> the correct length for messages over 128 in size.  I think it's something to do with Variants</p>
  
  <p>Does anyone know how to do this? as it's driving me insane.  </p>
  
  <p>Thanks in advance.</p>