diff options
author | Robert <rw@users.noreply.github.com> | 2017-10-06 08:34:07 -0700 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2017-10-06 08:34:07 -0700 |
commit | 86fb05d3201f14a3ac65f663077e2c9644c9f79d (patch) | |
tree | 21c1310edbb08fdfeb0a12093c08a2e1b35f23fa /python | |
parent | 5e4739184f7ac028dfe2eb14eed5c3e25b49f9c9 (diff) | |
download | flatbuffers-86fb05d3201f14a3ac65f663077e2c9644c9f79d.tar.gz flatbuffers-86fb05d3201f14a3ac65f663077e2c9644c9f79d.tar.bz2 flatbuffers-86fb05d3201f14a3ac65f663077e2c9644c9f79d.zip |
Python: CreateByteVector function in builder. (#4453)
Diffstat (limited to 'python')
-rw-r--r-- | python/flatbuffers/builder.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/python/flatbuffers/builder.py b/python/flatbuffers/builder.py index e6d6882c..a21f3616 100644 --- a/python/flatbuffers/builder.py +++ b/python/flatbuffers/builder.py @@ -421,6 +421,27 @@ class Builder(object): 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 def assertNested(self): """ |