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
86fb05d3
Commit
86fb05d3
authored
Oct 06, 2017
by
Robert
Committed by
Wouter van Oortmerssen
Oct 06, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Python: CreateByteVector function in builder. (#4453)
parent
5e473918
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
0 deletions
+39
-0
builder.py
python/flatbuffers/builder.py
+21
-0
py_test.py
tests/py_test.py
+18
-0
No files found.
python/flatbuffers/builder.py
View file @
86fb05d3
...
@@ -421,6 +421,27 @@ class Builder(object):
...
@@ -421,6 +421,27 @@ class Builder(object):
return
self
.
EndVector
(
len
(
x
))
return
self
.
EndVector
(
len
(
x
))
def
CreateByteVector
(
self
,
x
):
"""CreateString writes a byte vector."""
self
.
assertNotNested
()
## @cond FLATBUFFERS_INTERNAL
self
.
nested
=
True
## @endcond
if
not
isinstance
(
x
,
compat
.
binary_types
):
raise
TypeError
(
"non-byte vector passed to CreateByteVector"
)
self
.
Prep
(
N
.
UOffsetTFlags
.
bytewidth
,
len
(
x
)
*
N
.
Uint8Flags
.
bytewidth
)
l
=
UOffsetTFlags
.
py_type
(
len
(
x
))
## @cond FLATBUFFERS_INTERNAL
self
.
head
=
UOffsetTFlags
.
py_type
(
self
.
Head
()
-
l
)
## @endcond
self
.
Bytes
[
self
.
Head
():
self
.
Head
()
+
l
]
=
x
return
self
.
EndVector
(
len
(
x
))
## @cond FLATBUFFERS_INTERNAL
## @cond FLATBUFFERS_INTERNAL
def
assertNested
(
self
):
def
assertNested
(
self
):
"""
"""
...
...
tests/py_test.py
View file @
86fb05d3
...
@@ -459,6 +459,17 @@ class TestByteLayout(unittest.TestCase):
...
@@ -459,6 +459,17 @@ class TestByteLayout(unittest.TestCase):
self
.
assertBuilderEquals
(
b
,
[
4
,
0
,
0
,
0
,
4
,
5
,
6
,
7
,
0
,
0
,
0
,
0
,
self
.
assertBuilderEquals
(
b
,
[
4
,
0
,
0
,
0
,
4
,
5
,
6
,
7
,
0
,
0
,
0
,
0
,
3
,
0
,
0
,
0
,
1
,
2
,
3
,
0
])
3
,
0
,
0
,
0
,
1
,
2
,
3
,
0
])
def
test_create_byte_vector
(
self
):
b
=
flatbuffers
.
Builder
(
0
)
b
.
CreateByteVector
(
b
""
)
# 0-byte pad:
self
.
assertBuilderEquals
(
b
,
[
0
,
0
,
0
,
0
])
b
=
flatbuffers
.
Builder
(
0
)
b
.
CreateByteVector
(
b
"
\x01\x02\x03
"
)
# 1-byte pad:
self
.
assertBuilderEquals
(
b
,
[
3
,
0
,
0
,
0
,
1
,
2
,
3
,
0
])
def
test_empty_vtable
(
self
):
def
test_empty_vtable
(
self
):
b
=
flatbuffers
.
Builder
(
0
)
b
=
flatbuffers
.
Builder
(
0
)
b
.
StartObject
(
0
)
b
.
StartObject
(
0
)
...
@@ -1226,6 +1237,13 @@ class TestExceptions(unittest.TestCase):
...
@@ -1226,6 +1237,13 @@ class TestExceptions(unittest.TestCase):
assertRaises
(
self
,
lambda
:
b
.
CreateString
(
s
),
assertRaises
(
self
,
lambda
:
b
.
CreateString
(
s
),
flatbuffers
.
builder
.
IsNestedError
)
flatbuffers
.
builder
.
IsNestedError
)
def
test_create_byte_vector_is_nested_error
(
self
):
b
=
flatbuffers
.
Builder
(
0
)
b
.
StartObject
(
0
)
s
=
b
'test1'
assertRaises
(
self
,
lambda
:
b
.
CreateByteVector
(
s
),
flatbuffers
.
builder
.
IsNestedError
)
def
test_finished_bytes_error
(
self
):
def
test_finished_bytes_error
(
self
):
b
=
flatbuffers
.
Builder
(
0
)
b
=
flatbuffers
.
Builder
(
0
)
assertRaises
(
self
,
lambda
:
b
.
Output
(),
assertRaises
(
self
,
lambda
:
b
.
Output
(),
...
...
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