def serialize(dec):
     sign, digits, exponent = dec.as_tuple()
     unscaled = int(''.join([str(digit) for digit in digits]))
     if sign:
         unscaled *= -1
     scale = int32_pack(-exponent)
     unscaled = varint_pack(unscaled)
     return scale + unscaled
Exemple #2
0
 def serialize(dec):
     try:
         sign, digits, exponent = dec.as_tuple()
     except AttributeError:
         raise TypeError("Non-Decimal type received for Decimal value")
     unscaled = int(''.join([str(digit) for digit in digits]))
     if sign:
         unscaled *= -1
     scale = int32_pack(-exponent)
     unscaled = varint_pack(unscaled)
     return scale + unscaled
Exemple #3
0
 def serialize(dec, protocol_version):
     try:
         sign, digits, exponent = dec.as_tuple()
     except AttributeError:
         raise TypeError("Non-Decimal type received for Decimal value")
     unscaled = int(''.join([str(digit) for digit in digits]))
     if sign:
         unscaled *= -1
     scale = int32_pack(-exponent)
     unscaled = varint_pack(unscaled)
     return scale + unscaled
Exemple #4
0
 def serialize(dec, protocol_version):
     try:
         sign, digits, exponent = dec.as_tuple()
     except AttributeError:
         try:
             sign, digits, exponent = Decimal(dec).as_tuple()
         except Exception:
             raise TypeError("Invalid type for Decimal value: %r", dec)
     unscaled = int(''.join([str(digit) for digit in digits]))
     if sign:
         unscaled *= -1
     scale = int32_pack(-exponent)
     unscaled = varint_pack(unscaled)
     return scale + unscaled
Exemple #5
0
 def serialize(dec, protocol_version):
     try:
         sign, digits, exponent = dec.as_tuple()
     except AttributeError:
         try:
             sign, digits, exponent = Decimal(dec).as_tuple()
         except Exception:
             raise TypeError("Invalid type for Decimal value: %r", dec)
     unscaled = int("".join([str(digit) for digit in digits]))
     if sign:
         unscaled *= -1
     scale = int32_pack(-exponent)
     unscaled = varint_pack(unscaled)
     return scale + unscaled
Exemple #6
0
 def serialize(byts, protocol_version):
     return varint_pack(byts)
Exemple #7
0
 def serialize(byts, protocol_version):
     return varint_pack(byts)