// Serialization of simple elements, that doesn't use caching private void SerializeInternal(T[] valueToSerialize, Action arraySerializeAction) { // Case: null value if (valueToSerialize == null) { SerializerStorage.WriteStorageFormat(new NullArray()); return; } // Case: empty Array if (valueToSerialize.Length == 0) { SerializerStorage.WriteStorageFormat(new EmptyArray()); return; } // Case: normal Array with Id SerializerStorage.WriteStorageFormat(new NormalArray()); // Store array size Int32Serializer intSerializer = new Int32Serializer(SerializerStorage); intSerializer.Serialize(valueToSerialize.Length); // Serialization of array elements arraySerializeAction(); }
// Serialization of simple elements, that doesn't use caching public void Serialize(T[] valueToSerialize) { // Case: null value if (valueToSerialize == null) { SerializerStorage.WriteStorageFormat(new NullArray()); return; } // Case: empty Array if (valueToSerialize.Length == 0) { SerializerStorage.WriteStorageFormat(new EmptyArray()); return; } // Case: normal Array with Id SerializerStorage.WriteStorageFormat(new NormalArray()); // Store array size Int32Serializer intSerializer = new Int32Serializer(SerializerStorage); intSerializer.Serialize(valueToSerialize.Length); // Serialization of array elements for (int pos = 0; pos < valueToSerialize.Length; pos++) { m_ElemSerializationAction(valueToSerialize[pos]); } }
// Serialization public void Serialize(string valueToSerialize) { // Case: null value if (valueToSerialize == null) { SerializerStorage.WriteStorageFormat(new NullString()); return; } // Case: empty string if (valueToSerialize == String.Empty) { SerializerStorage.WriteStorageFormat(new EmptyString()); return; } // Int32 Serializer Int32Serializer int32Serializer = new Int32Serializer(SerializerStorage); // If caching has been activated if (SerializerStorage.UseValCaching) { // Regular string - we should obtain string Id from cache bool shouldStoreFullData = ObjectCache.GetObjectIdForValueTypeField(valueToSerialize, this); // If we should store full data if (shouldStoreFullData) { // Case: normal string with Id SerializerStorage.WriteStorageFormat(new NormalString()); // Store Id of string int32Serializer.Serialize(this.ObjectId); // Encode string to utf-8 byte[] stringData = Encoding.UTF8.GetBytes(valueToSerialize); // Store string length int32Serializer.Serialize(stringData.Length); // Store string data SerializerStorage.WritePackedData(stringData); } else { // Case: cached string SerializerStorage.WriteStorageFormat(new CachedString()); // Store Id of string int32Serializer.Serialize(this.ObjectId); } } else { // Store value without caching SerializerStorage.WriteStorageFormat(new NormalString()); // Encode string to utf-8 byte[] stringData = Encoding.UTF8.GetBytes(valueToSerialize); // Store string length int32Serializer.Serialize(stringData.Length); // Store string data SerializerStorage.WritePackedData(stringData); } }