Skip to content

Commit d346df7

Browse files
author
cabrol
committed
Added support for commentAttributes within the add_fields() rooutine
Signed-off-by: qcabrol
1 parent c0b2feb commit d346df7

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

dissect/cstruct/cstruct.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def _read(self, stream):
8181
8282
return Instance(self, r, sizes)
8383
84-
def add_fields(self, name, type_, offset=None):
84+
def add_fields(self, name, type_, offset=None, commentAttributes={}):
8585
raise NotImplementedError("Can't add fields to a compiled structure")
8686
8787
def __repr__(self):
@@ -877,15 +877,15 @@ def _write(self, stream, data):
877877

878878
return num
879879

880-
def add_field(self, name, type_, offset=None):
880+
def add_fields(self, name, type_, offset=None, commentAttributes={}):
881881
"""Add a field to this structure.
882882
883883
Args:
884884
name: The field name.
885885
type_: The field type.
886886
offset: The field offset.
887887
"""
888-
field = Field(name, type_, offset=offset)
888+
field = Field(name, type_, offset=offset, commentAttributes=commentAttributes)
889889
self.fields.append(field)
890890
self.lookup[name] = field
891891
self.size = None

tests/test_basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,9 +731,9 @@ def test_struct_sizes():
731731
""", compiled=False)
732732

733733
assert len(c.static) == 4
734-
c.static.add_field("another", c.uint32)
734+
c.static.add_fields("another", c.uint32)
735735
assert len(c.static) == 8
736-
c.static.add_field("atoffset", c.uint32, 12)
736+
c.static.add_fields("atoffset", c.uint32, 12)
737737
assert len(c.static) == 16
738738

739739
a = c.static(b'\x01\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00')

0 commit comments

Comments
 (0)