Example #1
0
        public static void WriteEntry(Stream s, Entry e)
        {
            Helpers.BinaryWriter7Bit w = new Helpers.BinaryWriter7Bit(s);
            switch (e.type)
            {
            case 0x82:
                s.WriteByte(0x82);
                MemoryStream m = new MemoryStream();
                foreach (Field f in e.fields)
                {
                    WriteField(m, f);
                }
                m.WriteByte(0);
                w.Write7BitEncodedInt((int)m.Length);
                s.Write(m.ToArray(), 0, (int)m.Length);
                break;

            case 0x87:
                s.WriteByte(0x87);
                w.Write7BitEncodedInt(e.type87name.Length + 1);
                Helpers.WriteNullString(s, e.type87name);
                break;
            }
        }
Example #2
0
 public static void WriteField(Stream s, Field f)
 {
     if (f.type == 0)
     {
         s.WriteByte(0);
         return;
     }
     s.WriteByte(f.type);
     Helpers.WriteNullString(s, f.fieldname);
     Helpers.BinaryWriter7Bit w = new Helpers.BinaryWriter7Bit(s);
     MemoryStream m;
     switch (f.type)
     {
         case 0x01:
             List<Entry> listb = (List<Entry>)f.data;
             m = new MemoryStream();
             foreach (Entry e in listb)
                 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);
             Helpers.WriteNullString(s, (string)f.data);
             break;
         case 0x06:
             s.WriteByte(((bool)f.data) ? (byte)1 : (byte)0);
             break;
         case 0x08:
             s.Write((byte[])f.data, 0, 4);
             break;
         case 0x09:
             s.Write((byte[])f.data, 0, 8);
             break;
         case 0xf:
         case 0x10:
             s.Write((byte[])f.data, 0, (int)((byte[])f.data).Length);
             break;
         case 0x02:
             List<Field> listf = (List<Field>)f.data;
             m = new MemoryStream();
             foreach (Field e in listf)
                 WriteField(m, e);
             m.WriteByte(0);
             w.Write7BitEncodedInt((int)m.Length);
             s.Write(m.ToArray(), 0, (int)m.Length);
             break;
         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);
 }
Example #3
0
 public static void WriteEntry(Stream s, Entry e)
 {
     Helpers.BinaryWriter7Bit w = new Helpers.BinaryWriter7Bit(s);
     switch (e.type)
     {
         case 0x82:
             s.WriteByte(0x82);
             MemoryStream m = new MemoryStream();
             foreach (Field f in e.fields)
                 WriteField(m, f);
             m.WriteByte(0);
             w.Write7BitEncodedInt((int)m.Length);
             s.Write(m.ToArray(), 0, (int)m.Length);
             break;
         case 0x87:
             s.WriteByte(0x87);
             w.Write7BitEncodedInt(e.type87name.Length + 1);
             Helpers.WriteNullString(s, e.type87name);
             break;
     }
 }
Example #4
0
        public static void WriteField(Stream s, Field f)
        {
            if (f.type == 0)
            {
                s.WriteByte(0);
                return;
            }
            s.WriteByte(f.type);
            Helpers.WriteNullString(s, f.fieldname);
            Helpers.BinaryWriter7Bit w = new Helpers.BinaryWriter7Bit(s);
            MemoryStream             m;

            switch (f.type)
            {
            case 0x01:
                List <Entry> listb = (List <Entry>)f.data;
                m = new MemoryStream();
                foreach (Entry e in listb)
                {
                    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);
                Helpers.WriteNullString(s, (string)f.data);
                break;

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

            case 0x08:
                s.Write((byte[])f.data, 0, 4);
                break;

            case 0x09:
                s.Write((byte[])f.data, 0, 8);
                break;

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

            case 0x02:
                List <Field> listf = (List <Field>)f.data;
                m = new MemoryStream();
                foreach (Field e in listf)
                {
                    WriteField(m, e);
                }
                m.WriteByte(0);
                w.Write7BitEncodedInt((int)m.Length);
                s.Write(m.ToArray(), 0, (int)m.Length);
                break;

            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);
                }
            }
        }