File tree 1 file changed +4
-1
lines changed
src/MediaStation/Primitives
1 file changed +4
-1
lines changed Original file line number Diff line number Diff line change 1
1
from enum import IntEnum
2
+ from typing import Optional
2
3
3
4
import self_documenting_struct as struct
4
5
from asset_extraction_framework .Exceptions import BinaryParsingError
@@ -54,10 +55,12 @@ class Type(IntEnum):
54
55
## The number of bytes read from the stream depends on the type
55
56
## of the datum.
56
57
## \param[in] stream - A binary stream that supports the read method.
57
- def __init__ (self , stream ):
58
+ def __init__ (self , stream , expected_type : Optional [ Type ] = None ):
58
59
# READ THE TYPE OF THE DATUM.
59
60
# Regardless of the datum's value the type always has constant size.
60
61
self .t = struct .unpack .uint16_le (stream )
62
+ if expected_type is not None and self .t != expected_type :
63
+ raise BinaryParsingError (f'Expected datum type { expected_type .name } , but got datum type { self .Type (self .t ).name } .' )
61
64
62
65
# READ THE VALUE IN THE DATUM.
63
66
if (self .t == Datum .Type .UINT8 ):
You can’t perform that action at this time.
0 commit comments