storage
Non-Volatile Storage (NVS) bindings for ESP32 Provides persistent key-value storage across reboots using ESP32's NVS partition
- AssemblyScript
- Zig
- Rust
- TinyGo
- C
- C++
export enum StorageError {
Ok = 0,
NotInitialized = 1,
NotFound = 2,
InvalidArg = 3,
InvalidState = 4,
InvalidLength = 5,
NoMemory = 6,
ReadOnly = 7,
NotEnoughSpace = 8,
InvalidName = 9,
InvalidHandle = 10,
RemoveFailed = 11,
FlashError = 12,
CommitFailed = 13,
PartitionNotFound = 14
}
// @ts-ignore
@external("storage", "storage_get_string")
export declare function storageGetString(namespace: u32, key: u32, out: u32): StorageError;
// @ts-ignore
@external("storage", "storage_set_string")
export declare function storageSetString(namespace: u32, key: u32, value: u32): StorageError;
// @ts-ignore
@external("storage", "storage_get_u32")
export declare function storageGetU32(namespace: u32, key: u32, out: u32): StorageError;
// @ts-ignore
@external("storage", "storage_set_u32")
export declare function storageSetU32(namespace: u32, key: u32, value: u32): StorageError;
// @ts-ignore
@external("storage", "storage_get_u8")
export declare function storageGetU8(namespace: u32, key: u32, out: u32): StorageError;
// @ts-ignore
@external("storage", "storage_set_u8")
export declare function storageSetU8(namespace: u32, key: u32, value: undefined): StorageError;
// @ts-ignore
@external("storage", "storage_get_blob")
export declare function storageGetBlob(namespace: u32, key: u32, out: u32, size: u32): StorageError;
// @ts-ignore
@external("storage", "storage_set_blob")
export declare function storageSetBlob(namespace: u32, key: u32, data: u32, size: u32): StorageError;
pub const StorageError = enum(u32) {
ok = 0,
notInitialized = 1,
notFound = 2,
invalidArg = 3,
invalidState = 4,
invalidLength = 5,
noMemory = 6,
readOnly = 7,
notEnoughSpace = 8,
invalidName = 9,
invalidHandle = 10,
removeFailed = 11,
flashError = 12,
commitFailed = 13,
partitionNotFound = 14
};
pub extern "storage" fn storage_get_string(namespace: u32, key: u32, out: u32) StorageError;
pub extern "storage" fn storage_set_string(namespace: u32, key: u32, value: u32) StorageError;
pub extern "storage" fn storage_get_u32(namespace: u32, key: u32, out: u32) StorageError;
pub extern "storage" fn storage_set_u32(namespace: u32, key: u32, value: u32) StorageError;
pub extern "storage" fn storage_get_u8(namespace: u32, key: u32, out: u32) StorageError;
pub extern "storage" fn storage_set_u8(namespace: u32, key: u32, value: undefined) StorageError;
pub extern "storage" fn storage_get_blob(namespace: u32, key: u32, out: u32, size: u32) StorageError;
pub extern "storage" fn storage_set_blob(namespace: u32, key: u32, data: u32, size: u32) StorageError;
#[derive(Debug, Clone, Copy)]
#[repr(u32)]
pub enum StorageError {
Ok = 0,
NotInitialized = 1,
NotFound = 2,
InvalidArg = 3,
InvalidState = 4,
InvalidLength = 5,
NoMemory = 6,
ReadOnly = 7,
NotEnoughSpace = 8,
InvalidName = 9,
InvalidHandle = 10,
RemoveFailed = 11,
FlashError = 12,
CommitFailed = 13,
PartitionNotFound = 14
}
#[link(wasm_import_module = "storage")]
extern "C" {
#[link_name = "storage_get_string"]
fn unsafe_storage_get_string(namespace: u32, key: u32, out: u32) -> StorageError;
#[link_name = "storage_set_string"]
fn unsafe_storage_set_string(namespace: u32, key: u32, value: u32) -> StorageError;
#[link_name = "storage_get_u32"]
fn unsafe_storage_get_u32(namespace: u32, key: u32, out: u32) -> StorageError;
#[link_name = "storage_set_u32"]
fn unsafe_storage_set_u32(namespace: u32, key: u32, value: u32) -> StorageError;
#[link_name = "storage_get_u8"]
fn unsafe_storage_get_u8(namespace: u32, key: u32, out: u32) -> StorageError;
#[link_name = "storage_set_u8"]
fn unsafe_storage_set_u8(namespace: u32, key: u32, value: undefined) -> StorageError;
#[link_name = "storage_get_blob"]
fn unsafe_storage_get_blob(namespace: u32, key: u32, out: u32, size: u32) -> StorageError;
#[link_name = "storage_set_blob"]
fn unsafe_storage_set_blob(namespace: u32, key: u32, data: u32, size: u32) -> StorageError;
}
pub fn storage_get_string(namespace: u32, key: u32, out: u32) -> StorageError {
unsafe {
return unsafe_storage_get_string(namespace, key, out);
}
}
pub fn storage_set_string(namespace: u32, key: u32, value: u32) -> StorageError {
unsafe {
return unsafe_storage_set_string(namespace, key, value);
}
}
pub fn storage_get_u32(namespace: u32, key: u32, out: u32) -> StorageError {
unsafe {
return unsafe_storage_get_u32(namespace, key, out);
}
}
pub fn storage_set_u32(namespace: u32, key: u32, value: u32) -> StorageError {
unsafe {
return unsafe_storage_set_u32(namespace, key, value);
}
}
pub fn storage_get_u8(namespace: u32, key: u32, out: u32) -> StorageError {
unsafe {
return unsafe_storage_get_u8(namespace, key, out);
}
}
pub fn storage_set_u8(namespace: u32, key: u32, value: undefined) -> StorageError {
unsafe {
return unsafe_storage_set_u8(namespace, key, value);
}
}
pub fn storage_get_blob(namespace: u32, key: u32, out: u32, size: u32) -> StorageError {
unsafe {
return unsafe_storage_get_blob(namespace, key, out, size);
}
}
pub fn storage_set_blob(namespace: u32, key: u32, data: u32, size: u32) -> StorageError {
unsafe {
return unsafe_storage_set_blob(namespace, key, data, size);
}
}
package storage
type StorageError uint32
const (
Ok StorageError = 0
NotInitialized StorageError = 1
NotFound StorageError = 2
InvalidArg StorageError = 3
InvalidState StorageError = 4
InvalidLength StorageError = 5
NoMemory StorageError = 6
ReadOnly StorageError = 7
NotEnoughSpace StorageError = 8
InvalidName StorageError = 9
InvalidHandle StorageError = 10
RemoveFailed StorageError = 11
FlashError StorageError = 12
CommitFailed StorageError = 13
PartitionNotFound StorageError = 14
)
//go:wasmimport storage storage_get_string
func StorageGetString(Namespace uint32, Key uint32, Out uint32) uint32;
//go:wasmimport storage storage_set_string
func StorageSetString(Namespace uint32, Key uint32, Value uint32) uint32;
//go:wasmimport storage storage_get_u32
func StorageGetU32(Namespace uint32, Key uint32, Out uint32) uint32;
//go:wasmimport storage storage_set_u32
func StorageSetU32(Namespace uint32, Key uint32, Value uint32) uint32;
//go:wasmimport storage storage_get_u8
func StorageGetU8(Namespace uint32, Key uint32, Out uint32) uint32;
//go:wasmimport storage storage_set_u8
func StorageSetU8(Namespace uint32, Key uint32, Value undefined) uint32;
//go:wasmimport storage storage_get_blob
func StorageGetBlob(Namespace uint32, Key uint32, Out uint32, Size uint32) uint32;
//go:wasmimport storage storage_set_blob
func StorageSetBlob(Namespace uint32, Key uint32, Data uint32, Size uint32) uint32;
typedef enum {
STORAGE_ERROR_OK,
STORAGE_ERROR_NOT_INITIALIZED,
STORAGE_ERROR_NOT_FOUND,
STORAGE_ERROR_INVALID_ARG,
STORAGE_ERROR_INVALID_STATE,
STORAGE_ERROR_INVALID_LENGTH,
STORAGE_ERROR_NO_MEMORY,
STORAGE_ERROR_READ_ONLY,
STORAGE_ERROR_NOT_ENOUGH_SPACE,
STORAGE_ERROR_INVALID_NAME,
STORAGE_ERROR_INVALID_HANDLE,
STORAGE_ERROR_REMOVE_FAILED,
STORAGE_ERROR_FLASH_ERROR,
STORAGE_ERROR_COMMIT_FAILED,
STORAGE_ERROR_PARTITION_NOT_FOUND
} storage_error_t;
__attribute__((import_module("storage")))
__attribute__((import_name("storage_get_string")))
extern storage_error_t storage_get_string(unsigned int namespace, unsigned int key, unsigned int out);
__attribute__((import_module("storage")))
__attribute__((import_name("storage_set_string")))
extern storage_error_t storage_set_string(unsigned int namespace, unsigned int key, unsigned int value);
__attribute__((import_module("storage")))
__attribute__((import_name("storage_get_u32")))
extern storage_error_t storage_get_u32(unsigned int namespace, unsigned int key, unsigned int out);
__attribute__((import_module("storage")))
__attribute__((import_name("storage_set_u32")))
extern storage_error_t storage_set_u32(unsigned int namespace, unsigned int key, unsigned int value);
__attribute__((import_module("storage")))
__attribute__((import_name("storage_get_u8")))
extern storage_error_t storage_get_u8(unsigned int namespace, unsigned int key, unsigned int out);
__attribute__((import_module("storage")))
__attribute__((import_name("storage_set_u8")))
extern storage_error_t storage_set_u8(unsigned int namespace, unsigned int key, undefined value);
__attribute__((import_module("storage")))
__attribute__((import_name("storage_get_blob")))
extern storage_error_t storage_get_blob(unsigned int namespace, unsigned int key, unsigned int out, unsigned int size);
__attribute__((import_module("storage")))
__attribute__((import_name("storage_set_blob")))
extern storage_error_t storage_set_blob(unsigned int namespace, unsigned int key, unsigned int data, unsigned int size);
typedef enum {
STORAGE_ERROR_OK,
STORAGE_ERROR_NOT_INITIALIZED,
STORAGE_ERROR_NOT_FOUND,
STORAGE_ERROR_INVALID_ARG,
STORAGE_ERROR_INVALID_STATE,
STORAGE_ERROR_INVALID_LENGTH,
STORAGE_ERROR_NO_MEMORY,
STORAGE_ERROR_READ_ONLY,
STORAGE_ERROR_NOT_ENOUGH_SPACE,
STORAGE_ERROR_INVALID_NAME,
STORAGE_ERROR_INVALID_HANDLE,
STORAGE_ERROR_REMOVE_FAILED,
STORAGE_ERROR_FLASH_ERROR,
STORAGE_ERROR_COMMIT_FAILED,
STORAGE_ERROR_PARTITION_NOT_FOUND
} storage_error_t;
extern "C" {
__attribute__((import_module("storage")))
__attribute__((import_name("storage_get_string")))
extern storage_error_t storage_get_string(unsigned int namespace, unsigned int key, unsigned int out);
__attribute__((import_module("storage")))
__attribute__((import_name("storage_set_string")))
extern storage_error_t storage_set_string(unsigned int namespace, unsigned int key, unsigned int value);
__attribute__((import_module("storage")))
__attribute__((import_name("storage_get_u32")))
extern storage_error_t storage_get_u32(unsigned int namespace, unsigned int key, unsigned int out);
__attribute__((import_module("storage")))
__attribute__((import_name("storage_set_u32")))
extern storage_error_t storage_set_u32(unsigned int namespace, unsigned int key, unsigned int value);
__attribute__((import_module("storage")))
__attribute__((import_name("storage_get_u8")))
extern storage_error_t storage_get_u8(unsigned int namespace, unsigned int key, unsigned int out);
__attribute__((import_module("storage")))
__attribute__((import_name("storage_set_u8")))
extern storage_error_t storage_set_u8(unsigned int namespace, unsigned int key, undefined value);
__attribute__((import_module("storage")))
__attribute__((import_name("storage_get_blob")))
extern storage_error_t storage_get_blob(unsigned int namespace, unsigned int key, unsigned int out, unsigned int size);
__attribute__((import_module("storage")))
__attribute__((import_name("storage_set_blob")))
extern storage_error_t storage_set_blob(unsigned int namespace, unsigned int key, unsigned int data, unsigned int size);
}