Hi, I'm trying to use Suitcase to define the Apple iAP protocol received through a stream.
I'm not sure my approach to handle the payload length is smart enough. The size could be on 1 byte or 3bytes depending if the packet is a small one or a large one. I used ConditionalField but would have preferred to record the length in only one field.
I also don't understand why I can't use Structure this way without fixing the length. I'm not able to decode LingoGeneralIdentifyDeviceLingoes as soon as I use DispatchTarget() in LingoGeneral.
classLingoGeneralIdentifyDeviceLingoes(Structure):
id=UBInt8Sequence(12)
classLingoGeneral(Structure):
command_id=DispatchField(UBInt8())
command_data=DispatchTarget(dispatch_field=command_id, dispatch_mapping={
0x13: LingoGeneralIdentifyDeviceLingoes,
})
classLingoSimpleRemote(Structure):
command_id=DispatchField(UBInt8())
command_data=Payload()
classLingoDisplayRemote(Structure):
command_id=DispatchField(UBInt8())
command_data=Payload()
classLingoExtendedInterface(Structure):
command_id=DispatchField(UBInt16())
command_data=Payload()
classLingoPacket(Structure):
header=Magic(b'\xFF\x55')
payload_length=LengthField(UBInt8(), get_length=lambdal: l.getval() -1, set_length=lambdaf, v: f.setval(v+1))
large_payload_length=ConditionalField(LengthField(UBInt16(), get_length=lambdal: l.getval() -1,
set_length=lambdaf, v: f.setval(v+1)), lambdam: m.payload_length==0)
lingo_id=DispatchField(UBInt8())
payload=ConditionalField(DispatchTarget(length_provider=payload_length, dispatch_field=lingo_id, dispatch_mapping={
0x00: LingoGeneral,
0x02: LingoSimpleRemote,
0x03: LingoDisplayRemote,
0x04: LingoExtendedInterface
}), lambdam: m.payload_length!=0)
large_payload=ConditionalField(
DispatchTarget(length_provider=large_payload_length, dispatch_field=lingo_id, dispatch_mapping={
0x00: LingoGeneral,
0x02: LingoSimpleRemote,
0x03: LingoDisplayRemote,
0x04: LingoExtendedInterface
}), lambdam: m.payload_length==0)
checksum=CRCField(UBInt8(), algo=ipod_checksum, start=2, end=-1)
Hi, I'm trying to use Suitcase to define the Apple iAP protocol received through a stream.
I'm not sure my approach to handle the payload length is smart enough. The size could be on 1 byte or 3bytes depending if the packet is a small one or a large one. I used ConditionalField but would have preferred to record the length in only one field.
I also don't understand why I can't use Structure this way without fixing the length. I'm not able to decode LingoGeneralIdentifyDeviceLingoes as soon as I use DispatchTarget() in LingoGeneral.