| 27 | |
| 28 | template <typename T> |
| 29 | static T devolve(const google::protobuf::Message& message) |
| 30 | { |
| 31 | T t; |
| 32 | |
| 33 | string data; |
| 34 | |
| 35 | // NOTE: We need to use 'SerializePartialToString' instead of |
| 36 | // 'SerializeToString' because some required fields might not be set |
| 37 | // and we don't want an exception to get thrown. |
| 38 | CHECK(message.SerializePartialToString(&data)) |
| 39 | << "Failed to serialize " << message.GetTypeName() |
| 40 | << " while devolving to " << t.GetTypeName(); |
| 41 | |
| 42 | // NOTE: We need to use 'ParsePartialFromString' instead of |
| 43 | // 'ParseFromString' because some required fields might not |
| 44 | // be set and we don't want an exception to get thrown. |
| 45 | CHECK(t.ParsePartialFromString(data)) |
| 46 | << "Failed to parse " << t.GetTypeName() |
| 47 | << " while devolving from " << message.GetTypeName(); |
| 48 | |
| 49 | return t; |
| 50 | } |
| 51 | |
| 52 | |
| 53 | CommandInfo devolve(const v1::CommandInfo& command) |