// #NOTE the attributes here should match the ones used in EcfChunk's code public void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s) where TDoc : class where TCursor : class { var ecf_expander = s.Owner as EcfFileExpander; if (s.IsReading) { Parent = (EcfFileDefinition)s.UserData; } s.StreamAttribute("id", this, obj => Id, NumeralBase.Hex); s.StreamAttributeOpt("align", this, obj => AlignmentBit, b => b != EcfChunk.kDefaultAlignmentBit, NumeralBase.Hex); if (s.StreamAttributeEnumOpt("Compression", this, obj => CompressionType, e => e != EcfCompressionType.Stored)) { // #NOTE DeflateRaw requires the decompressed size to be known somewhere, and generic ECF files do not store such info // Only available in ERAs if (CompressionType == EcfCompressionType.DeflateRaw) { s.ThrowReadException(new InvalidDataException(CompressionType + " is not supported in this context")); } } if (s.IsReading) { ReadResourceFlags(s); } else if (s.IsWriting) { WriteResourceFlags(s); } s.StreamAttributeOpt("Path", this, obj => FilePath, Predicates.IsNotNullOrEmpty); // Don't try to write the file bytes bool try_to_serialize_file_bytes = s.IsReading || FilePath.IsNullOrEmpty(); if (ecf_expander != null) { if (!ecf_expander.ExpanderOptions.Test(EcfFileExpanderOptions.DontSaveChunksToFiles)) { try_to_serialize_file_bytes = true; } } if (try_to_serialize_file_bytes) { if (!s.StreamCursorBytesOpt(this, obj => FileBytes)) { if (FilePath.IsNullOrEmpty()) { s.ThrowReadException(new InvalidDataException("Expect Path attribute or file hex bytes")); } } } }