MCPcopy Index your code
hub / github.com/apache/dubbo-python2 / _read_utf

Method _read_utf

dubbo/codec/decoder.py:162–182  ·  view source on GitHub ↗

读取n个字符 :param length: :return:

(self, length)

Source from the content-addressed store, hash-verified

160 return result
161
162 def _read_utf(self, length):
163 """
164 读取n个字符
165 :param length:
166 :return:
167 """
168 value = u''
169 for i in xrange(length):
170 ch = self.read_byte()
171 if ch < 0x80:
172 value += unichr(ch)
173 elif (ch & 0xe0) == 0xc0:
174 ch1 = self.read_byte()
175 value += unichr(((ch & 0x1f) << 6) + (ch1 & 0x3f))
176 elif (ch & 0xf0) == 0xe0:
177 ch1 = self.read_byte()
178 ch2 = self.read_byte()
179 value += unichr(((ch & 0x0f) << 12) + ((ch1 & 0x3f) << 6) + (ch2 & 0x3f))
180 else:
181 raise ValueError('Can\'t parse utf-8 char {}&#x27;.format(ch))
182 return value.encode('utf-8') # 将unicode转化为str类型
183
184 @ranges((0x00, 0x1f), (0x30, 0x33), 0x52, ord('S'))
185 def read_string(self):

Callers 1

read_stringMethod · 0.95

Calls 3

read_byteMethod · 0.95
formatMethod · 0.80
encodeMethod · 0.80

Tested by

no test coverage detected