Пример #1
0
        public static void WriteField(Stream s, Tools.Field f)
        {
            if (f.type == 0)
            {
                s.WriteByte(0);
                return;
            }
            s.WriteByte(f.type);
            Tools.WriteNullString(s, f.fieldname);
            Tools.BinaryWriter7Bit w = new Tools.BinaryWriter7Bit(s);
            switch (f.type)
            {
            case 0x01:
                List <Tools.Entry> list = (List <Tools.Entry>)f.data;
                MemoryStream       m    = new MemoryStream();
                foreach (Tools.Entry e in list)
                {
                    WriteEntry(m, e);
                }
                m.WriteByte(0);
                w.Write7BitEncodedInt((int)m.Length);
                s.Write(m.ToArray(), 0, (int)m.Length);
                break;

            case 0x07:
                w.Write7BitEncodedInt((int)((string)f.data).Length + 1);
                Tools.WriteNullString(s, (string)f.data);
                break;

            case 0x06:
                s.WriteByte(((bool)f.data) ? (byte)1 : (byte)0);
                break;

            case 0x08:
            case 0x09:
            case 0xf:
            case 0x10:
                s.Write((byte[])f.data, 0, (int)((byte[])f.data).Length);
                break;

            case 0x02:
            case 0x13:
                w.Write7BitEncodedInt((int)((byte[])f.data).Length);
                s.Write((byte[])f.data, 0, (int)((byte[])f.data).Length);
                break;
            }
            if (f.fields != null)
            {
                foreach (Field subfield in f.fields)
                {
                    WriteField(s, subfield);
                }
            }
        }
Пример #2
0
        public static void WriteEntry(Stream s, Tools.Entry e)
        {
            Tools.BinaryWriter7Bit w = new Tools.BinaryWriter7Bit(s);
            switch (e.type)
            {
            case 0x82:
                s.WriteByte(0x82);
                MemoryStream m = new MemoryStream();
                foreach (Tools.Field f in e.fields)
                {
                    WriteField(m, f);
                }
                w.Write7BitEncodedInt((int)m.Length);
                s.Write(m.ToArray(), 0, (int)m.Length);
                break;

            case 0x87:
                w.Write7BitEncodedInt(e.type87name.Length + 1);
                Tools.WriteNullString(s, e.type87name);
                break;
            }
        }