Пример #1
0
 public object Read(Format format, FormatReader reader)
 {
     if (format.IsNil)
     {
         return(new byte[0]);
     }
     if (format.IsBin8)
     {
         return(reader.ReadBin8());
     }
     if (format.IsBin16)
     {
         return(reader.ReadBin16());
     }
     if (format.IsBin32)
     {
         return(reader.ReadBin32());
     }
     throw new FormatException(this, format, reader);
 }
Пример #2
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);
 }
Пример #3
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);
        }