Esempio n. 1
0
        private void WriteLongArray(TagNodeLongArray val)
        {
            byte[] lenBytes = BitConverter.GetBytes(val.Length);

            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(lenBytes);
            }

            _stream.Write(lenBytes, 0, 4);

            byte[] data = new byte[val.Length * 8];
            for (int i = 0; i < val.Length; i++)
            {
                byte[] buffer = BitConverter.GetBytes(val.Data[i]);
                if (BitConverter.IsLittleEndian)
                {
                    Array.Reverse(buffer);
                }
                Array.Copy(buffer, 0, data, i * 8, 8);
            }

            _stream.Write(data, 0, data.Length);
        }
Esempio n. 2
0
        private TagNode ReadLongArray()
        {
            byte[] lenBytes = new byte[4];
            _stream.Read(lenBytes, 0, 4);
            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(lenBytes);
            }
            int length = BitConverter.ToInt32(lenBytes, 0);

            if (length < 0)
            {
                throw new NBTException(NBTException.MSG_READ_NEG);
            }
            List <byte> Lista_Bytes = new List <byte>();

            long[] data   = new long[length];
            byte[] buffer = new byte[8];
            for (int i = 0; i < length; i++)
            {
                _stream.Read(buffer, 0, 8);
                if (BitConverter.IsLittleEndian)
                {
                    Array.Reverse(buffer);
                }
                Lista_Bytes.AddRange(buffer);
                data[i] = BitConverter.ToInt64(buffer, 0);
            }
            TagNodeLongArray Nodo = new TagNodeLongArray(data);

            //Lista_Bytes.Reverse();
            new BitArray(Lista_Bytes.ToArray()).CopyTo(Nodo.Matriz_Bits, 0);
            //Array.Reverse(val.Matriz_Bits);
            Lista_Bytes = null;
            return(Nodo);
        }