예제 #1
0
            public float ReadSingle(WireType _wt)
            {
                switch (_wt)
                {
                case WireType.Fixed32:
                {
                    int value = ReadInt32(_wt);
                    return(BitConverter.ToSingle(BitConverter.GetBytes(value), 0));
                }

                case WireType.Fixed64:
                {
                    double value = ReadDouble(_wt);
                    float  f     = (float)value;
                    if (PBHelperCSLE.IsInfinity(f) &&
                        !PBHelperCSLE.IsInfinity(value))
                    {
                        throw new InvalidOperationException("ReadSingle 读取错误 value:" + value);
                    }
                    return(f);
                }

                default:
                    throw new InvalidOperationException("错误的读取类型 ReadSingle:" + _wt);
                }
            }
예제 #2
0
            public void WriteDouble(double value)
            {
                switch (mWireType)
                {
                case WireType.Fixed32:
                    float f = (float)value;
                    if (PBHelperCSLE.IsInfinity(f) &&
                        !PBHelperCSLE.IsInfinity(value))
                    {
                        throw new InvalidOperationException("WriteDouble Fixed32 " + value);
                    }
                    WriteSingle(f);
                    return;

                case WireType.Fixed64:
                    WriteInt64(BitConverter.ToInt64(BitConverter.GetBytes(value), 0));
                    return;

                default:
                    DebugLogTypeError();
                    break;
                }
            }