def compile(self, position, fields, bisturi_conf): slots = Field._compile(self, position, fields, bisturi_conf) if self.aligned_to is None: self.aligned_to = bisturi_conf.get('align', 1) # XXX we are propagating the 'align' attribute (in bisturi_conf) to # the prototype packet. This is valid ...but inelegant # This happen in others fields like Optional and Ref self.seq_elem_field_name = "_seq_elem__"+self.field_name self.prototype_field.field_name = self.seq_elem_field_name self.prototype_field.compile(position=-1, fields=[], bisturi_conf=bisturi_conf) count, until, when = self.tmp if isinstance(count, (UnaryExpr, BinaryExpr)): count = compile_expr_into_callable(count) #if isinstance(until, (UnaryExpr, BinaryExpr)): # until = compile_expr_into_callable(until) if isinstance(when, (UnaryExpr, BinaryExpr)): when = compile_expr_into_callable(when) self.resolved_count = None if count is None else _get_count(count) self.when = _get_when(self.resolved_count, when) self.until_condition = _get_until(self.resolved_count, until) return slots + [self.seq_elem_field_name]
def compile(self, position, fields, bisturi_conf): slots = Field._compile(self, position, fields, bisturi_conf) self.opt_elem_field_name = "_opt_elem__"+self.field_name self.prototype_field.field_name = self.opt_elem_field_name self.prototype_field.compile(position=-1, fields=[], bisturi_conf=bisturi_conf) when = self.tmp del self.tmp if isinstance(when, (UnaryExpr, BinaryExpr)): when = compile_expr_into_callable(when) self.when = _get_when(None, when) return slots + [self.opt_elem_field_name]
def compile(self, position, fields, bisturi_conf): slots = Field._compile(self, position, fields, bisturi_conf) if self.byte_count is not None: if isinstance(self.byte_count, (int, long)): self.struct_code = "%is" % self.byte_count self.unpack = self._unpack_fixed_size elif isinstance(self.byte_count, Field): self.unpack = self._unpack_variable_size_field elif callable(self.byte_count): self.unpack = self._unpack_variable_size_callable elif isinstance(self.byte_count, (UnaryExpr, BinaryExpr)): self.byte_count = compile_expr_into_callable(self.byte_count) self.unpack = self._unpack_variable_size_callable else: assert False else: self._search_buffer_length = bisturi_conf.get('search_buffer_length') if self._search_buffer_length is not None: assert self._search_buffer_length >= 0 # the length can be 0 or None (means infinite) or a positive number if isinstance(self.until_marker, basestring): self.unpack = self._unpack_with_string_marker elif hasattr(self.until_marker, 'search'): self.unpack = self._unpack_with_regexp_marker else: assert False return slots