@@ -69,18 +69,42 @@ def check_arguments(cls, **kwargs):
6969 if hasattr (composite , "check_arguments" ):
7070 composite .check_arguments (** subset_arguments )
7171
72- def deframe (self , data , no_copy = False ):
73- """ Deframe via a chain of children deframers """
74- packet = data [:] if not no_copy else data
75- remaining = None
76- discarded = b""
72+ def deframe_all (self , data , no_copy ):
73+ """ Deframe all available frames"
7774
75+ Since packets can be composites of multiple underlying packets, the chaining framer must override deframe_all
76+ in order to allow for these composite packets
77+ """
78+ # Packet the incoming data as an array of 1 packet. This will set up the standard algorithm where each packet
79+ # is processed in series
80+ packets = [data if no_copy else data [:]]
81+ # Remaining data (left over from first packet) is unset, but will be set after the processing of the first
82+ # packet as the first represents the outer frame
83+ remaining = None
84+ # Aggregate discarded data across all packets
85+ discarded_aggregate = b""
86+ # Loop over ever deframer
7887 for deframer in self .deframers :
79- new_packet , new_remaining , new_discarded = deframer .deframe (packet , True )
80- discarded += new_discarded
81- remaining = new_remaining if remaining is None else remaining
82- packet = new_packet
83- return packet , remaining , discarded
88+ deframer_packets = []
89+ # Loop over the list of packets from the previous deframer
90+ for packet_data in packets :
91+ # Deframe all packets available in this current packet. The packet list is updated from the return
92+ # value as we use the chained deframers to continually break into it
93+ new_packets , new_remaining , new_discarded = deframer .deframe_all (packet_data , True )
94+ # If the first packet remaining hasn't be updated, then we set remaining. Otherwise we retain the old
95+ # value because remaining is defined as the outer-most packet.
96+ remaining = new_remaining if remaining is None else remaining
97+ # Discarded data is aggregated regardless of where it comes from
98+ discarded_aggregate += new_discarded
99+ # Append all packets from this layer into the list of processing for the next layer
100+ deframer_packets .extend (new_packets )
101+ # Update the list of packets for the next deframer as the concatenated output of each run of this layer.
102+ packets = deframer_packets
103+ # Return list of packets from the last layer, remaining from the outer layer, and discarded from all layers
104+ return packets , remaining , discarded_aggregate
105+
106+ def deframe (self , data , no_copy = False ):
107+ assert False , "Should never be called"
84108
85109 def frame (self , data ):
86110 """ Frame via a chain of children framers """
0 commit comments