Beispiel #1
0
        private TagNode ReadIntArray()
        {
            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);
            }

            int[]  data   = new int[length];
            byte[] buffer = new byte[4];
            for (int i = 0; i < length; i++)
            {
                _stream.Read(buffer, 0, 4);
                if (BitConverter.IsLittleEndian)
                {
                    Array.Reverse(buffer);
                }
                data[i] = BitConverter.ToInt32(buffer, 0);
            }

            TagNodeIntArray val = new TagNodeIntArray(data);

            return(val);
        }
        private bool VerifyIntArray(TagNode tag, SchemaNodeIntArray schema)
        {
            TagNodeIntArray atag = tag as TagNodeIntArray;

            if (atag == null)
            {
                if (!OnInvalidTagType(new TagEventArgs(schema, tag)))
                {
                    return(false);
                }
            }
            if (schema.Length > 0 && atag.Length != schema.Length)
            {
                if (!OnInvalidTagValue(new TagEventArgs(schema, tag)))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #3
0
        private void WriteIntArray(TagNodeIntArray val)
        {
            byte[] lenBytes = BitConverter.GetBytes(val.Length);

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

            _stream.Write(lenBytes, 0, 4);

            byte[] data = new byte[val.Length * 4];
            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 * 4, 4);
            }

            _stream.Write(data, 0, data.Length);
        }