Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
flatbuffers
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
flatbuffers
Commits
b7d97ff3
Commit
b7d97ff3
authored
Jan 20, 2016
by
Robert
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3491 from faizanrashid/master
[BUG FIX] [MINOR] Fix encoding with unicode characters.
parents
bf07c37a
af236833
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
8 deletions
+22
-8
builder.py
python/flatbuffers/builder.py
+2
-2
py_test.py
tests/py_test.py
+20
-6
No files found.
python/flatbuffers/builder.py
View file @
b7d97ff3
...
...
@@ -391,7 +391,7 @@ class Builder(object):
self
.
PlaceUOffsetT
(
vectorNumElems
)
return
self
.
Offset
()
def
CreateString
(
self
,
s
):
def
CreateString
(
self
,
s
,
encoding
=
'utf-8'
,
errors
=
'strict'
):
"""CreateString writes a null-terminated byte string as a vector."""
self
.
assertNotNested
()
...
...
@@ -400,7 +400,7 @@ class Builder(object):
## @endcond
if
isinstance
(
s
,
compat
.
string_types
):
x
=
s
.
encode
()
x
=
s
.
encode
(
encoding
,
errors
)
elif
isinstance
(
s
,
compat
.
binary_type
):
x
=
s
else
:
...
...
tests/py_test.py
View file @
b7d97ff3
# coding=utf-8
# Copyright 2014 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
...
...
@@ -389,23 +390,36 @@ class TestByteLayout(unittest.TestCase):
def
test_create_ascii_string
(
self
):
b
=
flatbuffers
.
Builder
(
0
)
b
.
CreateString
(
u"foo"
.
encode
(
'ascii'
))
b
.
CreateString
(
u"foo"
,
encoding
=
'ascii'
)
# 0-terminated, no pad:
self
.
assertBuilderEquals
(
b
,
[
3
,
0
,
0
,
0
,
'f'
,
'o'
,
'o'
,
0
])
b
.
CreateString
(
u"moop"
.
encode
(
'ascii'
)
)
b
.
CreateString
(
u"moop"
,
encoding
=
'ascii'
)
# 0-terminated, 3-byte pad:
self
.
assertBuilderEquals
(
b
,
[
4
,
0
,
0
,
0
,
'm'
,
'o'
,
'o'
,
'p'
,
0
,
0
,
0
,
0
,
3
,
0
,
0
,
0
,
'f'
,
'o'
,
'o'
,
0
])
def
test_create_utf8_string
(
self
):
b
=
flatbuffers
.
Builder
(
0
)
b
.
CreateString
(
u"Цлїςσδε"
)
self
.
assertBuilderEquals
(
b
,
"
\x0e\x00\x00\x00\xd0\xa6\xd0\xbb\xd1\x97
"
\
"
\xcf\x82\xcf\x83\xce\xb4\xce\xb5\x00\x00
"
)
b
.
CreateString
(
u"フムアムカモケモ"
)
self
.
assertBuilderEquals
(
b
,
"
\x18\x00\x00\x00\xef\xbe\x8c\xef\xbe\x91
"
\
"
\xef\xbd\xb1\xef\xbe\x91\xef\xbd\xb6\xef\xbe\x93\xef\xbd\xb9\xef
"
\
"
\xbe\x93\x00\x00\x00\x00\x0e\x00\x00\x00\xd0\xa6\xd0\xbb\xd1\x97
"
\
"
\xcf\x82\xcf\x83\xce\xb4\xce\xb5\x00\x00
"
)
def
test_create_arbitrary_string
(
self
):
b
=
flatbuffers
.
Builder
(
0
)
s
=
"
\x01\x02\x03
"
.
encode
(
'utf-8'
)
b
.
CreateString
(
s
)
s
=
"
\x01\x02\x03
"
b
.
CreateString
(
s
)
# Default encoding is utf-8.
# 0-terminated, no pad:
self
.
assertBuilderEquals
(
b
,
[
3
,
0
,
0
,
0
,
1
,
2
,
3
,
0
])
s2
=
"
\x04\x05\x06\x07
"
.
encode
(
'utf-8'
)
b
.
CreateString
(
s2
)
s2
=
"
\x04\x05\x06\x07
"
b
.
CreateString
(
s2
)
# Default encoding is utf-8.
# 0-terminated, 3-byte pad:
self
.
assertBuilderEquals
(
b
,
[
4
,
0
,
0
,
0
,
4
,
5
,
6
,
7
,
0
,
0
,
0
,
0
,
3
,
0
,
0
,
0
,
1
,
2
,
3
,
0
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment