Exemplo n.º 1
0
        /// <exception cref="System.IO.IOException"/>
        public static void writeAddressBook()
        {
            MessageBuilder message = new MessageBuilder();

            Addressbook.AddressBook.Builder addressbook            = message.InitRoot(Addressbook.AddressBook.SingleFactory);
            StructList.Builder <Addressbook.Person.Builder> people = addressbook.InitPeople(2);
            Addressbook.Person.Builder alice = people[0];
            alice.SetId(123);
            alice.SetName("Alice");
            alice.SetEmail("*****@*****.**");
            StructList.Builder <Addressbook.Person.PhoneNumber.Builder> alicePhones = alice.InitPhones(1);
            alicePhones[0].SetNumber("555-1212");
            alicePhones[0].SetType(Addressbook.Person.PhoneNumber.Type.Mobile);
            alice.GetEmployment().SetSchool("MIT");
            Addressbook.Person.Builder bob = people[1];
            bob.SetId(456);
            bob.SetName("Bob");
            bob.SetEmail("*****@*****.**");
            StructList.Builder <Addressbook.Person.PhoneNumber.Builder> bobPhones = bob.InitPhones(2);
            bobPhones[0].SetNumber("555-4567");
            bobPhones[0].SetType(Addressbook.Person.PhoneNumber.Type.Home);
            bobPhones[1].SetNumber("555-7654");
            bobPhones[1].SetType(Addressbook.Person.PhoneNumber.Type.Work);
            bob.GetEmployment().SetUnemployed(Void.VOID);
            SerializePacked.WriteToUnbuffered((new FileDescriptor(Console.OpenStandardOutput())), message);
        }
Exemplo n.º 2
0
        /// <exception cref="System.IO.IOException"/>
        public static void printAddressBook()
        {
            MessageReader message = SerializePacked.ReadFromUnbuffered(new FileDescriptor(Console.OpenStandardInput()));

            Addressbook.AddressBook.Reader addressbook = message.GetRoot(Addressbook.AddressBook.SingleFactory);
            foreach (Addressbook.Person.Reader person in addressbook.GetPeople())
            {
                Console.Out.WriteLine(person.GetName() + ": " + person.GetEmail());
                foreach (Addressbook.Person.PhoneNumber.Reader phone in person.GetPhones())
                {
                    string typeName = "UNKNOWN";
                    switch (phone.GetType())
                    {
                    case Addressbook.Person.PhoneNumber.Type.Mobile:
                        typeName = "mobile";
                        break;

                    case Addressbook.Person.PhoneNumber.Type.Home:
                        typeName = "home";
                        break;

                    case Addressbook.Person.PhoneNumber.Type.Work:
                        typeName = "work";
                        break;
                    }
                    Console.Out.WriteLine("  " + typeName + " phone: " + phone.GetNumber());
                }
                Addressbook.Person.Employment.Reader employment = person.GetEmployment();
                switch (employment.Which)
                {
                case Addressbook.Person.Employment.Which.Unemployed:
                    System.Console.Out.WriteLine("  unemployed");
                    break;

                case Addressbook.Person.Employment.Which.Employer:
                    System.Console.Out.WriteLine("  employer: " + employment.GetEmployer());
                    break;

                case Addressbook.Person.Employment.Which.School:
                    System.Console.Out.WriteLine("  student at: " + employment.GetSchool());
                    break;

                case Addressbook.Person.Employment.Which.SelfEmployed:
                    System.Console.Out.WriteLine("  self-employed");
                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 3
0
 /// <exception cref="System.IO.IOException"/>
 public override MessageReader newBufferedReader(BufferedInputStream inputStream)
 {
     return(SerializePacked.Read(inputStream));
 }
Exemplo n.º 4
0
 /// <exception cref="System.IO.IOException"/>
 public override void writeBuffered(BufferedOutputStream writer, MessageBuilder message)
 {
     SerializePacked.Write(writer, message);
     writer.Flush();
 }