Skip to main content

co_api/
co_v1.rs

1// SPDX-License-Identifier: AGPL-3.0-only
2// Copyright (C) 2026 1io BRANDGUARDIAN GmbH
3
4#[cfg(target_arch = "wasm32")]
5#[link(wasm_import_module = "co_v1")]
6extern "C" {
7	/// Read block.
8	///
9	/// Returns the byte length of the block.
10	/// If the buffer_size is smaller than the returned byte length only the the first bytes until buffer_size are
11	/// placed in buffer. The caller may call this again with an larger buffer.
12	/// Also it is possible to call it with buffer_size=0 to only retrieve the size of the block.
13	pub fn storage_block_get(cid: *const u8, cid_size: u32, buffer: *mut u8, buffer_size: u32) -> u32;
14
15	/// Write block.
16	pub fn storage_block_set(cid: *const u8, cid_size: u32, buffer: *const u8, buffer_size: u32) -> u32;
17}
18
19/// Stub
20///
21/// # Safety
22/// This is only a stub to prevent mistakes.
23#[cfg(not(target_arch = "wasm32"))]
24pub unsafe extern "C" fn storage_block_get(
25	_cid: *const u8,
26	_cid_size: u32,
27	_buffer: *mut u8,
28	_buffer_size: u32,
29) -> u32 {
30	panic!("only available for target_arch = \"wasm32\"");
31}
32
33/// Stub
34///
35/// # Safety
36/// This is only a stub to prevent mistakes.
37#[cfg(not(target_arch = "wasm32"))]
38pub unsafe extern "C" fn storage_block_set(
39	_cid: *const u8,
40	_cid_size: u32,
41	_buffer: *const u8,
42	_buffer_size: u32,
43) -> u32 {
44	panic!("only available for target_arch = \"wasm32\"");
45}