/// <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); }
public override void handleRequest(CatRankSchema.SearchResultList.Reader request, CatRankSchema.SearchResultList.Builder response) { System.Collections.Generic.List <CatRank.ScoredResult> scoredResults = new System.Collections.Generic.List <CatRank.ScoredResult>(); foreach (CatRankSchema.SearchResult.Reader result in request.GetResults()) { double score = result.GetScore(); if (result.GetSnippet().ToString().Contains(" cat ")) { score *= 10000.0; } if (result.GetSnippet().ToString().Contains(" dog ")) { score /= 10000.0; } scoredResults.Add(new CatRank.ScoredResult(score, result)); } scoredResults.Sort(); StructList.Builder <CatRankSchema.SearchResult.Builder> list = response.InitResults(scoredResults.Count); for (int i = 0; i < list.Length; ++i) { CatRankSchema.SearchResult.Builder item = list.Get(i); CatRank.ScoredResult result = scoredResults[i]; item.SetScore(result.score); item.SetUrl(result.result.GetUrl()); item.SetSnippet(result.result.GetSnippet()); } }
public sealed override ulong setupRequest(Common.FastRand rng, CarSalesSchema.ParkingLot.Builder request) { ulong result = 0; StructList.Builder <CarSalesSchema.Car.Builder> cars = request.InitCars(rng.nextLessThan(200)); for (int i = 0; i < cars.Length; ++i) { CarSalesSchema.Car.Builder car = cars.Get(i); randomCar(rng, car); result += carValue(car.AsReader()); } return(result); }
public override int setupRequest(Common.FastRand rng, CatRankSchema.SearchResultList.Builder request) { int count = rng.nextLessThan(1000); int goodCount = 0; StructList.Builder <CatRankSchema.SearchResult.Builder> list = request.InitResults(count); for (int i = 0; i < list.Length; ++i) { CatRankSchema.SearchResult.Builder result = list.Get(i); result.SetScore(1000.0 - (double)i); int urlSize = rng.nextLessThan(100); int urlPrefixLength = URL_PREFIX.Length; Text.Builder url = result.InitUrl(urlSize + urlPrefixLength); java.nio.ByteBuffer bytes = url.asByteBuffer(); bytes.put(URL_PREFIX.asByteBuffer()); for (int j = 0; j < urlSize; j++) { bytes.put(unchecked ((byte)(97 + rng.nextLessThan(26)))); } bool isCat = rng.nextLessThan(8) == 0; bool isDog = rng.nextLessThan(8) == 0; if (isCat && !isDog) { goodCount += 1; } System.Text.StringBuilder snippet = new System.Text.StringBuilder(" "); int prefix = rng.nextLessThan(20); for (int j = 0; j < prefix; ++j) { snippet.Append(Common.WORDS[rng.nextLessThan(Common.WORDS.Length)]); } if (isCat) { snippet.Append("cat "); } if (isDog) { snippet.Append("dog "); } int suffix = rng.nextLessThan(20); for (int j = 0; j < suffix; ++j) { snippet.Append(Common.WORDS[rng.nextLessThan(Common.WORDS.Length)]); } result.SetSnippet(snippet.ToString()); } return(goodCount); }