예제 #1
0
 public object Read(Format format, FormatReader reader)
 {
     if (format.IsFloat32)
     {
         return((double)reader.ReadFloat32());
     }
     if (format.IsFloat64)
     {
         return(reader.ReadFloat64());
     }
     if (format.IsPositiveFixInt)
     {
         return((double)reader.ReadPositiveFixInt(format));
     }
     if (format.IsUInt8)
     {
         return((double)reader.ReadUInt8());
     }
     if (format.IsUInt16)
     {
         return((double)reader.ReadUInt16());
     }
     if (format.IsUInt32)
     {
         return((double)reader.ReadUInt32());
     }
     if (format.IsUInt64)
     {
         return((double)reader.ReadUInt64());
     }
     if (format.IsNegativeFixInt)
     {
         return((double)reader.ReadNegativeFixInt(format));
     }
     if (format.IsInt8)
     {
         return((double)reader.ReadInt8());
     }
     if (format.IsInt16)
     {
         return((double)reader.ReadInt16());
     }
     if (format.IsInt32)
     {
         return((double)reader.ReadInt32());
     }
     if (format.IsInt64)
     {
         return((double)reader.ReadInt64());
     }
     if (format.IsNil)
     {
         return(default(double));
     }
     throw new FormatException(this, format, reader);
 }
예제 #2
0
 public object ReadExt(uint length, FormatReader reader)
 {
     // Timestamp 32
     if (length == 4)
     {
         return(epoch.AddSeconds(reader.ReadUInt32()).ToLocalTime());
     }
     // Timestamp 64
     if (length == 8)
     {
         byte[] buffer      = reader.ReadBytesOfLength(8);
         uint   nanoseconds = ((uint)buffer[0] << 22) | ((uint)buffer[1] << 14) | ((uint)buffer[2] << 6) | (uint)buffer[3] >> 2;
         ulong  seconds     = ((ulong)(buffer[3] & 0x3) << 32) | ((ulong)buffer[4] << 24) | ((ulong)buffer[5] << 16) | ((ulong)buffer[6] << 8) | (ulong)buffer[7];
         return(epoch.AddTicks(nanoseconds / 100).AddSeconds(seconds).ToLocalTime());
     }
     // Timestamp 96
     if (length == 12)
     {
         return(epoch.AddTicks(reader.ReadUInt32() / 100).AddSeconds(reader.ReadInt64()).ToLocalTime());
     }
     throw new FormatException();
 }
예제 #3
0
 public object Read(Format format, FormatReader reader)
 {
     if (format.IsNil)
     {
         return(null);
     }
     if (format.IsFalse)
     {
         return(false);
     }
     if (format.IsTrue)
     {
         return(true);
     }
     if (format.IsPositiveFixInt)
     {
         return(reader.ReadPositiveFixInt(format));
     }
     if (format.IsUInt8)
     {
         return(reader.ReadUInt8());
     }
     if (format.IsUInt16)
     {
         return(reader.ReadUInt16());
     }
     if (format.IsUInt32)
     {
         return(reader.ReadUInt32());
     }
     if (format.IsUInt64)
     {
         return(reader.ReadUInt64());
     }
     if (format.IsNegativeFixInt)
     {
         return(reader.ReadNegativeFixInt(format));
     }
     if (format.IsInt8)
     {
         return(reader.ReadInt8());
     }
     if (format.IsInt16)
     {
         return(reader.ReadInt16());
     }
     if (format.IsInt32)
     {
         return(reader.ReadInt32());
     }
     if (format.IsInt64)
     {
         return(reader.ReadInt64());
     }
     if (format.IsFloat32)
     {
         return(reader.ReadFloat32());
     }
     if (format.IsFloat64)
     {
         return(reader.ReadFloat64());
     }
     if (format.IsFixStr)
     {
         return(reader.ReadFixStr(format));
     }
     if (format.IsStr8)
     {
         return(reader.ReadStr8());
     }
     if (format.IsStr16)
     {
         return(reader.ReadStr16());
     }
     if (format.IsStr32)
     {
         return(reader.ReadStr32());
     }
     if (format.IsBin8)
     {
         return(reader.ReadBin8());
     }
     if (format.IsBin16)
     {
         return(reader.ReadBin16());
     }
     if (format.IsBin32)
     {
         return(reader.ReadBin32());
     }
     if (format.IsArrayFamily)
     {
         return(ReadArray(format, reader));
     }
     if (format.IsMapFamily)
     {
         return(ReadMap(format, reader));
     }
     if (format.IsExtFamily)
     {
         return(ReadExt(format, reader));
     }
     throw new FormatException(this, format, reader);
 }
예제 #4
0
        JsonConverter AppendStream()
        {
            Format format = reader.ReadFormat();

            if (format.IsNil)
            {
                Append("null");
            }
            else if (format.IsFalse)
            {
                Append("false");
            }
            else if (format.IsTrue)
            {
                Append("true");
            }
            else if (format.IsPositiveFixInt)
            {
                Append(reader.ReadPositiveFixInt(format).ToString());
            }
            else if (format.IsUInt8)
            {
                Append(reader.ReadUInt8().ToString());
            }
            else if (format.IsUInt16)
            {
                Append(reader.ReadUInt16().ToString());
            }
            else if (format.IsUInt32)
            {
                Append(reader.ReadUInt32().ToString());
            }
            else if (format.IsUInt64)
            {
                Append(reader.ReadUInt64().ToString());
            }
            else if (format.IsNegativeFixInt)
            {
                Append(reader.ReadNegativeFixInt(format).ToString());
            }
            else if (format.IsInt8)
            {
                Append(reader.ReadInt8().ToString());
            }
            else if (format.IsInt16)
            {
                Append(reader.ReadInt16().ToString());
            }
            else if (format.IsInt32)
            {
                Append(reader.ReadInt32().ToString());
            }
            else if (format.IsInt64)
            {
                Append(reader.ReadInt64().ToString());
            }
            else if (format.IsFloat32)
            {
                Append(reader.ReadFloat32().ToString());
            }
            else if (format.IsFloat64)
            {
                Append(reader.ReadFloat64().ToString());
            }
            else if (format.IsFixStr)
            {
                AppendQuotedString(reader.ReadFixStr(format));
            }
            else if (format.IsStr8)
            {
                AppendQuotedString(reader.ReadStr8());
            }
            else if (format.IsStr16)
            {
                AppendQuotedString(reader.ReadStr16());
            }
            else if (format.IsStr32)
            {
                AppendQuotedString(reader.ReadStr32());
            }
            else if (format.IsBin8)
            {
                StringifyBinary(reader.ReadBin8());
            }
            else if (format.IsBin16)
            {
                StringifyBinary(reader.ReadBin16());
            }
            else if (format.IsBin32)
            {
                StringifyBinary(reader.ReadBin32());
            }
            else if (format.IsArrayFamily)
            {
                ReadArray(format);
            }
            else if (format.IsMapFamily)
            {
                ReadMap(format);
            }
            else if (format.IsExtFamily)
            {
                ReadExt(format);
            }
            else
            {
                throw new FormatException(format, reader);
            }

            return(this);
        }
예제 #5
0
 public object Read(Format format, FormatReader reader)
 {
     if (format.IsFloat32)
     {
         return(reader.ReadFloat32());
     }
     if (format.IsFloat64)
     {
         double value = reader.ReadFloat64();
         if (value > float.MaxValue)
         {
             throw new InvalidCastException(string.Format("{0} is too big for a float", value));
         }
         if (value < float.MinValue)
         {
             throw new InvalidCastException(string.Format("{0} is too small for a float", value));
         }
         return((float)value);
     }
     if (format.IsPositiveFixInt)
     {
         return((float)reader.ReadPositiveFixInt(format));
     }
     if (format.IsUInt8)
     {
         return((float)reader.ReadUInt8());
     }
     if (format.IsUInt16)
     {
         return((float)reader.ReadUInt16());
     }
     if (format.IsUInt32)
     {
         return((float)reader.ReadUInt32());
     }
     if (format.IsUInt64)
     {
         return((float)reader.ReadUInt64());
     }
     if (format.IsNegativeFixInt)
     {
         return((float)reader.ReadNegativeFixInt(format));
     }
     if (format.IsInt8)
     {
         return((float)reader.ReadInt8());
     }
     if (format.IsInt16)
     {
         return((float)reader.ReadInt16());
     }
     if (format.IsInt32)
     {
         return((float)reader.ReadInt32());
     }
     if (format.IsInt64)
     {
         return((float)reader.ReadInt64());
     }
     if (format.IsNil)
     {
         return(default(float));
     }
     throw new FormatException(this, format, reader);
 }