generator: Strings are utf-8 by default in python3
authorKyle Manna <kyle@kylemanna.com>
Sat, 19 Sep 2015 22:13:05 +0000 (15:13 -0700)
committerKyle Manna <kyle@kylemanna.com>
Mon, 21 Sep 2015 01:53:15 +0000 (18:53 -0700)
* Not sure how to handle this case in python2, seems to work
* Python 3 doesn't need this since all strings are utf-8

generator/nanopb_generator.py

index f7d4322..78140a4 100755 (executable)
@@ -379,12 +379,10 @@ class Field:
                 inner_init = '0'
         else:
             if self.pbtype == 'STRING':
-                inner_init = self.default.encode('utf-8').encode('string_escape')
-                inner_init = inner_init.replace('"', '\\"')
+                inner_init = self.default.replace('"', '\\"')
                 inner_init = '"' + inner_init + '"'
             elif self.pbtype == 'BYTES':
-                data = str(self.default).decode('string_escape')
-                data = ['0x%02x' % ord(c) for c in data]
+                data = ['0x%02x' % ord(c) for c in self.default]
                 if len(data) == 0:
                     inner_init = '{0, {0}}'
                 else: