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

Function concat

modules/llrt_buffer/src/buffer.rs:220–246  ·  view source on GitHub ↗
(ctx: Ctx<'js>, list: Array<'js>, max_length: Opt<usize>)

Source from the content-addressed store, hash-verified

218}
219
220fn concat<'js>(ctx: Ctx<'js>, list: Array<'js>, max_length: Opt<usize>) -> Result<Value<'js>> {
221 let mut bytes = Vec::new();
222 let mut total_length = 0;
223 let mut length;
224 for value in list.iter::<Object>() {
225 let typed_array = TypedArray::<u8>::from_object(value?)?;
226 let bytes_ref: &[u8] = typed_array.as_ref();
227
228 length = bytes_ref.len();
229
230 if length == 0 {
231 continue;
232 }
233
234 if let Some(max_length) = max_length.0 {
235 total_length += length;
236 if total_length > max_length {
237 let diff = max_length - (total_length - length);
238 bytes.extend_from_slice(&bytes_ref[0..diff]);
239 break;
240 }
241 }
242 bytes.extend_from_slice(bytes_ref);
243 }
244
245 Buffer(bytes).into_js(&ctx)
246}
247
248fn from<'js>(
249 ctx: Ctx<'js>,

Callers

nothing calls this directly

Calls 3

BufferClass · 0.70
lenMethod · 0.45
into_jsMethod · 0.45

Tested by

no test coverage detected