示例#1
0
 def encode_string(cls, value):
     size = cls._encode_varint(bytelength(value))
     data = value.encode('utf-8')
     return size + data
示例#2
0
 def test_bytelength(self):
     self.assertEqual(0, bytelength(''))
     self.assertEqual(3, bytelength('foo'))
     self.assertEqual(3, bytelength(b'\xe2\x84\xa2'.decode('utf-8')))
     self.assertEqual(3, bytelength(u'\u2122'))
示例#3
0
 def test_bytelength(self):
     self.assertEqual(0, bytelength(''))
     self.assertEqual(3, bytelength('foo'))
     self.assertEqual(3, bytelength(b'\xe2\x84\xa2'.decode('utf-8')))
     self.assertEqual(3, bytelength(u'\u2122'))
示例#4
0
文件: encoder.py 项目: paperclip/krpc
 def encode_string(cls, value):
     size = cls._encode_varint(bytelength(value))
     data = value.encode('utf-8')
     return size + data