Пример #1
0
    void FB_Serialize(FlatBufferBuilder fbb)
    {
        fbb.Clear();
        for (int p = 0; p < 10; ++p)
        {
            for (int n = 0; n < 10; ++n)
            {
                StringOffset phoneNumberOffset = fbb.CreateString(phoneNumber);
                PhoneNumber.StartPhoneNumber(fbb);
                PhoneNumber.AddNumber(fbb, phoneNumberOffset);
                PhoneNumber.AddType(fbb, (PhoneType)(n % 3));
                mPhoneArray[n] = PhoneNumber.EndPhoneNumber(fbb);
            }

            StringOffset nameOffset       = fbb.CreateString(personName);
            StringOffset emailOffset      = fbb.CreateString(email);
            VectorOffset phoneArrayOffset = Person.CreatePhonesVector(fbb, mPhoneArray);

            Person.StartPerson(fbb);
            Person.AddName(fbb, nameOffset);
            Person.AddId(fbb, p);
            Person.AddEmail(fbb, emailOffset);
            Person.AddPhones(fbb, phoneArrayOffset);
            mPersonArray[p] = Person.EndPerson(fbb);
        }

        VectorOffset peopleArrayOffset = AddressBook.CreatePeopleVector(fbb, mPersonArray);

        AddressBook.StartAddressBook(fbb);
        AddressBook.AddPeople(fbb, peopleArrayOffset);
        Offset <AddressBook> offset = AddressBook.EndAddressBook(fbb);

        fbb.Finish(offset.Value);
    }
Пример #2
0
    static void FB_Serialize(FlatBufferBuilder fbb)
    {
        fbb.Clear();
        var phoneArray  = OffsetArrayPool.Alloc <PhoneNumber>(10);
        var personArray = OffsetArrayPool.Alloc <Person>(10);

        for (int p = 0; p < 10; ++p)
        {
            phoneArray.Clear();
            for (int n = 0; n < 10; ++n)
            {
                StringOffset phoneNumberOffset = fbb.CreateString((p * 100 + n).ToString());
                PhoneNumber.StartPhoneNumber(fbb);
                PhoneNumber.AddNumber(fbb, phoneNumberOffset);
                PhoneNumber.AddType(fbb, (PhoneType)(n % 3));
                phoneArray.offsets[phoneArray.position++] = PhoneNumber.EndPhoneNumber(fbb);
            }

            StringOffset nameOffset  = fbb.CreateString(personName + p);
            StringOffset emailOffset = fbb.CreateString(string.Format("{0}{1}@gmail.com", personName, p));
            Person.StartPhonesVector(fbb, phoneArray.position);
            VectorOffset phoneArrayOffset = Helpers.SetVector(fbb, phoneArray);

            Person.StartPerson(fbb);
            Person.AddName(fbb, nameOffset);
            Person.AddId(fbb, p);
            Person.AddEmail(fbb, emailOffset);
            Person.AddPhones(fbb, phoneArrayOffset);
            personArray.offsets[personArray.position++] = Person.EndPerson(fbb);
        }

        AddressBook.StartPeopleVector(fbb, personArray.position);
        VectorOffset peopleArrayOffset = Helpers.SetVector(fbb, personArray);

        AddressBook.StartAddressBook(fbb);
        AddressBook.AddPeople(fbb, peopleArrayOffset);
        Offset <AddressBook> offset = AddressBook.EndAddressBook(fbb);

        fbb.Finish(offset.Value);

        OffsetArrayPool.Dealloc(ref phoneArray);
        OffsetArrayPool.Dealloc(ref personArray);
    }