void phone_add_diphones (void) /*------------------------* * DESCRIPTION - figure out what the word begin/end diphones of intrest are * and add them to the phone set. */ { int32 phone_cnt = phone_count(); int32 pid; int32 ret; int32 new_phone_id = phone_cnt; char tp[64]; char ci[32], lc[64], rc[64], pc[64]; for (pid = 0; pid < phone_cnt; pid++) { strcpy (tp, phone_from_id (pid)); ret = parse_triphone (tp, ci, lc, rc, pc); if (ret == 4) { switch (pc[0]) { case 'b': sprintf (tp, "%s(%%s,%s)b", ci, rc); if (phone_to_id (tp, FALSE) == NO_PHONE) { add_phone (tp, new_phone_id, phone_to_id(ci, TRUE), PT_DIPHONE, 1); new_phone_id++; } break; case 'e': sprintf (tp, "%s(%s,%%s)e", ci, lc); if (phone_to_id (tp, FALSE) == NO_PHONE) { add_phone (tp, new_phone_id, phone_to_id(ci, TRUE), PT_DIPHONE, 1); new_phone_id++; } break; case 's': sprintf (tp, "%s(%%s,%%s)s", ci); if (phone_to_id (tp, FALSE) == NO_PHONE) { add_phone (tp, new_phone_id, phone_to_id(ci, TRUE), PT_DIPHONE_S, 1); new_phone_id++; } break; case '\0': break; default: E_FATAL("Unknown position context in %s == '%c'\n", tp, pc[0]); } } } /* * Remake the phone map to account for the diphones */ mk_phone_map (); E_INFO("Added %d new begin/end word diphones\n", new_phone_id - phone_cnt); }
TEST(zmq_protobuf_msg_test, send_recv) { tutorial::MessageUnion msg; auto person = msg.mutable_person(); person->set_name("bob"); person->set_id(678); auto phone = person->add_phone(); phone->set_number("4125556666"); phone->set_type(tutorial::Person::WORK); tutorial::MessageUnion out = msg2protobuf(protobuf2msg(msg)); EXPECT_TRUE(out.msg_case() == tutorial::MessageUnion::kPerson); EXPECT_TRUE(out.has_person()); EXPECT_EQ(out.person().name(), msg.person().name()); // note that person() creates a default instance if the oneof did // not contain a person, I had expected exception instead. }
int phone_read (char *filename) /*------------------------------------------------------------* * read in the phone file filename *------------------------------------------------------------*/ { int32 retval = 0; FILE *fs = NULL; char phone_str[1024]; int32 phone_id = 0; int32 base_id = 0; int32 field1; int32 field2; int32 model_len, j; int32 tmp_num_phones; /* * Find #phones and set hash and list tables size hints. * (Otherwise, the simple-minded PC malloc library goes berserk.) */ fs = CM_fopen (filename, "r"); for (j = 1;; j++) if (fgets (phone_str, sizeof(phone_str), fs) == NULL) break; phones.size_hint = j; phones_list.size_hint = j; phone_base_map.size_hint = j; phone_model_len.size_hint = j; phone_type_map.size_hint = j; rewind(fs); while (EOF != fscanf (fs, "%s%d%d%d%d\n", phone_str, &field1, &field2, &base_id, &phone_id)) { /* * field1 is 0 for ciPhones */ if (field1 == 0) numCiPhones++; /* * Phones marked with a '-2' account for more than one model */ if (field1 == -2) { numWdPhones++; model_len = field2; } else model_len = 1; if (model_len <= 0) { E_WARN("%s has length %d\n", phone_str, model_len); } add_phone (phone_str, phone_id, base_id, field1, model_len); } tmp_num_phones = phone_id; /* * Next availiable phone id */ phone_id++; for (j = 0; j < tmp_num_phones; j++) { /* * If the phone is one of these within word phones then * create model_len-1 additional phones name ...(1) ...(2) and * and so on up to ...(model_len-1). It's these phones the * word refers to for it pronunciation */ if (phone_type(j) == -2) { int32 i; int32 model_len = phone_len (j); for (i = 1; i < model_len; i++) { char tmpstr[256]; sprintf (tmpstr, "%s(%d)", phone_from_id(j), i); add_phone (tmpstr, phone_id, j, 1000+i, 1); phone_id++; } } } mk_phone_map(); if (fs) fclose (fs); return (retval); }
bool Person::MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input) { #define DO_(EXPRESSION) if (!(EXPRESSION)) goto failure ::google::protobuf::uint32 tag; ::google::protobuf::io::StringOutputStream unknown_fields_string( mutable_unknown_fields()); ::google::protobuf::io::CodedOutputStream unknown_fields_stream( &unknown_fields_string); // @@protoc_insertion_point(parse_start:tutorial.Person) for (;;) { ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127); tag = p.first; if (!p.second) goto handle_unusual; switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { // required string name = 1; case 1: { if (tag == 10) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_name())); } else { goto handle_unusual; } if (input->ExpectTag(16)) goto parse_id; break; } // required int32 id = 2; case 2: { if (tag == 16) { parse_id: DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( input, &id_))); set_has_id(); } else { goto handle_unusual; } if (input->ExpectTag(26)) goto parse_email; break; } // optional string email = 3; case 3: { if (tag == 26) { parse_email: DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_email())); } else { goto handle_unusual; } if (input->ExpectTag(34)) goto parse_phone; break; } // repeated .tutorial.Person.PhoneNumber phone = 4; case 4: { if (tag == 34) { parse_phone: DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_phone())); } else { goto handle_unusual; } if (input->ExpectTag(34)) goto parse_phone; if (input->ExpectAtEnd()) goto success; break; } default: { handle_unusual: if (tag == 0 || ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { goto success; } DO_(::google::protobuf::internal::WireFormatLite::SkipField( input, tag, &unknown_fields_stream)); break; } } } success: // @@protoc_insertion_point(parse_success:tutorial.Person) return true; failure: // @@protoc_insertion_point(parse_failure:tutorial.Person) return false; #undef DO_ }