def putScaledInt(self, value): """Appends a Scaled Integer value to the message.""" scale = abs(value.as_tuple()[2]) valueStr = toSignedByteString(int(value * decimal.Decimal(10**scale))) packed = chr(protocol.SCALEDLEN0 + len(valueStr)) + chr(scale) + valueStr self.__output += packed return self
def putScaledDate(self, value): """Appends a Scaled Date value to the message.""" ticks = datatype.DateToTicks(value) valueStr = toSignedByteString(ticks) if len(valueStr) == 0: packed = chr(protocol.SCALEDDATELEN1) + chr(0) + chr(0) else: packed = chr(protocol.SCALEDDATELEN1 - 1 + len(valueStr)) + chr(0) + valueStr self.__output += packed return self
def putScaledTimestamp(self, value): """Appends a Scaled Timestamp value to the message.""" (ticks, scale) = datatype.TimestampToTicks(value) valueStr = toSignedByteString(ticks) if len(valueStr) == 0: packed = chr(protocol.SCALEDTIMESTAMPLEN1) + chr(0) + chr(0) else: packed = chr(protocol.SCALEDTIMESTAMPLEN1 - 1 + len(valueStr)) + chr(scale) + valueStr self.__output += packed return self
def putScaledInt(self, value): """ Appends a Scaled Integer value to the message. @type value decimal.Decimal """ scale = abs(value.as_tuple()[2]) valueStr = toSignedByteString(int(value * decimal.Decimal(10**scale))) packed = chr(protocol.SCALEDLEN0 + len(valueStr)) + chr(scale) + valueStr self.__output += packed return self
def putInt(self, value, isMessageId = False): """Appends an Integer value to the message.""" if value < 32 and value > -11: packed = chr(protocol.INT0 + value) else: if isMessageId: valueStr = toByteString(value) else: valueStr = toSignedByteString(value) packed = chr(protocol.INTLEN1 - 1 + len(valueStr)) + valueStr self.__output += packed return self
def putInt(self, value, isMessageId=False): """ Appends an Integer value to the message. @type value int @type isMessageId bool """ if value < 32 and value > -11: packed = chr(protocol.INT0 + value) else: if isMessageId: valueStr = toByteString(value) else: valueStr = toSignedByteString(value) packed = chr(protocol.INTLEN1 - 1 + len(valueStr)) + valueStr self.__output += packed return self
def putNsSinceEpoch(self, value): """Appends the NsSinceEpoch value to the message.""" valueStr = toSignedByteString(value) packed = chr(protocol.NANOSECLEN0 + len(valueStr)) + valueStr self.__output += packed return self