def encode_string(cls, value): size = cls._encode_varint(bytelength(value)) data = value.encode('utf-8') return size + data
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'))