MCPcopy Index your code
hub / github.com/RustPython/RustPython / from_bytes

Method from_bytes

crates/vm/src/builtins/int.rs:535–550  ·  view source on GitHub ↗
(
        cls: PyTypeRef,
        args: IntFromByteArgs,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

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> {

Callers

nothing calls this directly

Calls 1

as_bytesMethod · 0.45

Tested by

no test coverage detected