/// <summary> /// Reads the TAG file schema dictionary from the TAG file data using the TAG file reader /// </summary> /// <returns></returns> public bool Read(NybbleStream reader) { string fieldName; while ((fieldName = reader.ReadANSIString()) != string.Empty) { uint tempFieldType = reader.ReadUnSignedIntegerValue(1); // If field type is 15, then read an extra var int to determine extended data type if (tempFieldType == 15) { if (!reader.ReadVarInt(out short tempFieldTypeExtended)) { return(false); } tempFieldType += (uint)tempFieldTypeExtended; } var fieldType = (TAGDataType)tempFieldType; if (!reader.ReadVarInt(out var id)) { return(false); } Entries.Add(id, new TAGDictionaryItem(fieldName, fieldType, id)); } return(true); }
public void Write(NybbleStream stream) { // Write out each tagfile data entry to stream. First one must be a timestamp foreach (TagData td in Entries) { stream.WriteVarSizeUnsignedInt((uint)td.DictID); // write dictionary id first td.Write(ref stream); } }
/// <summary> /// Write stream of nybbles /// </summary> /// <param name="stream"></param> public void Write(NybbleStream stream) { foreach (KeyValuePair <short, TAGDictionaryItem> kvp in Entries) { TAGDictionaryItem theElement = kvp.Value; byte[] bytes = Encoding.ASCII.GetBytes(theElement.Name); for (int i = 0; i < bytes.Length; i++) { // bytes[i]; stream.WriteFixedSizeUnsignedInt((uint)bytes[i], 2); } stream.WriteFixedSizeUnsignedInt(0, 2); // end of name marker stream.WriteNybble((byte)(theElement.Type)); stream.WriteVarSizeUnsignedInt((uint)theElement.ID); } stream.WriteFixedSizeUnsignedInt(0, 2); // end of dictionary marker }