Skip to content

Commit 37fb840

Browse files
committed
Store null-terminated strings and omit string lengths
1 parent 0386c8a commit 37fb840

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

bulk_insert.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ def __init__(self, prop_str):
5555

5656
# If we've reached this point, the property is a string
5757
self.type = Type.STRING
58-
self.format_str += "I%ds" % len(prop_str) # 4-byte int for string length, then string
59-
self.pack_args = [len(prop_str), prop_str]
58+
self.format_str += "%ds" % (len(prop_str) + 1)
59+
self.pack_args = [prop_str]
6060

6161
def to_binary(self):
6262
return struct.pack(self.format_str, *[self.type] + self.pack_args)
@@ -83,12 +83,11 @@ def __init__(self, filename):
8383
def pack_header(self, header):
8484
prop_count = len(header) - self.prop_offset
8585
# String format
86-
# Is == length, string
87-
fmt = "=I%dsI" % len(self.entity_str) # Unaligned native, entity_string length, entity_string string, count of properties
88-
args = [len(self.entity_str), self.entity_str, prop_count]
86+
fmt = "=%dsI" % (len(self.entity_str) + 1) # Unaligned native, entity_string, count of properties
87+
args = [self.entity_str, prop_count]
8988
for prop in header[self.prop_offset:]:
90-
fmt += "I%ds" % len(prop)
91-
args += [len(prop), prop]
89+
fmt += "%ds" % (len(prop) + 1)
90+
args += [prop]
9291
return struct.pack(fmt, *args)
9392

9493
def pack_props(self, line):

0 commit comments

Comments
 (0)