1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2025 ReifyDB
//! Utility functions for stateful FFI operators
//!
//! This module provides helper functions for working with state in FFI operators,
//! mirroring the functionality available to internal operators.
use ;
use crate::;
/// Create an empty key for single-state operators
///
/// This is useful for operators that only need a single state value
/// (like counters or accumulators).
///
/// # Example
///
/// ```ignore
/// let key = empty_key();
/// let value = ctx.state().get(&key)?;
/// ```
/// Load state for a key, creating with default values if it doesn't exist
///
/// This is a common pattern where you want to ensure a state row exists,
/// initializing it with defaults if it's the first access.
///
/// # Arguments
///
/// * `ctx` - The operator context
/// * `key` - The key to load
/// * `schema` - The schema defining the structure and default values
///
/// # Example
///
/// ```ignore
/// let schema = Schema::testing(&[Type::Int32, Type::Float8]);
/// let row = load_or_create_row(ctx, &key, &schema)?;
/// ```
/// Save a state row
///
/// This is a convenience wrapper around `ctx.state().set()` for saving
/// encoded values.
///
/// # Arguments
///
/// * `ctx` - The operator context
/// * `key` - The key to save under
/// * `row` - The encoded values to save
///
/// # Example
///
/// ```ignore
/// let row = EncodedValues::new(data);
/// save_row(ctx, &key, row)?;
/// ```