Exemple #1
0
        public uint ReadUShort()
        {
            _stream.Read(_buffer, 0, 1);
            ETFType type = (ETFType)_buffer[0];

            return((ushort)ReadLongInternal(type));
        }
Exemple #2
0
        public double ReadDouble()
        {
            _stream.Read(_buffer, 0, 1);
            ETFType type = (ETFType)_buffer[0];

            return(ReadDoubleInternal(type));
        }
Exemple #3
0
        public uint ReadByte()
        {
            _stream.Read(_buffer, 0, 1);
            ETFType type = (ETFType)_buffer[0];

            return((byte)ReadLongInternal(type));
        }
Exemple #4
0
        public bool?ReadNullableBool()
        {
            _stream.Read(_buffer, 0, 1);
            ETFType type = (ETFType)_buffer[0];

            if (type == ETFType.SMALL_ATOM_EXT)
            {
                _stream.Read(_buffer, 0, 1);
                switch (_buffer[0]) //Length
                {
                case 3:
                    if (ReadNil())
                    {
                        return(null);
                    }
                    break;

                case 4:
                    ReadTrue();
                    return(true);

                case 5:
                    ReadFalse();
                    return(false);
                }
            }
            throw new InvalidDataException();
        }
Exemple #5
0
        public float ReadSingle()
        {
            _stream.Read(_buffer, 0, 1);
            ETFType type = (ETFType)_buffer[0];

            return((float)ReadDoubleInternal(type));
        }
Exemple #6
0
        public long ReadLongInternal(ETFType type)
        {
            switch (type)
            {
            case ETFType.SMALL_INTEGER_EXT:
                _stream.Read(_buffer, 0, 1);
                return(_buffer[0]);

            case ETFType.INTEGER_EXT:
                _stream.Read(_buffer, 0, 4);
                return((_buffer[0] << 24) | (_buffer[1] << 16) | (_buffer[2] << 8) | (_buffer[3]));

            case ETFType.SMALL_BIG_EXT:
                _stream.Read(_buffer, 0, 2);
                bool isPositive = _buffer[0] == 0;
                byte count      = _buffer[1];

                int   shiftValue = (count - 1) * 8;
                ulong value      = 0;
                _stream.Read(_buffer, 0, count);
                for (int i = 0; i < count; i++, shiftValue -= 8)
                {
                    value = value + _buffer[i] << shiftValue;
                }
                if (!isPositive)
                {
                    return(-(long)value);
                }
                else
                {
                    return((long)value);
                }
            }
            throw new InvalidDataException();
        }
Exemple #7
0
        public ulong ReadULong()
        {
            _stream.Read(_buffer, 0, 1);
            ETFType type = (ETFType)_buffer[0];

            return((ulong)ReadLongInternal(type));
        }
Exemple #8
0
        public int ReadInt()
        {
            _stream.Read(_buffer, 0, 1);
            ETFType type = (ETFType)_buffer[0];

            return((int)ReadLongInternal(type));
        }
Exemple #9
0
        public double?ReadNullableDouble()
        {
            _stream.Read(_buffer, 0, 1);
            ETFType type = (ETFType)_buffer[0];

            if (type == ETFType.SMALL_ATOM_EXT && ReadNil())
            {
                return(null);
            }
            return(ReadDoubleInternal(type));
        }
Exemple #10
0
        public ulong?ReadNullableULong()
        {
            _stream.Read(_buffer, 0, 1);
            ETFType type = (ETFType)_buffer[0];

            if (type == ETFType.SMALL_ATOM_EXT && ReadNil())
            {
                return(null);
            }
            return((ulong)ReadLongInternal(type));
        }
Exemple #11
0
        public int?ReadNullableShort()
        {
            _stream.Read(_buffer, 0, 1);
            ETFType type = (ETFType)_buffer[0];

            if (type == ETFType.SMALL_ATOM_EXT && ReadNil())
            {
                return(null);
            }
            return((short)ReadLongInternal(type));
        }
Exemple #12
0
 public double ReadDoubleInternal(ETFType type)
 {
     throw new NotImplementedException();
 }