static void WriteDouble(double value, ProtoWriter writer) { if (writer == null) { throw new ArgumentNullException("writer"); } switch (writer.wireType) { case WireType.Fixed32: float f = (float)value; if (Helpers.IsInfinity(f) && !Helpers.IsInfinity(value)) { throw new OverflowException(); } ProtoWriter.WriteSingle(f, writer); return; case WireType.Fixed64: #if FEAT_SAFE ProtoWriter.WriteInt64(BitConverter.ToInt64(BitConverter.GetBytes(value), 0), writer); #else ProtoWriter.WriteInt64(*(long *)&value, writer); #endif return; default: throw CreateException(writer); } }
float ReadSingle() { switch (wireType) { case WireType.Fixed32: { int value = ReadInt32(); #if FEAT_SAFE return(BitConverter.ToSingle(BitConverter.GetBytes(value), 0)); #else return(*(float *)&value); #endif } case WireType.Fixed64: { double value = ReadDouble(); float f = (float)value; if (Helpers.IsInfinity(f) && !Helpers.IsInfinity(value)) { throw AddErrorData(new OverflowException(), this); } return(f); } default: throw CreateException(); } }
public static void WriteDouble(double value, ProtoWriter writer) { if (writer == null) { throw new ArgumentNullException("writer"); } WireType wireType = writer.wireType; if (wireType == WireType.Fixed64) { ProtoWriter.WriteInt64(BitConverter.ToInt64(BitConverter.GetBytes(value), 0), writer); return; } if (wireType != WireType.Fixed32) { throw ProtoWriter.CreateException(writer); } float value2 = (float)value; if (Helpers.IsInfinity(value2) && !Helpers.IsInfinity(value)) { throw new OverflowException(); } ProtoWriter.WriteSingle(value2, writer); }
public unsafe static void WriteDouble(double value, ProtoWriter writer) { if (writer == null) { throw new ArgumentNullException("writer"); } switch (writer.wireType) { case WireType.Fixed32: { float value2 = (float)value; if (Helpers.IsInfinity(value2) && !Helpers.IsInfinity(value)) { throw new OverflowException(); } WriteSingle(value2, writer); break; } case WireType.Fixed64: WriteInt64(*(long *)(&value), writer); break; default: throw CreateException(writer); } }
public unsafe float ReadSingle() { switch (wireType) { case WireType.Fixed32: { int num3 = ReadInt32(); return(*(float *)(&num3)); } case WireType.Fixed64: { double num = ReadDouble(); float num2 = (float)num; if (Helpers.IsInfinity(num2) && !Helpers.IsInfinity(num)) { throw AddErrorData(new OverflowException(), this); } return(num2); } default: throw CreateWireTypeException(); } }
public float ReadSingle() { WireType wireType = this.wireType; if (wireType != WireType.Fixed64) { if (wireType != WireType.Fixed32) { throw this.CreateWireTypeException(); } int num = this.ReadInt32(); return(BitConverter.ToSingle(BitConverter.GetBytes(num), 0)); } else { double num2 = this.ReadDouble(); float num3 = (float)num2; if (Helpers.IsInfinity(num3) && !Helpers.IsInfinity(num2)) { throw ProtoReader.AddErrorData(new OverflowException(), this); } return(num3); } }