IsNegativeFixnum() public static méthode

public static IsNegativeFixnum ( byte b ) : bool
b byte
Résultat bool
Exemple #1
0
    public sbyte UnpackSByte()
    {
        byte b = reader.ReadByte();

        if (MsgPack.IsPositiveFixnum(b))
        {
            return((sbyte)b);
        }
        if (MsgPack.IsNegativeFixnum(b))
        {
            return((sbyte)b);
        }
        switch (b)
        {
        case MsgPack.UInt8Type:
            var v = reader.ReadByte();
            if (v > sbyte.MaxValue)
            {
                throw new MessagePackOverflowException("sbyte");
            }
            return((sbyte)v);

        case MsgPack.Int8Type:
            return((sbyte)reader.ReadByte());

        default:
            throw new MessageTypeException();
        }
    }
Exemple #2
0
    public long UnpackLong()
    {
        byte b = reader.ReadByte();

        if (MsgPack.IsPositiveFixnum(b))
        {
            return(b);
        }
        if (MsgPack.IsNegativeFixnum(b))
        {
            return((sbyte)b);
        }
        switch (b)
        {
        case MsgPack.UInt8Type:
            return(reader.ReadByte());

        case MsgPack.UInt16Type:
            return(reader.ReadUInt16());

        case MsgPack.UInt32Type:
            return(reader.ReadUInt32());

        case MsgPack.UInt64Type:
            var v = reader.ReadUInt64();
            if (v > long.MaxValue)
            {
                throw new MessagePackOverflowException("long");
            }
            return((long)v);

        case MsgPack.Int8Type:
            return((sbyte)reader.ReadByte());

        case MsgPack.Int16Type:
            return(reader.ReadInt16());

        case MsgPack.Int32Type:
            return(reader.ReadInt32());

        case MsgPack.Int64Type:
            return(reader.ReadInt64());

        default:
            throw new MessageTypeException();
        }
    }
Exemple #3
0
    /// <summary>
    /// Unpacks the next value from the inputStream. The value can be of primitive type,
    /// a collection, a dictionary or a value of type implementing IMessagePackable.
    /// If it's a collection, the result type will be List&lt;object&gt;.
    /// If it's a dictionary, the result type will be Dictionary&lt;object, object&gt;.
    /// Enum and Char are unpacked as int.
    /// String is unpacked as byte[].
    /// </summary>
    public object UnpackObject()
    {
        byte b = reader.ReadByte();

        int rawLength;
        int arrayLength;
        int mapLength;

        if (TryUnpackRaw(b, out rawLength))
        {
            return(UnpackRawBody(rawLength));
        }
        if (TryUnpackArray(b, out arrayLength))
        {
            return(UnpackObjectListBody(arrayLength));
        }
        if (TryUnpackMap(b, out mapLength))
        {
            return(UnpackDictionaryBody(mapLength));
        }
        if (MsgPack.IsPositiveFixnum(b))
        {
            return(b);
        }
        if (MsgPack.IsNegativeFixnum(b))
        {
            return((sbyte)b);
        }
        switch (b)
        {
        case MsgPack.NilType:
            return(null);

        case MsgPack.BoolTrueType:
            return(true);

        case MsgPack.BoolFalseType:
            return(false);

        case MsgPack.DoubleType:
            return(reader.ReadDouble());

        case MsgPack.FloatType:
            return(reader.ReadSingle());

        case MsgPack.UInt64Type:
            return(reader.ReadUInt64());

        case MsgPack.Int64Type:
            return(reader.ReadInt64());

        case MsgPack.UInt32Type:
            return(reader.ReadUInt32());

        case MsgPack.Int32Type:
            return(reader.ReadInt32());

        case MsgPack.UInt16Type:
            return(reader.ReadUInt16());

        case MsgPack.Int16Type:
            return(reader.ReadInt16());

        case MsgPack.UInt8Type:
            return(reader.ReadByte());

        case MsgPack.Int8Type:
            return((sbyte)reader.ReadByte());

        default:
            throw new MessageTypeException();
        }
    }