ReadInt16() public method

public ReadInt16 ( ) : short
return short
Esempio n. 1
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();
        }
    }
Esempio n. 2
0
        private void parse()
        {
            BinaryReaderBigEndian reader = new BinaryReaderBigEndian(new MemoryStream(source.Data));

            if (string.Join("", reader.ReadChars(Signature.Length)) != Signature)
            {
                throw new Exception("signature not found");
            }

            Width  = reader.ReadInt16();
            Height = reader.ReadInt16();

            if (Width <= 0 || Height <= 0)
            {
                throw new Exception($"invalid dimensions encountered: width={Width}, height={Height}");
            }

            int unknown = reader.ReadInt16();

            if (unknown != 9)
            {
                throw new Exception($"invalid unknown constant: {unknown}");
            }

            int num = Width * Height;

            Cells = new MapCell[Width, Height];

            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    ushort value = reader.ReadUInt16();
                    Cells[x, y] = new MapCell()
                    {
                        Tile = value & 0b0000_0001_1111_1111, Type = value >> 9
                    };
                }
            }

            if (reader.BaseStream.Position != reader.BaseStream.Length)
            {
                throw new Exception($"missed {reader.BaseStream.Length - reader.BaseStream.Position} extra bytes at end of file");
            }
        }
    }