#NEWLINE# @ staticmethod #NEWLINE# def serialize( dec , protocol_version ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ( sign , digits , exponent ) = dec . as_tuple ( ) #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ( sign , digits , exponent ) = Decimal ( dec ) . as_tuple ( ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# raise TypeError ( 'Invalid type for Decimal value: %r' , dec ) #NEWLINE# #UNINDENT# #UNINDENT# unscaled = int ( '' . join ( [ str ( digit ) for digit in digits ] ) ) #NEWLINE# if sign : #NEWLINE# #INDENT# unscaled *= ( - 1 ) #NEWLINE# #UNINDENT# scale = int32_pack ( ( - dec ) ) #NEWLINE# unscaled = varint_pack ( unscaled ) #NEWLINE# return ( scale + unscaled )