Exemplo n.º 1
0
 public void WriteNullable(
     MutagenWriter writer,
     ITranslatedStringGetter?item,
     RecordType header,
     StringBinaryType binaryType,
     StringsSource source)
 {
     if (item == null)
     {
         return;
     }
     try
     {
         using (HeaderExport.Header(writer, header, ObjectType.Subrecord))
         {
             if (writer.MetaData.StringsWriter == null)
             {
                 writer.Write(
                     item.String ?? string.Empty,
                     binaryType: binaryType);
             }
             else
             {
                 writer.Write(writer.MetaData.StringsWriter.Register(item, source));
             }
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Factory(ex, header);
     }
 }
Exemplo n.º 2
0
 public void Write(
     MutagenWriter writer,
     T item,
     RecordType header,
     bool nullable)
 {
     if (item == null)
     {
         if (nullable)
         {
             return;
         }
         throw new ArgumentException("Non optional string was null.");
     }
     try
     {
         using (HeaderExport.Header(writer, header, ObjectType.Subrecord))
         {
             Write(writer, item);
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Factory(ex, header);
     }
 }
Exemplo n.º 3
0
            public static BodyTemplate ParseBod2(ushort version, IMutagenReadStream frame, SubrecordHeader subrecordHeader)
            {
                var len = subrecordHeader.ContentLength;

                if (version <= 22 && len <= 8)
                {
                    throw SubrecordException.Create("BOD2 can not be parsed on Form Versions <= 22 with length <= 8", RecordTypes.BOD2);
                }

                var item = new BodyTemplate();

                item.ActsLike44       = true;
                item.FirstPersonFlags = EnumBinaryTranslation <BipedObjectFlag, IMutagenReadStream, MutagenWriter> .Instance.Parse(
                    reader : frame,
                    length : 4);

                if (len == 8)
                {
                    item.ArmorType = EnumBinaryTranslation <ArmorType, IMutagenReadStream, MutagenWriter> .Instance.Parse(
                        reader : frame,
                        length : 4);
                }
                else
                {
                    item.Flags = EnumBinaryTranslation <BodyTemplate.Flag, IMutagenReadStream, MutagenWriter> .Instance.Parse(
                        reader : frame,
                        length : 4);

                    item.ArmorType = EnumBinaryTranslation <ArmorType, IMutagenReadStream, MutagenWriter> .Instance.Parse(
                        reader : frame,
                        length : 4);
                }
                return(item);
            }
 public static void Write <T>(
     this TypicalBinaryTranslation <T, MutagenFrame, MutagenWriter> transl,
     MutagenWriter writer,
     T item,
     RecordType header,
     bool nullable)
 {
     if (item == null)
     {
         if (nullable)
         {
             return;
         }
         throw new ArgumentException("Non optional string was null.");
     }
     try
     {
         using (HeaderExport.Header(writer, header, ObjectType.Subrecord))
         {
             transl.Write(writer, item);
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Factory(ex, header);
     }
 }
Exemplo n.º 5
0
 public static void WriteNullable <T>(
     this PrimitiveBinaryTranslation <T, MutagenFrame, MutagenWriter> transl,
     MutagenWriter writer,
     T?item,
     RecordType header,
     Action <MutagenWriter, T>?write = null)
     where T : struct
 {
     if (!item.HasValue)
     {
         return;
     }
     write ??= transl.Write;
     try
     {
         using (HeaderExport.Header(writer, header, ObjectType.Subrecord))
         {
             write(writer, item.Value);
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Factory(ex, header);
     }
 }
Exemplo n.º 6
0
 public static void Write(MutagenWriter writer, float?item, RecordType header, FloatIntegerType integerType, double multiplier)
 {
     try
     {
         if (item == null)
         {
             return;
         }
         using (HeaderExport.Subrecord(writer, header))
         {
             Write(writer, item, integerType, multiplier);
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Enrich(ex, header);
     }
 }
Exemplo n.º 7
0
 public void Write(
     MutagenWriter writer,
     E item,
     RecordType header,
     long length)
 {
     try
     {
         using (HeaderExport.Header(writer, header, ObjectType.Subrecord))
         {
             WriteValue(writer, item, length);
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Factory(ex, header);
     }
 }
Exemplo n.º 8
0
 public void Write <T>(
     MutagenWriter writer,
     FormLink <T> item,
     RecordType header)
     where T : class, IMajorRecordCommonGetter
 {
     try
     {
         FormKeyBinaryTranslation.Instance.Write(
             writer,
             item.FormKey,
             header);
     }
     catch (Exception ex)
     {
         throw SubrecordException.Enrich(ex, header);
     }
 }
 public static void Write(
     this PrimitiveBinaryTranslation <bool, MutagenFrame, MutagenWriter> transl,
     MutagenWriter writer,
     bool item,
     RecordType header,
     byte byteLength)
 {
     try
     {
         using (HeaderExport.Header(writer, header, ObjectType.Subrecord))
         {
             writer.Write(item ? 1 : 0, byteLength);
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Factory(ex, header);
     }
 }
 public void Write(
     MutagenWriter writer,
     T item,
     RecordType header,
     Action <MutagenWriter, T>?write = null)
 {
     write ??= this.Write;
     try
     {
         using (HeaderExport.Header(writer, header, ObjectType.Subrecord))
         {
             write(writer, item);
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Enrich(ex, header);
     }
 }
Exemplo n.º 11
0
 public static void Write <TEnum>(
     this EnumBinaryTranslation <TEnum, MutagenFrame, MutagenWriter> transl,
     MutagenWriter writer,
     TEnum item,
     RecordType header,
     long length)
     where TEnum : struct, Enum, IConvertible
 {
     try
     {
         using (HeaderExport.Header(writer, header, ObjectType.Subrecord))
         {
             transl.WriteValue(writer, item, length);
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Factory(ex, header);
     }
 }
Exemplo n.º 12
0
 public void Write(
     MutagenWriter writer,
     string item,
     RecordType header,
     StringBinaryType binaryType = StringBinaryType.NullTerminate)
 {
     try
     {
         using (HeaderExport.Header(writer, header, ObjectType.Subrecord))
         {
             writer.Write(
                 item,
                 binaryType: binaryType);
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Factory(ex, header);
     }
 }
 public void Write(
     MutagenWriter writer,
     FormKey item,
     RecordType header,
     bool nullable = false)
 {
     try
     {
         using (HeaderExport.Header(writer, header, ObjectType.Subrecord))
         {
             this.Write(
                 writer,
                 item);
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Enrich(ex, header);
     }
 }
Exemplo n.º 14
0
 public void WriteAsMarker(
     MutagenWriter writer,
     bool item,
     RecordType header)
 {
     try
     {
         if (!item)
         {
             return;
         }
         using (HeaderExport.Header(writer, header, ObjectType.Subrecord))
         {
             // Presence of marker signifies true
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Factory(ex, header);
     }
 }
Exemplo n.º 15
0
 public void Write(
     MutagenWriter writer,
     ReadOnlyMemorySlice <byte>?item,
     RecordType header)
 {
     try
     {
         if (!item.HasValue)
         {
             return;
         }
         using (HeaderExport.Subrecord(writer, header))
         {
             Write(writer, item.Value.Span);
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Enrich(ex, header);
     }
 }
Exemplo n.º 16
0
 public void WriteNullable(
     MutagenWriter writer,
     E?item,
     RecordType header,
     long length)
 {
     try
     {
         if (!item.HasValue)
         {
             return;
         }
         using (HeaderExport.Header(writer, header, ObjectType.Subrecord))
         {
             WriteValue(writer, item.Value, length);
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Factory(ex, header);
     }
 }
Exemplo n.º 17
0
 public static void WriteAsMarker(
     this PrimitiveBinaryTranslation <bool, MutagenFrame, MutagenWriter> transl,
     MutagenWriter writer,
     bool item,
     RecordType header)
 {
     try
     {
         if (!item)
         {
             return;
         }
         using (HeaderExport.Header(writer, header, ObjectType.Subrecord))
         {
             // Presence of marker signifies true
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Factory(ex, header);
     }
 }
 public static void Write(
     this ByteArrayBinaryTranslation <MutagenFrame, MutagenWriter> transl,
     MutagenWriter writer,
     ReadOnlyMemorySlice <byte>?item,
     RecordType header)
 {
     try
     {
         if (!item.HasValue)
         {
             return;
         }
         using (HeaderExport.Subrecord(writer, header))
         {
             transl.Write(writer, item.Value.Span);
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Enrich(ex, header);
     }
 }
Exemplo n.º 19
0
 public void Write(
     MutagenWriter writer,
     ITranslatedStringGetter item,
     RecordType header,
     StringBinaryType binaryType,
     StringsSource source)
 {
     try
     {
         using (HeaderExport.Header(writer, header, ObjectType.Subrecord))
         {
             Write(
                 writer,
                 item,
                 binaryType,
                 source);
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Factory(ex, header);
     }
 }
 public void WriteNullable(
     MutagenWriter writer,
     T?item,
     RecordType header,
     Action <MutagenWriter, T>?write = null)
 {
     if (!item.HasValue)
     {
         return;
     }
     write ??= this.Write;
     try
     {
         using (HeaderExport.Header(writer, header, ObjectType.Subrecord))
         {
             write(writer, item.Value);
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Enrich(ex, header);
     }
 }
Exemplo n.º 21
0
 public static void Write(
     this PrimitiveBinaryTranslation <float, MutagenFrame, MutagenWriter> transl,
     MutagenWriter writer,
     float?item,
     RecordType header,
     FloatIntegerType integerType,
     double multiplier)
 {
     try
     {
         if (item == null)
         {
             return;
         }
         using (HeaderExport.Subrecord(writer, header))
         {
             FloatBinaryTranslation <MutagenFrame, MutagenWriter> .Instance.Write(writer, item, integerType, multiplier);
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Factory(ex, header);
     }
 }
Exemplo n.º 22
0
 public void Write(
     MutagenWriter writer,
     ReadOnlyMemorySlice <byte>?item,
     RecordType header,
     RecordType overflowRecord)
 {
     try
     {
         if (!item.HasValue)
         {
             return;
         }
         if (item.Value.Length > ushort.MaxValue)
         {
             using (HeaderExport.Subrecord(writer, overflowRecord))
             {
                 writer.Write(item.Value.Length);
             }
             using (HeaderExport.Subrecord(writer, header))
             {
             }
             Write(writer, item.Value.Span);
         }
         else
         {
             using (HeaderExport.Subrecord(writer, header))
             {
                 Write(writer, item.Value.Span);
             }
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Enrich(ex, header);
     }
 }
Exemplo n.º 23
0
 public void WriteNullable(
     MutagenWriter writer,
     string?item,
     RecordType header,
     StringBinaryType binaryType = StringBinaryType.NullTerminate)
 {
     if (item == null)
     {
         return;
     }
     try
     {
         using (HeaderExport.Header(writer, header, ObjectType.Subrecord))
         {
             writer.Write(
                 item,
                 binaryType: binaryType);
         }
     }
     catch (Exception ex)
     {
         throw SubrecordException.Enrich(ex, header);
     }
 }