MCPcopy Create free account
hub / github.com/awslabs/llrt / write_buf

Function write_buf

modules/llrt_buffer/src/buffer.rs:597–690  ·  view source on GitHub ↗
(
    this: &This<Object<'js>>,
    ctx: &Ctx<'js>,
    value: &Value<'js>,
    offset: &Opt<usize>,
    endian: Endian,
    kind: NumberKind,
)

Source from the content-addressed store, hash-verified

595 NumberKind::Int8 => &[(Endian::Little, "Int8", None)],
596 NumberKind::UInt8 => &[(Endian::Little, "UInt8", Some("Uint8"))],
597 NumberKind::Int16 => &[
598 (Endian::Little, "Int16LE", None),
599 (Endian::Big, "Int16BE", None),
600 ],
601 NumberKind::UInt16 => &[
602 (Endian::Little, "UInt16LE", Some("Uint16LE")),
603 (Endian::Big, "UInt16BE", Some("Uint16BE")),
604 ],
605 NumberKind::Int32 => &[
606 (Endian::Little, "Int32LE", None),
607 (Endian::Big, "Int32BE", None),
608 ],
609 NumberKind::UInt32 => &[
610 (Endian::Little, "UInt32LE", Some("Uint32LE")),
611 (Endian::Big, "UInt32BE", Some("Uint32BE")),
612 ],
613 NumberKind::Float32 => &[
614 (Endian::Little, "FloatLE", None),
615 (Endian::Big, "FloatBE", None),
616 ],
617 NumberKind::Float64 => &[
618 (Endian::Little, "DoubleLE", None),
619 (Endian::Big, "DoubleBE", None),
620 ],
621 NumberKind::BigInt => &[
622 (Endian::Little, "BigInt64LE", None),
623 (Endian::Big, "BigInt64BE", None),
624 ],
625 NumberKind::BigUInt => &[
626 (Endian::Little, "BigUInt64LE", Some("BigUint64LE")),
627 (Endian::Big, "BigUInt64BE", Some("BigUint64BE")),
628 ],
629 }
630 }
631}
632
633iterable_enum!(
634 NumberKind, Int8, UInt8, Int16, UInt16, Int32, UInt32, Float32, Float64, BigInt, BigUInt
635);
636
637#[allow(clippy::too_many_arguments)]
638fn write_buf<'js>(
639 this: &This<Object<'js>>,
640 ctx: &Ctx<'js>,
641 value: &Value<'js>,
642 offset: &Opt<usize>,
643 endian: Endian,
644 kind: NumberKind,
645) -> Result<usize> {
646 let offset = offset.0.unwrap_or_default();
647
648 // Extract and convert value
649 let (byte_count, bytes) = match kind {
650 NumberKind::BigInt => {
651 let Some(bigint) = value.as_big_int() else {
652 return Err(Exception::throw_type(ctx, "Expected BigInt"));
653 };
654 let (byte_count, val) = (8, bigint.clone().to_i64().or_throw(ctx)? as u64);

Callers 1

set_prototypeFunction · 0.85

Calls 10

endian_bytesFunction · 0.85
shifted_bytesFunction · 0.85
fromFunction · 0.85
or_throwMethod · 0.80
as_numberMethod · 0.80
bitsMethod · 0.80
is_signedMethod · 0.80
cloneMethod · 0.45
lenMethod · 0.45
get_array_bufferMethod · 0.45

Tested by

no test coverage detected