/// <summary> /// Creates a new <see cref="ABSaveIdentifiedType"/> with all the information. /// </summary> public unsafe ABSaveIdentifiedType(short key, string value, Type type) { // Set the key/value. Key = key; Value = value; // Set the type. Type = type; // Create the "WrittenKey". var bytes = ABSaveUtils.ConvertNumberToByteArray(key, TypeCode.Int16); WrittenKey = new char[2]; // Add the bytes to the "WrittenKey" as characters. fixed(byte *fixedBytePointer = bytes) fixed(char *fixedCharPointer = WrittenKey) { // Create non-fixed pointers for each array. var charPointer = fixedCharPointer; var bytePointer = fixedBytePointer; // And, finally, copy them. for (int i = 0; i < bytes.Length; i++) { *(charPointer++) = (char)*(bytePointer++); } } }
public static string WriteDotAndInt32(int num, bool writeToSB, StringBuilder sb) { string ret = ""; ret += WriteCharacter('.', writeToSB, sb); ret += WriteByteArray(ABSaveUtils.ConvertNumberToByteArray(num, TypeCode.Int32), writeToSB, sb); return(ret); }
/// <summary> /// Writes a number, and either returns the result or writes it to a StringBuilder. /// </summary> /// <param name="str">The number to write.</param> /// <param name="useSB">Whether we are writing to a StringBuilder or not.</param> /// <param name="numType">The type that the number is.</param> /// <param name="sb">The StringBuilder to write to - if we're writing to one at all.</param> /// <returns>If <paramref name="useSB"/> is false, this method will return the result as a string.</returns> public static string WriteNumerical(dynamic num, TypeCode numType, bool writeLengthBytes = true, bool useSB = false, StringBuilder sb = null) { // NOTE: WE DON'T NEED THE "Next Instruction" CHARACTER BECAUSE \A AND \B ARE ACTUALLY ESCAPED! // Create a variable to store what we'll return. var ret = ""; // Write the number as a byte array. byte[] numberBytes = ABSaveUtils.ConvertNumberToByteArray(num, numType); // Next, work out how many of those bytes actually contain something (we don't want to waste space on trailing "\0"s) numberBytes = RemoveTrailingZeroBytesInByteArray(numberBytes); // Then, if we're going to write the "length bytes", then do it. var lengthBytes = WriteNumericalLengthBytes(writeLengthBytes, numberBytes); // Write out those "length bytes" now. ret += WriteByteArray(lengthBytes, useSB, sb); // Write the actual number - as a byte array. ret += WriteByteArray(numberBytes, useSB, sb); // Now, "ret" would be empty if we were using a StringBuilder, however, if we weren't... It will have the correct string in it so return it. return(ret); }