예제 #1
0
        // Generic deserialization
        private T[] DeserializeInternal(Action <int, T[]> arrayDeserializationAction)
        {
            // Read info about storage format
            ArrayStorageFormats format = (ArrayStorageFormats)SerializerStorage.ReadStorageFormatId(ArrayStorageBase.FormatIdSizeInBits);

            // Case: null Array
            if (format == ArrayStorageFormats.NullArray)
            {
                return(null);
            }

            // Case: empty Array
            if (format == ArrayStorageFormats.EmptyArray)
            {
                return(new T[0]);
            }

            // Restore array size
            Int32Serializer intSerializer = new Int32Serializer(SerializerStorage);
            Int32           arrayLength   = intSerializer.Deserialize();

            // Case: normal Array
            T[] outputArray = new T[arrayLength];

            // Deserialize array elements
            arrayDeserializationAction(arrayLength, outputArray);

            // Return result
            return(outputArray);
        }
예제 #2
0
        // Generic deserialization
        public T[] Deserialize()
        {
            // Read info about storage format
            ArrayStorageFormats format = (ArrayStorageFormats)SerializerStorage.ReadStorageFormatId(ArrayStorageBase.FormatIdSizeInBits);

            // Case: null Array
            if (format == ArrayStorageFormats.NullArray)
            {
                return(null);
            }

            // Case: empty Array
            if (format == ArrayStorageFormats.EmptyArray)
            {
                return(new T[0]);
            }

            // Restore array size
            Int32Serializer intSerializer = new Int32Serializer(SerializerStorage);
            Int32           arrayLength   = intSerializer.Deserialize();

            // Case: normal Array
            T[] outputArray = new T[arrayLength];

            // Deserialize all the elems
            for (int pos = 0; pos < arrayLength; pos++)
            {
                T value = m_ElemDeserializationFunc();
                outputArray[pos] = value;
            }

            // Return result
            return(outputArray);
        }
예제 #3
0
        // Deserialization
        public string Deserialize()
        {
            // Read info about storage format
            StringStorageFormats format = (StringStorageFormats)SerializerStorage.ReadStorageFormatId(StringStorageBase.FormatIdSizeInBits);

            // Case: null string
            if (format == StringStorageFormats.NullString)
            {
                return(null);
            }

            // Case: empty string
            if (format == StringStorageFormats.EmptyString)
            {
                return(string.Empty);
            }

            // Int32 serializer
            Int32Serializer int32Serializer = new Int32Serializer(SerializerStorage);

            // If caching has been activated
            if (SerializerStorage.UseValCaching)
            {
                // Case: cached string
                if (format == StringStorageFormats.CachedString)
                {
                    // Read object Id
                    this.ObjectId = int32Serializer.Deserialize();

                    // Take value from cache (objects dictionary)
                    return(ObjectCache.GetObjectValueForValueTypeField <String>(this));
                }

                // Case: new string
                if (format == StringStorageFormats.NormalString)
                {
                    this.ObjectId = int32Serializer.Deserialize();                                      // Read object Id
                    int    encodedStringLength = int32Serializer.Deserialize();                         // Read encoded string length
                    byte[] encodedString       = SerializerStorage.ReadPackedData(encodedStringLength); // Read encoded data

                    // Decode string
                    string result = Encoding.UTF8.GetString(encodedString, 0, encodedString.Length);

                    // Register new string in cache
                    ObjectCache.RegisterValue(result, this);

                    // Return result
                    return(result);
                }
            }
            else
            {
                // Value without caching (so without Id)
                int    encodedStringLength = int32Serializer.Deserialize();                         // Read encoded string length
                byte[] encodedString       = SerializerStorage.ReadPackedData(encodedStringLength); // Read encoded data

                // Decode string
                return(Encoding.UTF8.GetString(encodedString, 0, encodedString.Length));
            }

            // Default result
            return(null);
        }