Google.Protobuf.CodedOutputStream.WriteInt32 C# (CSharp) Method

WriteInt32() public method

Writes an int32 field value, without a tag, to the stream.
public WriteInt32 ( int value ) : void
value int The value to write
return void
        public void WriteInt32(int value)
        {
            if (value >= 0)
            {
                WriteRawVarint32((uint) value);
            }
            else
            {
                // Must sign-extend.
                WriteRawVarint64((ulong) value);
            }
        }

Usage Example

Example #1
0
 static ByteString EncodeObject (object value, Type type, MemoryStream buffer, CodedOutputStream stream)
 {
     buffer.SetLength (0);
     if (value != null && !type.IsInstanceOfType (value))
         throw new ArgumentException ("Value of type " + value.GetType () + " cannot be encoded to type " + type);
     if (value == null && !type.IsSubclassOf (typeof(RemoteObject)) && !IsACollectionType (type))
         throw new ArgumentException ("null cannot be encoded to type " + type);
     if (value == null)
         stream.WriteUInt64 (0);
     else if (value is Enum)
         stream.WriteInt32 ((int)value);
     else {
         switch (Type.GetTypeCode (type)) {
         case TypeCode.Int32:
             stream.WriteInt32 ((int)value);
             break;
         case TypeCode.Int64:
             stream.WriteInt64 ((long)value);
             break;
         case TypeCode.UInt32:
             stream.WriteUInt32 ((uint)value);
             break;
         case TypeCode.UInt64:
             stream.WriteUInt64 ((ulong)value);
             break;
         case TypeCode.Single:
             stream.WriteFloat ((float)value);
             break;
         case TypeCode.Double:
             stream.WriteDouble ((double)value);
             break;
         case TypeCode.Boolean:
             stream.WriteBool ((bool)value);
             break;
         case TypeCode.String:
             stream.WriteString ((string)value);
             break;
         default:
             if (type.Equals (typeof(byte[])))
                 stream.WriteBytes (ByteString.CopyFrom ((byte[])value));
             else if (IsAClassType (type))
                 stream.WriteUInt64 (((RemoteObject)value).id);
             else if (IsAMessageType (type))
                 ((IMessage)value).WriteTo (buffer);
             else if (IsAListType (type))
                 WriteList (value, type, buffer);
             else if (IsADictionaryType (type))
                 WriteDictionary (value, type, buffer);
             else if (IsASetType (type))
                 WriteSet (value, type, buffer);
             else if (IsATupleType (type))
                 WriteTuple (value, type, buffer);
             else
                 throw new ArgumentException (type + " is not a serializable type");
             break;
         }
     }
     stream.Flush ();
     return ByteString.CopyFrom (buffer.GetBuffer (), 0, (int)buffer.Length);
 }
All Usage Examples Of Google.Protobuf.CodedOutputStream::WriteInt32