| 65 | # If encoding and sign bit is 1 (negative), flip all of the bits. Otherwise, just flip sign. |
| 66 | # If decoding and sign bit is 0 (negative), flip all of the bits. Otherwise, just flip sign. |
| 67 | def _float_adjust(v, encode): |
| 68 | if encode and six.indexbytes(v, 0) & 0x80 != 0x00: |
| 69 | return b''.join(map(lambda x: six.int2byte(x ^ 0xff), six.iterbytes(v))) |
| 70 | elif not encode and six.indexbytes(v, 0) & 0x80 != 0x80: |
| 71 | return b''.join(map(lambda x: six.int2byte(x ^ 0xff), six.iterbytes(v))) |
| 72 | else: |
| 73 | return six.int2byte(six.indexbytes(v, 0) ^ 0x80) + v[1:] |
| 74 | |
| 75 | |
| 76 | @functools.total_ordering |