对响应头部的字节做解析 :param response_head: :return:
(response_head)
| 417 | |
| 418 | |
| 419 | def parse_response_head(response_head): |
| 420 | """ |
| 421 | 对响应头部的字节做解析 |
| 422 | :param response_head: |
| 423 | :return: |
| 424 | """ |
| 425 | # Magic number |
| 426 | if not (response_head[0] == 0xda and response_head[1] == 0xbb): |
| 427 | raise DubboException('illegal response') |
| 428 | |
| 429 | # 第三位为1表示这是一个心跳包 |
| 430 | if response_head[2] & 0x20 == 0x20: |
| 431 | if response_head[2] & 0x80 == 0x80: |
| 432 | # 第一位为1,一个心跳请求的包 |
| 433 | heartbeat = 2 |
| 434 | else: |
| 435 | # 第一位为0,一个心跳响应的包 |
| 436 | heartbeat = 1 |
| 437 | response_status = response_head[3] |
| 438 | if response_status != 20: |
| 439 | raise DubboException(response_status_message[response_status]) |
| 440 | else: |
| 441 | heartbeat = 0 |
| 442 | response_status = response_head[3] |
| 443 | if response_status != 20: |
| 444 | raise DubboResponseException(response_status_message[response_status]) |
| 445 | return heartbeat, unpack('!i', response_head[12:])[0] |
| 446 | |
| 447 | |
| 448 | if __name__ == '__main__': |
no test coverage detected