예제 #1
0
        /// <summary>
        /// Create an SerializedPropertyValue from a given byte array
        /// </summary>
        /// <param name="ba">The byte array</param>
        /// <returns>An SerializedPropertyValue object</returns>
        public static SerializedPropertyValue FromByteArray(byte[] ba)
        {
            StringName StringName = new StringName();

            if (ba.Length < 9)
            {
                throw new ArgumentException(String.Format("Size of the StringName is less than 9 ({0})", ba.Length));
            }

            UInt32 ValueSize = BitConverter.ToUInt32(ba, 0);

            if (ba.Length < ValueSize)
            {
                throw new ArgumentException(String.Format("Size of the StringName is not equal to {0} ({1})", ValueSize, ba.Length));
            }

            UInt32 NameSize = BitConverter.ToUInt32(ba, 4);

            if (ba.Length - 9 < NameSize)
            {
                throw new ArgumentException(String.Format("Size of the NameSize is not equal to {0} ({1})", ValueSize, ba.Length - 8));
            }

            byte[] Name = ba.Skip(9).Take((int)NameSize).ToArray();
            StringName.Name = Encoding.Unicode.GetString(Name).TrimEnd(new char[] { (char)0 });

            PropertyType Type = (PropertyType)BitConverter.ToUInt16(ba, 9);

            byte[] Value = ba.Skip(9 + (int)NameSize).Take((int)(ValueSize - 9 - (int)NameSize)).ToArray();
            StringName.TypedPropertyValue = new TypedPropertyValue(Type, Value);

            return(StringName);
        }
예제 #2
0
        /// <summary>
        /// Create a LinkTargetIDList from a given byte array
        /// </summary>
        /// <param name="ba">The byte array</param>
        /// <returns>A LinkTargetIDList object</returns>
        public static SerializedPropertyStorage FromByteArray(byte[] ba)
        {
            SerializedPropertyStorage SerializedPropertyStorage = new SerializedPropertyStorage();

            if (ba.Length < 28)
            {
                throw new ArgumentException(String.Format("Size of the SerializedPropertyStorage is less than 28 ({0})", ba.Length));
            }

            UInt32 StorageSize = BitConverter.ToUInt32(ba, 0);

            if (ba.Length < StorageSize)
            {
                throw new ArgumentException(String.Format("Size of the SerializedPropertyStore is less than {0} ({1})", StorageSize, ba.Length));
            }

            UInt32 Version = BitConverter.ToUInt32(ba, 4);

            if (SerializedPropertyStorage.Version != Version)
            {
                throw new ArgumentException(String.Format("Version is not equal to {0} ({1})", SerializedPropertyStorage.Version, Version));
            }

            byte[] FormatID = new byte[16];
            Buffer.BlockCopy(ba, 8, FormatID, 0, FormatID.Length);
            SerializedPropertyStorage.FormatID = new Guid(FormatID);

            ba = ba.Skip(24).ToArray();
            UInt32 ValueSize = BitConverter.ToUInt32(ba, 0);

            while (ValueSize > 5)
            {
                SerializedPropertyValue PropertyValue;
                if (SerializedPropertyStorage.FormatID.Equals(new Guid("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")))
                {
                    PropertyValue = StringName.FromByteArray(ba);
                }
                else
                {
                    PropertyValue = IntegerName.FromByteArray(ba);
                }
                SerializedPropertyStorage.PropertyStorage.Add(PropertyValue);
                ba        = ba.Skip((int)ValueSize).ToArray();
                ValueSize = BitConverter.ToUInt32(ba, 0);
            }

            return(SerializedPropertyStorage);
        }