mrdor44 / stru Goto Github PK
View Code? Open in Web Editor NEWAn IDE friendly alternative to Python's struct and construct
License: GNU General Public License v3.0
An IDE friendly alternative to Python's struct and construct
License: GNU General Public License v3.0
When decorating a subclass of Struct
with @dataclass
or @attr.define
, the following errors occur at Point
's construction time: TypeError: TestSelf.test_pack_unpack.<locals>.Point.__init__() got an unexpected keyword argument 'x'
def test_pack_unpack(self):
class Point(Struct):
"""
Semantic eq method is provided by Struct
@attr.define -- does not play well with the super-class
@dataclass -- does not play well with the super-class
"""
_endianess = Endianess.LittleEndian
x = FieldType.WORD
y = FieldType.WORD
name = FieldType.String[6]("NONAME")
original_point = Point(x=1, y=2)
packed_point = original_point.pack()
assert_that(packed_point,
is_(b'\x01\x00\x02\x00NONAME'))
unpacked_point = Point.unpack(packed_point)
assert_that(unpacked_point,
is_(original_point))
self.log().debug(unpacked_point)
def should_pack_unpack(self):
class LEStruct(Struct):
_endianess = Endianess.LittleEndian
class HasId(LEStruct):
id = FieldType.WORD(default=0)
class HasName(LEStruct):
name = FieldType.String[6]("NONAME")
# ISSUE paprika provided @to_string decorator fails when used
# together with Struct super-class
# @to_string
# https://github.com/rayanht/paprika/issues/28#issuecomment-2212366362
# ISSUE multiple inheritance does not work, only first member is
# recognized
class Point(HasName, HasId):
"""
Semantic eq method is provided by Struct
@attr.define -- does not play well with the super-class
@dataclass -- does not play well with the super-class
"""
x = FieldType.WORD
y = FieldType.WORD
@to_string
class Point3D(Point):
z = FieldType.WORD
original_point = Point3D(x=1, y=2, z=3)
packed_point = original_point.pack()
# assert_that(packed_point,
# is_(b'NONAME\x00\x00\x01\x00\x02\x00\x03\x00'))
self.log.debug(packed_point)
unpacked_point = Point3D.unpack(packed_point)
self.log.debug(unpacked_point)
assert_that(unpacked_point,
is_(original_point))
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.