diff options
author | Jon Skeet <skeet@pobox.com> | 2008-08-14 20:35:21 +0100 |
---|---|---|
committer | Jon Skeet <skeet@pobox.com> | 2008-08-14 20:35:21 +0100 |
commit | 575083ae9c3ecb17e14ae29aa20b784940fcdfd1 (patch) | |
tree | a8b536c9b8e2982e9e904e25b8489404cd727155 /csharp/ProtocolBuffers/CodedOutputStream.cs | |
parent | 1353315dede3e22266df73fca8dd421119597e46 (diff) | |
download | protobuf-575083ae9c3ecb17e14ae29aa20b784940fcdfd1.tar.gz protobuf-575083ae9c3ecb17e14ae29aa20b784940fcdfd1.tar.bz2 protobuf-575083ae9c3ecb17e14ae29aa20b784940fcdfd1.zip |
Initial support for services and extensions. Incomplete, but enough to get generated unit test files to compile.
Diffstat (limited to 'csharp/ProtocolBuffers/CodedOutputStream.cs')
-rw-r--r-- | csharp/ProtocolBuffers/CodedOutputStream.cs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/csharp/ProtocolBuffers/CodedOutputStream.cs b/csharp/ProtocolBuffers/CodedOutputStream.cs index 260db868..fff30d3f 100644 --- a/csharp/ProtocolBuffers/CodedOutputStream.cs +++ b/csharp/ProtocolBuffers/CodedOutputStream.cs @@ -98,6 +98,7 @@ namespace Google.ProtocolBuffers { /// Writes a double field value, including tag, to the stream. /// </summary> public void WriteDouble(int fieldNumber, double value) { + // TODO(jonskeet): Test this on different endiannesses WriteTag(fieldNumber, WireFormat.WireType.Fixed64); WriteRawLittleEndian64((ulong)BitConverter.DoubleToInt64Bits(value)); } @@ -107,8 +108,10 @@ namespace Google.ProtocolBuffers { /// </summary> public void WriteFloat(int fieldNumber, float value) { WriteTag(fieldNumber, WireFormat.WireType.Fixed32); - // FIXME: How do we convert a single to 32 bits? (Without unsafe code) - //WriteRawLittleEndian32(BitConverter.SingleT(value)); + // TODO(jonskeet): Test this on different endiannesses + byte[] rawBytes = BitConverter.GetBytes(value); + uint asInteger = BitConverter.ToUInt32(rawBytes, 0); + WriteRawLittleEndian32(asInteger); } /// <summary> @@ -434,7 +437,7 @@ namespace Google.ProtocolBuffers { /// Compute the number of bytes that would be needed to encode a /// fixed64 field, including the tag. /// </summary> - public static int ComputeFixed64Size(int fieldNumber, long value) { + public static int ComputeFixed64Size(int fieldNumber, ulong value) { return ComputeTagSize(fieldNumber) + LittleEndian64Size; } @@ -442,7 +445,7 @@ namespace Google.ProtocolBuffers { /// Compute the number of bytes that would be needed to encode a /// fixed32 field, including the tag. /// </summary> - public static int ComputeFixed32Size(int fieldNumber, int value) { + public static int ComputeFixed32Size(int fieldNumber, uint value) { return ComputeTagSize(fieldNumber) + LittleEndian32Size; } @@ -625,8 +628,8 @@ namespace Google.ProtocolBuffers { case FieldType.Int64: return ComputeInt64Size(fieldNumber, (long)value); case FieldType.UInt64: return ComputeUInt64Size(fieldNumber, (ulong)value); case FieldType.Int32: return ComputeInt32Size(fieldNumber, (int)value); - case FieldType.Fixed64: return ComputeFixed64Size(fieldNumber, (long)value); - case FieldType.Fixed32: return ComputeFixed32Size(fieldNumber, (int)value); + case FieldType.Fixed64: return ComputeFixed64Size(fieldNumber, (ulong)value); + case FieldType.Fixed32: return ComputeFixed32Size(fieldNumber, (uint)value); case FieldType.Bool: return ComputeBoolSize(fieldNumber, (bool)value); case FieldType.String: return ComputeStringSize(fieldNumber, (string)value); case FieldType.Group: return ComputeGroupSize(fieldNumber, (IMessage)value); |