コード例 #1
0
 def test_bcs_i128(self):
     self.assertEqual(
         bcs.serialize(st.int128(0x0102030405060708090A0B0C0D0E0F10),
                       st.int128),
         b"\x10\x0f\x0e\r\x0c\x0b\n\t\x08\x07\x06\x05\x04\x03\x02\x01",
     )
     self.assertEqual(bcs.deserialize(b"\xff" * 16, st.int128),
                      (st.int128(-1), b""))
コード例 #2
0
        st.int16(int.from_bytes(content[:2], byteorder="little", signed=True)),
        content[2:],
    ),
    st.int32:
    lambda content: (
        st.int32(int.from_bytes(content[:4], byteorder="little", signed=True)),
        content[4:],
    ),
    st.int64:
    lambda content: (
        st.int64(int.from_bytes(content[:8], byteorder="little", signed=True)),
        content[8:],
    ),
    st.int128:
    lambda content: (
        st.int128(int.from_bytes(content[:16], byteorder="little", signed=True)
                  ),
        content[16:],
    ),
    st.float32:
    lambda content: not_implemented(),
    st.float64:
    lambda content: not_implemented(),
    st.unit:
    lambda content: (None, content),
    st.char:
    lambda content: not_implemented(),
    str:
    lambda content: decode_str(content),
    bytes:
    lambda content: decode_bytes(content),
}
コード例 #3
0
 def deserialize_i128(self) -> st.int128:
     return st.int128(int.from_bytes(self.read(16), byteorder="little", signed=True))
コード例 #4
0
 def test_i128_negative(self):
     x = -2
     y = st.int128(x)
     self.assertEqual(y.high, -1)
     self.assertEqual(y.low, 0xFFFFFFFFFFFFFFFE)
     self.assertEqual(int(y), x)
コード例 #5
0
 def test_i128_positive(self):
     x = 0x0102030405060708090A0B0C0D0E0F10
     y = st.int128(x)
     self.assertEqual(y.high, 0x0102030405060708)
     self.assertEqual(y.low, 0x090A0B0C0D0E0F10)
     self.assertEqual(int(y), x)