Releases: dargueta/binobj
0.4.2
Released: 2018-06-07
Bugfixes
Variable-length integer fields now set their size
attribute if const
is
defined. Not doing so was apparently a deliberate decision (there was a unit test for it), which I no longer
understand.
Other Changes
Union
now throws aConfigurationError
if it gets aField
class
instead of an instance of aField
class. This would otherwise result in
hard to debugTypeError
s being thrown when trying to load or dump.- Trying to use a
computes
decorator on a const field will trigger a
ConfigurationError
. Bytes
no longer crashes with anUndefinedSizeError
if it isn't given a
size. I'm not sure why I ever thought thatBytes
should only be a fixed
length.
0.4.1
Released: 2018-05-13
Bugfixes
- Struct size couldn't be calculated if the struct contained computed fields or
had to use the default value for any field. - Setting the value of a computed or const field would persist until that field
was deleted. Trying to modify a computed or const field will now trigger a
ImmutableFieldError
. - Accessing a field as an attribute no longer sets the field to its default
value if the field hasn't been assigned yet. This made sense before computed
fields were added, since ostensibly changing one field wouldn't affect any
others. - Values assigned to a struct using dictionary notation were not validated.
len()
now throws aMissingRequiredValueError
exception if the struct
size couldn't be computed.UndefinedSizeError
is a configuration error and
in retrospect made no sense to throw there.- A better error message is shown when accessing a
Struct
using a field name
that doesn't exist. - Attempting to get the value of a field that hasn't been set yet via dictionary
access used to throw aKeyError
even if it was a computed field. Now it
throws the expectedMissingRequiredValueError
.
Other Changes
- Dictionary methods on
Struct
likeget
,setdefault
, etc. are
deprecated and should not be used anymore. They will be removed in 0.5.0. - Validator decorators now detect when they're being misused (i.e. called as
@validator
instead of@validator()
and throw a helpful exception. - Bump tested CPython versions to the latest release, i.e. 3.4.7 -> 3.4.8, etc.
- Bump PyPy3.5 5.10 to v6.0
0.4.0
Released: 2018-04-21
Bugfixes
- Removed unused
__computed_fields__
property fromStruct
classes. It was
accidentally left in. - Fixed WAV file generation in the examples. It was writing the frequency of the
wave to the file, not the amplitude. - Miscellaneous tweaks and typo corrections in documentation.
Features
Added support for adding validators on fields, both as methods in their Struct
and passed in to the constructor. You can also have validator methods that
validate the entire Struct
just after loading or just before dumping.
Breaking Changes
- Dropped support for Python 3.3, which has been deprecated. Please upgrade to a
newer version of Python. VariableSizedFieldError
was deprecated in 0.3.1. It has been removed and
completely replaced byUndefinedSizeError
.
Other Changes
- Start testing on Python 3.7.
- Assigning directly to the
__values__
dict in aStruct
is deprecated,
as it circumvents validators.__values__
will be removed in a future
release.
0.3.1
Released: 2018-03-28
Bugfixes
- Fixed bug where
Bytes
wasn't checking how many bytes it was writing when
dumping. - Fixed bug where
Field.size
was incorrectly computed for fields where
len(const)
wasn't equivalent to the field size, e.g. forString
fields
using a UTF-16 encoding.
Other Changes
VariableSizedFieldError
has been deprecated, and will be replaced by
UndefinedSizeError
. This is because the exception name and error message
was misleadingly narrow in scope.- Removed undocumented
loaded_fields
andall_fields
arguments from the
loading and dumping methods inStruct
. They were left in by mistake and
never used.
0.3.0
Released: 2018-03-23
Bugfixes
- Fixed field redefinition detection. Subclassing wasn't supported in earlier
versions but the code was still there.
Features
Array
can now take anotherField
or a string naming aField
as its
count
argument. This lets you avoid having to write a halting function:
# As of 0.3.0:
class MyStruct(Struct):
n_numbers = UInt16()
numbers = Array(UInt16(), count=n_numbers)
# For earlier versions:
def halt_n_numbers(seq, stream, values, context, loaded_fields):
return len(values) >= loaded_fields['n_numbers']
class MyStruct(Struct):
n_numbers = UInt16()
numbers = Array(UInt16(), halt_check=halt_n_numbers)
-
The new
computes
decorator gives you the ability to use a function to
dynamically compute the value of a field when serializing, instead of passing
it in yourself. -
New field type
Union
allows you to emulate C'sunion
storage class
using fields, structs, or any combination of the two. -
Added
struct
andobj
keyword arguments toConfigurationError
to
give more flexibility in what errors it and its subclasses can be used for.
Breaking Changes
None.
Documentation
- Changed development stage from alpha stage to beta.
- Expanded documentation of existing code, fixed inter-module references.
0.2.1
Released: 2018-03-18
Bugfixes
- Fixed argument names in overridden methods of some fields differing from their
superclass' signature. AffectsInteger
,String
,StringZ
and
VariableLengthInteger
. - Fixed
to_dict()
method ofStruct
so that it recurses and converts all
nested fields and arrays into Python dicts as well. This means that the output
ofStruct.to_dict()
is JSON-serializable if all fields are defined. - Changed
BytesIO
in documentation toBufferedIOBase
sinceFileIO
is
also a legitimate input type. Array
halt functions can now reference the fields that have already been
deserialized. This was supposed to be included in 0.1.0 but somehow was
overlooked.
Breaking Changes
-
The fix for bug 2:
dict(struct)
andstruct.to_dict()
no longer give identical results.- For nested structures,
struct.to_dict()
will return dictionaries where
the old behavior would return instances of thoseStruct
objects. This
only matters if your code relied on nested structs beingStruct
objects.
-
The fix for bug 4 added additional a positional argument to
_do_load
,
_do_dump
, and the halt functions. This will break subclasses that define
these functions, but the fix is minimal:- Add
loaded_fields
as the last argument to your halt functions as well as
any overridden_do_load
methods in custom fields. - Add
all_fields
as the last argument to_do_dump
methods in custom
fields.
- Add
Documentation
- Added WAV file example and unit tests.
- Changed "end to end tests" file into a BMP file example since it was only using
the BMP format anyway. - Added comprehensive tutorial on basics with a bit of intermediate stuff.
Version 0.2.0
Released: 2018-03-04
Bugfixes
StringZ
can now load strings in character encodings that use more than one
byte to represent null, e.g. UTF-16.- Fixed some typos in documentation.
Features
String
and its subclasses now take apad_byte
argument that pads strings
with that byte if they're too short after encoding. For example:
>>> String(size=4, pad_byte=b' ').dumps('a')
b'a '
Version 0.1.0
Initial release.