protected void WriteAttributeData(BinaryStream stream, NomadValue attr, int baseOffset = 0) { var ptr = (int)stream.Position + baseOffset; var data = attr.Data; var type = data.Type; var size = data.Size; var buffer = data.Buffer; if (data.Type == DataType.RML) { throw new InvalidOperationException("Cannot serialize RML data directly!"); } var oldSize = size; var attrData = (Format != FormatType.Resource) ? Utils.GetAttributeDataMiniBuffer(buffer, type) : Utils.GetAttributeDataBuffer(buffer, type); size = attrData.Length; var writeData = true; if (size > 4) { // return cached instance, else cache it and return empty var cache = WriteCache.PreCache(ptr, attrData, size); if (!cache.IsEmpty) { // sizes must match if (cache.Size == size) { var nD = DescriptorTag.CreateReference(cache.Offset, ReferenceType.Offset); nD.WriteTo(stream, baseOffset); writeData = false; } } } if (writeData) { var nD = DescriptorTag.Create(size); nD.WriteTo(stream); stream.Write(attrData); } }
protected void WriteAttributesData_FmtB(BinaryStream stream, List <NomadValue> attributes, int baseOffset) { var ptr = (int)stream.Position + baseOffset; var nAttrs = attributes.Count; if (nAttrs > 0) { var attrData = new byte[nAttrs * 4]; using (var bs = new BinaryStream(attrData)) { foreach (var attr in attributes) { bs.Write(attr.Id.Hash); } } var cache = WriteCache.PreCache(ptr, attrData, nAttrs); if (!cache.IsEmpty) { var ndAttrs = DescriptorTag.CreateReference(cache.Offset, ReferenceType.Offset); ndAttrs.WriteTo(stream, baseOffset); } else { var count = DescriptorTag.Create(nAttrs); count.WriteTo(stream); stream.Write(attrData); } foreach (var attr in attributes) { WriteAttribute_FmtB(stream, attr, baseOffset); } } else { // nothing to write stream.WriteByte(0); } }