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 TranslatedString Parse( ReadOnlyMemorySlice <byte> data, StringsSource source, IStringsFolderLookup?lookup) { if (lookup != null) { if (data.Length != 4) { throw new ArgumentException($"String in Strings File format had unexpected length: {data.Length} != 4"); } uint key = BinaryPrimitives.ReadUInt32LittleEndian(data); if (key == 0) { return(string.Empty); } return(lookup.CreateString(source, key)); } else { return(BinaryStringUtility.ProcessWholeToZString(data)); } }
/// <summary> /// Interprets a subrecord's content as a string. /// </summary> /// <param name="frame">Frame to read from</param> /// <returns>Subrecord's content as a string, null trimmed if applicable</returns> public static string AsString(this SubrecordFrame frame) { return(BinaryStringUtility.ProcessWholeToZString(frame.Content)); }
/// <summary> /// Reads a ZString from the binary stream /// </summary> /// <param name="stream">Stream to read from</param> /// <param name="length">Length of the zstring</param> /// <returns>ZString of desired length</returns> public static string ReadZString(this IBinaryReadStream stream, int length) { return(BinaryStringUtility.ToZString(stream.ReadMemory(length))); }