public virtual string Parse(
            MutagenFrame frame,
            bool parseWhole = true,
            StringBinaryType stringBinaryType = StringBinaryType.NullTerminate)
        {
            switch (stringBinaryType)
            {
            case StringBinaryType.Plain:
            case StringBinaryType.NullTerminate:
                if (parseWhole)
                {
                    return(BinaryStringUtility.ProcessWholeToZString(frame.ReadMemory(checked ((int)frame.Remaining))));
                }
                else
                {
                    return(BinaryStringUtility.ParseUnknownLengthString(frame.Reader));
                }

            case StringBinaryType.PrependLength:
            {
                var len = frame.ReadInt32();
                return(BinaryStringUtility.ToZString(frame.ReadMemory(len)));
            }

            case StringBinaryType.PrependLengthUShort:
            {
                var len = frame.ReadInt16();
                return(BinaryStringUtility.ToZString(frame.ReadMemory(len)));
            }

            default:
                throw new NotImplementedException();
            }
        }
 public void WriteNullable(
     MutagenWriter writer,
     ITranslatedStringGetter?item,
     RecordType header,
     StringBinaryType binaryType,
     StringsSource source)
 {
     if (item == null)
     {
         return;
     }
     using (HeaderExport.Header(writer, header, ObjectType.Subrecord))
     {
         if (writer.MetaData.StringsWriter == null)
         {
             writer.Write(
                 item.String,
                 binaryType: binaryType);
         }
         else
         {
             writer.Write(writer.MetaData.StringsWriter.Register(item, source));
         }
     }
 }
示例#3
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);
     }
 }
 public void Write(
     MutagenWriter writer,
     string item,
     StringBinaryType binaryType)
 {
     writer.Write(item, binaryType);
 }
示例#5
0
 public bool Parse(
     MutagenFrame frame,
     bool parseWhole,
     out string item,
     StringBinaryType binaryType = StringBinaryType.NullTerminate)
 {
     item = Parse(frame, parseWhole: parseWhole, stringBinaryType: binaryType);
     return(true);
 }
示例#6
0
 public bool Parse(
     MutagenFrame frame,
     StringsSource source,
     StringBinaryType binaryType,
     out TranslatedString item,
     bool parseWhole = true)
 {
     item = Parse(frame, source, binaryType, parseWhole);
     return(true);
 }
 public void Write(
     MutagenWriter writer,
     string item,
     RecordType header,
     StringBinaryType binaryType = StringBinaryType.NullTerminate)
 {
     using (HeaderExport.Header(writer, header, ObjectType.Subrecord))
     {
         writer.Write(
             item,
             binaryType: binaryType);
     }
 }
 public void WriteNullable(
     MutagenWriter writer,
     string?item,
     StringBinaryType binaryType = StringBinaryType.NullTerminate)
 {
     if (item == null)
     {
         return;
     }
     writer.Write(
         item,
         binaryType: binaryType);
 }
 public void Write(
     MutagenWriter writer,
     ITranslatedStringGetter item,
     RecordType header,
     StringBinaryType binaryType,
     StringsSource source)
 {
     using (HeaderExport.Header(writer, header, ObjectType.Subrecord))
     {
         Write(
             writer,
             item,
             binaryType,
             source);
     }
 }
示例#10
0
 public void Write(
     MutagenWriter writer,
     ITranslatedStringGetter item,
     StringBinaryType binaryType,
     StringsSource source)
 {
     if (writer.MetaData.StringsWriter == null)
     {
         writer.Write(
             item.String,
             binaryType: binaryType);
     }
     else
     {
         writer.Write(writer.MetaData.StringsWriter.Register(item, source));
     }
 }
示例#11
0
 public void WriteNullable(
     MutagenWriter writer,
     string?item,
     RecordType header,
     StringBinaryType binaryType = StringBinaryType.NullTerminate)
 {
     if (item == null)
     {
         return;
     }
     using (HeaderExport.Header(writer, header, ObjectType.Subrecord))
     {
         writer.Write(
             item,
             binaryType: binaryType);
     }
 }
示例#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);
     }
 }
示例#13
0
 public void WriteNullable(
     MutagenWriter writer,
     ITranslatedStringGetter?item,
     StringBinaryType binaryType,
     StringsSource source)
 {
     if (item == null)
     {
         return;
     }
     if (writer.MetaData.StringsWriter == null)
     {
         writer.Write(
             item.String ?? string.Empty,
             binaryType: binaryType);
     }
     else
     {
         writer.Write(writer.MetaData.StringsWriter.Register(item, source));
     }
 }
示例#14
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);
     }
 }
示例#15
0
 public TranslatedString Parse(
     MutagenFrame reader,
     StringsSource source,
     StringBinaryType stringBinaryType,
     bool parseWhole = true)
 {
     if (reader.MetaData.StringsLookup != null)
     {
         if (reader.Remaining != 4)
         {
             throw new ArgumentException($"String in Strings File format had unexpected length: {reader.Remaining} != 4");
         }
         uint key = reader.ReadUInt32();
         if (key == 0)
         {
             return(new TranslatedString(directString: null));
         }
         return(reader.MetaData.StringsLookup.CreateString(source, key));
     }
     else
     {
         return(Parse(reader, parseWhole, stringBinaryType));
     }
 }
示例#16
0
 public virtual TranslatedString Parse(
     MutagenFrame frame,
     StringsSource source,
     StringBinaryType stringBinaryType,
     bool parseWhole = true)
 {
     if (frame.MetaData.StringsLookup != null)
     {
         if (frame.Remaining != 4)
         {
             throw new ArgumentException($"String in Strings File format had unexpected length: {frame.Remaining} != 4");
         }
         uint key = frame.ReadUInt32();
         if (key == 0)
         {
             return(string.Empty);
         }
         return(frame.MetaData.StringsLookup.CreateString(source, key));
     }
     else
     {
         return(Parse(frame, parseWhole, stringBinaryType));
     }
 }
示例#17
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);
     }
 }
示例#18
0
 public override async Task Load(XElement node, bool requireName = true)
 {
     this.BinaryType = node.GetAttribute <StringBinaryType>("binaryType", defaultVal: StringBinaryType.NullTerminate);
     this.Translated = node.GetAttribute <StringsSource?>("translated", defaultVal: null);
     await base.Load(node, requireName);
 }