Exemple #1
0
        private void WriteHash(NameHash hash, Stream into)
        {
            bool hasAHash = hash.ActualHash != 0;

            // Write the hash value
            byte[] bytes = BitConverter.GetBytes(hash.ActualHash);
            if (!BitConverter.IsLittleEndian)
                Array.Reverse(bytes);
            into.Write(bytes, 0, 2);

            // Having a hash of 0 means that this entity had hash collisions, so we
            // will write the full name.
            if (hash.ActualHash == 0)
            {
                mMethods[typeof(string)].Write(hash.Name, into);
            }
        }
Exemple #2
0
        private FieldData GetFieldForHash(NameHash hash, DictionaryEntry entry )
        {
            if ( hash.ActualHash == 0 )
            {
                if (hash.Name.Length == 0)
                    throw new UnknownTypeException("");

                foreach ( var field in entry.Fields )
                {
                    if (field.Hash.Name.Equals(hash.Name))
                        return field;
                }
            }
            else
            {
                foreach ( var field in entry.Fields )
                {
                    if (field.Hash.ActualHash == hash.ActualHash)
                        return field;
                }
            }

            return null;
        }
Exemple #3
0
        private NameHash ReadHash(Stream from)
        {
            NameHash hash = new NameHash();

            // Read the hash value
            byte[] bytes = new byte[2];
            from.Read(bytes, 0, 2);
            if (!BitConverter.IsLittleEndian)
                Array.Reverse(bytes);
            hash.ActualHash = BitConverter.ToInt16(bytes, 0);

            if (hash.ActualHash == 0)
            {
                hash.Name = (string)mMethods[typeof(string)].Read(@from);
            }
            return hash;
        }
Exemple #4
0
        private DictionaryEntry GetEntryForHash(NameHash hash)
        {
            if (hash.ActualHash == 0)
            {
                if (hash.Name.Length == 0)
                    throw new UnknownTypeException("");

                foreach (var cur in mTypes)
                {
                    if (cur.Value.Hash.Name.Equals(hash.Name))
                    {
                        return cur.Value;
                    }
                }
            }
            else
            {
                foreach (var cur in mTypes)
                {
                    if (cur.Value.Hash.ActualHash == hash.ActualHash)
                    {
                        return cur.Value;
                    }
                }
            }

            return null;
        }