sip - Problems with parsing a text header packet in c++ -
i trying parse header packet of sip protocol (similar http) text based protocol. fields in header not have order. ex: if there 3 fields, f1, f2, , f3 can come in order number of times f3, f2 , f1, f1.
this increasing complexity of parser since don't know come first.
what should overcome complexity?
ultimately, need decouple processing order of receipt. that, have loop repeats while fields encountered, , inside loop determine field type is, dispatch processing field type. if can process fields great, if need save potentially multiple values given field type might - example - put them vector or shared multimap keyed on field name or id.
pseudo-code:
field x; while (x = get_next_field(input)) { switch (x.type()) { case type1: field1_values.push_back(x.value()); break; case type2: field2 = x.value(); break; // keep last value seen... default: throw std::runtime_error("unsupported field type"); } } // use field1_values / field2 etc. variables....
Comments
Post a Comment