对字符串进行编码,编码格式utf-8 参见方法:com.alibaba.com.caucho.hessian.io.Hessian2Output#printString :param value: :return:
(value)
| 260 | |
| 261 | @staticmethod |
| 262 | def _encode_utf(value): |
| 263 | """ |
| 264 | 对字符串进行编码,编码格式utf-8 |
| 265 | 参见方法:com.alibaba.com.caucho.hessian.io.Hessian2Output#printString |
| 266 | :param value: |
| 267 | :return: |
| 268 | """ |
| 269 | result = [] |
| 270 | for v in value: |
| 271 | ch = ord(v) |
| 272 | if ch < 0x80: |
| 273 | result.append(ch & 0xff) |
| 274 | elif ch < 0x800: |
| 275 | result.append((0xc0 + ((ch >> 6) & 0x1f)) & 0xff) |
| 276 | result.append((0x80 + (ch & 0x3f)) & 0xff) |
| 277 | else: |
| 278 | result.append((0xe0 + ((ch >> 12) & 0xf)) & 0xff) |
| 279 | result.append((0x80 + ((ch >> 6) & 0x3f)) & 0xff) |
| 280 | result.append((0x80 + (ch & 0x3f)) & 0xff) |
| 281 | return result |
| 282 | |
| 283 | def _encode_str(self, value): |
| 284 | """ |