Skip to content

Commit 3e9617f

Browse files
committed
wip
1 parent f468e00 commit 3e9617f

7 files changed

Lines changed: 405 additions & 28 deletions

File tree

crates/core/src/host/instance_env.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use spacetimedb_table::indexes::RowPointer;
1919
use spacetimedb_table::table::RowRef;
2020
use std::ops::DerefMut;
2121
use std::sync::Arc;
22+
use std::vec::IntoIter;
2223

2324
#[derive(Clone)]
2425
pub struct InstanceEnv {
@@ -491,6 +492,33 @@ impl InstanceEnv {
491492

492493
Ok(chunks)
493494
}
495+
496+
pub fn fill_buffer_from_iter(
497+
iter: &mut IntoIter<Vec<u8>>,
498+
mut buffer: &mut [u8],
499+
chunk_pool: &mut ChunkPool,
500+
) -> usize {
501+
let mut written = 0;
502+
// Fill the buffer as much as possible.
503+
while let Some(chunk) = iter.as_slice().first() {
504+
let Some((buf_chunk, rest)) = buffer.split_at_mut_checked(chunk.len()) else {
505+
// Cannot fit chunk into the buffer,
506+
// either because we already filled it too much,
507+
// or because it is too small.
508+
break;
509+
};
510+
buf_chunk.copy_from_slice(chunk);
511+
written += chunk.len();
512+
buffer = rest;
513+
514+
// Advance the iterator, as we used a chunk.
515+
// SAFETY: We peeked one `chunk`, so there must be one at least.
516+
let chunk = unsafe { iter.next().unwrap_unchecked() };
517+
chunk_pool.put(chunk);
518+
}
519+
520+
written
521+
}
494522
}
495523

496524
impl TxSlot {

crates/core/src/host/module_common.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
use crate::{
55
energy::EnergyMonitor,
66
host::{
7-
module_host::{DynModule, ModuleInfo}, wasm_common::{module_host_actor::DescribeError, DESCRIBE_MODULE_DUNDER}, Scheduler
7+
module_host::{DynModule, ModuleInfo},
8+
wasm_common::{module_host_actor::DescribeError, DESCRIBE_MODULE_DUNDER},
9+
Scheduler,
810
},
911
module_host_context::ModuleCreationContext,
1012
replica_context::ReplicaContext,

crates/core/src/host/v8/de.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl de::Error for Error<'_> {
9292
}
9393

9494
/// Returns a scratch buffer to fill when deserializing strings.
95-
fn scratch_buf<const N: usize>() -> [MaybeUninit<u8>; N] {
95+
pub(crate) fn scratch_buf<const N: usize>() -> [MaybeUninit<u8>; N] {
9696
[const { MaybeUninit::uninit() }; N]
9797
}
9898

crates/core/src/host/v8/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ impl<'scope, M: IntoJsString> IntoException<'scope> for RangeError<M> {
5959
}
6060

6161
#[derive(Debug)]
62-
pub(super) struct ExceptionThrown {
62+
pub(crate) struct ExceptionThrown {
6363
_priv: (),
6464
}
6565

6666
/// A result where the error indicates that an exception has already been thrown in V8.
67-
pub(super) type ExcResult<T> = Result<T, ExceptionThrown>;
67+
pub(crate) type ExcResult<T> = Result<T, ExceptionThrown>;
6868

6969
/// Indicates that the JS side had thrown an exception.
7070
pub(super) fn exception_already_thrown() -> ExceptionThrown {

0 commit comments

Comments
 (0)