// Constructor that requires config case value public StringStorageBase(StringStorageFormats confCase, byte usedConfigBits) : base((byte)confCase, FormatIdSizeInBits, usedConfigBits) { }
// 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); }