| 38 | namespace policy { |
| 39 | |
| 40 | ParseResult ParseEspMessage( |
| 41 | butil::IOBuf* source, |
| 42 | Socket*, |
| 43 | bool /*read_eof*/, |
| 44 | const void* /*arg*/) { |
| 45 | |
| 46 | EspHead head; |
| 47 | const size_t n = source->copy_to((char *)&head, sizeof(head)); |
| 48 | if (n < sizeof(head)) { |
| 49 | return MakeParseError(PARSE_ERROR_NOT_ENOUGH_DATA); |
| 50 | } |
| 51 | |
| 52 | uint32_t body_len = head.body_len; |
| 53 | if (body_len > FLAGS_max_body_size) { |
| 54 | return MakeParseError(PARSE_ERROR_TOO_BIG_DATA); |
| 55 | } else if (source->length() < sizeof(head) + body_len) { |
| 56 | return MakeParseError(PARSE_ERROR_NOT_ENOUGH_DATA); |
| 57 | } |
| 58 | |
| 59 | policy::MostCommonMessage* msg = policy::MostCommonMessage::Get(); |
| 60 | source->cutn(&msg->meta, sizeof(head)); |
| 61 | source->cutn(&msg->payload, body_len); |
| 62 | return MakeMessage(msg); |
| 63 | } |
| 64 | |
| 65 | void SerializeEspRequest( |
| 66 | butil::IOBuf* request_buf, |