public object Read(Format format, FormatReader reader) { if (format.IsPositiveFixInt) { return((ulong)reader.ReadPositiveFixInt(format)); } if (format.IsUInt8) { return((ulong)reader.ReadUInt8()); } if (format.IsUInt16) { return((ulong)reader.ReadUInt16()); } if (format.IsUInt32) { return((ulong)reader.ReadUInt32()); } if (format.IsUInt64) { return(reader.ReadUInt64()); } if (format.IsNil) { return(default(ulong)); } throw new FormatException(this, format, reader); }
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(); }
public object Read(Format format, FormatReader reader) { if (format.IsPositiveFixInt) { return((int)reader.ReadPositiveFixInt(format)); } if (format.IsUInt8) { return((int)reader.ReadUInt8()); } if (format.IsUInt16) { return((int)reader.ReadUInt16()); } if (format.IsUInt32) { return(Convert.ToInt32(reader.ReadUInt32())); } if (format.IsNegativeFixInt) { return((int)reader.ReadNegativeFixInt(format)); } if (format.IsInt8) { return((int)reader.ReadInt8()); } if (format.IsInt16) { return((int)reader.ReadInt16()); } if (format.IsInt32) { return(reader.ReadInt32()); } if (format.IsNil) { return(default(int)); } throw new FormatException(this, format, reader); }
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); }
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); }
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); }