Exemple #1
0
    static MyJson.IJsonNode UnPackJsonNumber(System.IO.Stream stream, byte tagfirst)
    {
        MyJson.JsonNode_ValueNumber number = new MyJson.JsonNode_ValueNumber();
        bool isFloat = (tagfirst & 32) > 0;
        bool isBool  = (tagfirst & 16) > 0;
        bool isNull  = (tagfirst & 8) > 0;
        int  blen    = tagfirst % 8 + 1;

        byte[] buf = new byte[4];
        for (int i = 0; i < 4; i++)
        {
            buf[i] = 0;
        }
        if (isBool)
        {
            number.SetBool(isNull);
        }
        else if (isNull)
        {
            number.SetNull();
        }
        else if (isFloat)
        {
            stream.Read(buf, 0, blen);
            number.value = BitConverter.ToSingle(buf, 0);
        }
        else
        {
            stream.Read(buf, 0, blen);
            number.value = BitConverter.ToInt32(buf, 0);
        }

        return(number);
    }
Exemple #2
0
    static MyJson.IJsonNode UnPackJsonNumber(System.IO.Stream stream, byte tagfirst)
    {
        MyJson.JsonNode_ValueNumber number = new MyJson.JsonNode_ValueNumber();
        bool isFloat = (tagfirst & 32) > 0;
        bool isBool = (tagfirst & 16) > 0;
        bool isNull = (tagfirst & 8) > 0;
        int blen = tagfirst % 8 + 1;
        byte[] buf = new byte[4];
        for (int i = 0; i < 4; i++)
        {
            buf[i] = 0;
        }
        if (isBool)
        {
            number.SetBool(isNull);
        }
        else if (isNull)
        {
            number.SetNull();
        }
        else if (isFloat)
        {
            stream.Read(buf, 0, blen);
            number.value = BitConverter.ToSingle(buf, 0);
        }
        else
        {
            stream.Read(buf, 0, blen);
            number.value = BitConverter.ToInt32(buf, 0);
        }

        return number;
    }