Example #1
0
        private void WriteByteArray(TagNodeByteArray val)
        {
            byte[] lenBytes = BitConverter.GetBytes(val.Length);

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

            _stream.Write(lenBytes, 0, 4);
            _stream.Write(val.Data, 0, val.Length);
        }
Example #2
0
        private bool VerifyArray(TagNode tag, SchemaNodeArray schema)
        {
            TagNodeByteArray atag = tag as TagNodeByteArray;

            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);
        }
Example #3
0
        private TagNode ReadByteArray()
        {
            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);
            }

            byte[] data = new byte[length];
            _stream.Read(data, 0, length);

            TagNodeByteArray val = new TagNodeByteArray(data);

            return(val);
        }