Exemplo n.º 1
0
        public static void WriteTdfList(TdfList tdf, Stream s)
        {
            s.WriteByte(tdf.SubType);
            CompressInteger(tdf.Count, s);
            for (int i = 0; i < tdf.Count; i++)
            {
                switch (tdf.SubType)
                {
                case 0:
                    CompressInteger(((List <long>)tdf.List)[i], s);
                    break;

                case 1:
                    WriteString(((List <string>)tdf.List)[i], s);
                    break;

                case 3:
                    Blaze.TdfStruct str = ((List <Blaze.TdfStruct>)tdf.List)[i];
                    if (str.startswith2)
                    {
                        s.WriteByte(2);
                    }
                    foreach (Tdf ttdf in str.Values)
                    {
                        WriteTdf(ttdf, s);
                    }
                    s.WriteByte(0);
                    break;

                case 9:
                    WriteTrippleValue(((List <TrippleVal>)tdf.List)[i], s);
                    break;
                }
            }
        }
Exemplo n.º 2
0
            public static TdfList Create(string Label, byte subtype, int count, object list)
            {
                TdfList res = new TdfList();

                res.Set(Label, 4);
                res.SubType = subtype;
                res.Count   = count;
                res.List    = list;
                return(res);
            }
Exemplo n.º 3
0
        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);
        }