public static Blaze.TdfStruct CreateStructStub(List <Tdf> tdfs, bool has2 = false) { Blaze.TdfStruct res = new TdfStruct(); res.Values = tdfs; res.startswith2 = has2; return(res); }
public static TdfStruct Create(string Label, List <Tdf> list, bool start2 = false) { TdfStruct res = new TdfStruct(); res.startswith2 = start2; res.Set(Label, 3); res.Values = list; return(res); }
public static TdfStruct ReadTdfStruct(Tdf head, Stream s) { TdfStruct res = new TdfStruct(); res.Label = head.Label; res.Tag = head.Tag; res.Type = head.Type; bool has2 = false; res.Values = ReadStruct(s, out has2); res.startswith2 = has2; return(res); }
public static TdfDoubleList ReadTdfDoubleList(Tdf head, Stream s) { TdfDoubleList res = new TdfDoubleList(); res.Label = head.Label; res.Tag = head.Tag; res.Type = head.Type; res.SubType1 = (byte)s.ReadByte(); res.SubType2 = (byte)s.ReadByte(); res.Count = (int)DecompressInteger(s); for (int i = 0; i < res.Count; i++) { switch (res.SubType1) { case 0: if (res.List1 == null) { res.List1 = new List <long>(); } List <long> l1 = (List <long>)res.List1; l1.Add(DecompressInteger(s)); res.List1 = l1; break; case 1: if (res.List1 == null) { res.List1 = new List <string>(); } List <string> l2 = (List <string>)res.List1; l2.Add(ReadString(s)); res.List1 = l2; break; case 3: if (res.List1 == null) { res.List1 = new List <TdfStruct>(); } List <TdfStruct> l3 = (List <TdfStruct>)res.List1; Blaze.TdfStruct tmp = new TdfStruct(); tmp.startswith2 = false; tmp.Values = ReadStruct(s, out tmp.startswith2); l3.Add(tmp); res.List1 = l3; break; case 0xA: if (res.List1 == null) { res.List1 = new List <float>(); } List <float> lf3 = (List <float>)res.List1; lf3.Add(ReadFloat(s)); res.List1 = lf3; break; default: throw new Exception("Unknown Tdf Type in Double List: " + res.SubType1); } switch (res.SubType2) { case 0: if (res.List2 == null) { res.List2 = new List <long>(); } List <long> l1 = (List <long>)res.List2; l1.Add(DecompressInteger(s)); res.List2 = l1; break; case 1: if (res.List2 == null) { res.List2 = new List <string>(); } List <string> l2 = (List <string>)res.List2; l2.Add(ReadString(s)); res.List2 = l2; break; case 3: if (res.List2 == null) { res.List2 = new List <TdfStruct>(); } List <TdfStruct> l3 = (List <TdfStruct>)res.List2; Blaze.TdfStruct tmp = new TdfStruct(); tmp.startswith2 = false; tmp.Values = ReadStruct(s, out tmp.startswith2); l3.Add(tmp); res.List2 = l3; break; case 0xA: if (res.List2 == null) { res.List2 = new List <float>(); } List <float> lf3 = (List <float>)res.List2; lf3.Add(ReadFloat(s)); res.List2 = lf3; break; default: throw new Exception("Unknown Tdf Type in Double List: " + res.SubType2); } } return(res); }
public static TdfList ReadTdfList(Tdf head, Stream s) { TdfList res = new TdfList(); res.Label = head.Label; res.Tag = head.Tag; res.Type = head.Type; res.SubType = (byte)s.ReadByte(); res.Count = (int)DecompressInteger(s); for (int i = 0; i < res.Count; i++) { switch (res.SubType) { case 0: if (res.List == null) { res.List = new List <long>(); } List <long> l1 = (List <long>)res.List; l1.Add(DecompressInteger(s)); res.List = l1; break; case 1: if (res.List == null) { res.List = new List <string>(); } List <string> l2 = (List <string>)res.List; l2.Add(ReadString(s)); res.List = l2; break; case 3: if (res.List == null) { res.List = new List <TdfStruct>(); } List <TdfStruct> l3 = (List <TdfStruct>)res.List; Blaze.TdfStruct tmp = new TdfStruct(); tmp.startswith2 = false; tmp.Values = ReadStruct(s, out tmp.startswith2); l3.Add(tmp); res.List = l3; break; case 9: if (res.List == null) { res.List = new List <TrippleVal>(); } List <TrippleVal> l4 = (List <TrippleVal>)res.List; l4.Add(ReadTrippleVal(s)); res.List = l4; break; default: throw new Exception("Unknown Tdf Type in List: " + res.Type); } } return(res); }
public static void WriteTdf(Tdf tdf, Stream s) { s.WriteByte((byte)(tdf.Tag >> 24)); s.WriteByte((byte)(tdf.Tag >> 16)); s.WriteByte((byte)(tdf.Tag >> 8)); s.WriteByte(tdf.Type); switch (tdf.Type) { case 0: TdfInteger ti = (TdfInteger)tdf; CompressInteger(ti.Value, s); break; case 1: TdfString ts = (TdfString)tdf; WriteString(ts.Value, s); break; case 2: TdfBlob tb = (TdfBlob)tdf; CompressInteger(tb.Data.Length, s); for (int i = 0; i < tb.Data.Length; i++) { s.WriteByte(tb.Data[i]); } break; case 3: TdfStruct tst = (TdfStruct)tdf; if (tst.startswith2) { s.WriteByte(2); } foreach (Tdf ttdf in tst.Values) { WriteTdf(ttdf, s); } s.WriteByte(0); break; case 4: WriteTdfList((TdfList)tdf, s); break; case 5: WriteTdfDoubleList((TdfDoubleList)tdf, s); break; case 6: TdfUnion tu = (TdfUnion)tdf; s.WriteByte(tu.UnionType); if (tu.UnionType != 0x7F) { WriteTdf(tu.UnionContent, s); } break; case 7: TdfIntegerList til = (TdfIntegerList)tdf; CompressInteger(til.Count, s); if (til.Count != 0) { foreach (long l in til.List) { CompressInteger(l, s); } } break; case 8: WriteDoubleValue(((TdfDoubleVal)tdf).Value, s); break; case 9: WriteTrippleValue(((TdfTrippleVal)tdf).Value, s); break; case 0xA: TdfFloat tf = (TdfFloat)tdf; WriteFloat(s, tf.Value); break; } }