#NEWLINE# def value_to_bytes( self , obj , value , default_endianness = DEFAULT_ENDIANNESS ) : #NEWLINE# #INDENT# v = value . serialise ( default_endianness = default_endianness ) #NEWLINE# if isinstance ( self . length , Field ) : #NEWLINE# #INDENT# max_len = getattr ( obj , self . length . _name ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# max_len = self . length #NEWLINE# #UNINDENT# if ( ( max_len is not None ) and ( len ( v ) > max_len ) ) : #NEWLINE# #INDENT# raise PacketEncodeError ( 'Embedded field with max length {} is actually {} bytes long.' . format ( self . length , len ( v ) ) ) #NEWLINE# #UNINDENT# return v