| 533 | |
| 534 | #[pyclassmethod] |
| 535 | fn from_bytes( |
| 536 | cls: PyTypeRef, |
| 537 | args: IntFromByteArgs, |
| 538 | vm: &VirtualMachine, |
| 539 | ) -> PyResult<PyRef<Self>> { |
| 540 | let signed = args.signed.map_or(false, Into::into); |
| 541 | let value = match (args.byteorder, signed) { |
| 542 | (ArgByteOrder::Big, true) => BigInt::from_signed_bytes_be(args.bytes.as_bytes()), |
| 543 | (ArgByteOrder::Big, false) => BigInt::from_bytes_be(Sign::Plus, args.bytes.as_bytes()), |
| 544 | (ArgByteOrder::Little, true) => BigInt::from_signed_bytes_le(args.bytes.as_bytes()), |
| 545 | (ArgByteOrder::Little, false) => { |
| 546 | BigInt::from_bytes_le(Sign::Plus, args.bytes.as_bytes()) |
| 547 | } |
| 548 | }; |
| 549 | Self::with_value(cls, value, vm) |
| 550 | } |
| 551 | |
| 552 | #[pymethod] |
| 553 | fn to_bytes(&self, args: IntToByteArgs, vm: &VirtualMachine) -> PyResult<PyBytes> { |