scamper/serialization
JSON serialization and deserialization for scamper FSMs.
Users must provide encoder/decoder functions for their custom state, context, and event types.
Types
Errors that can occur during serialization or deserialization.
pub type SerializationError {
JsonEncodeError(reason: String)
JsonDecodeError(reason: String)
}
Constructors
-
JsonEncodeError(reason: String) -
JsonDecodeError(reason: String)
Values
pub fn deserialize(
data: String,
config: config.Config(state, context, event),
state_decoder: decode.Decoder(state),
context_decoder: decode.Decoder(context),
event_decoder: decode.Decoder(event),
) -> Result(
scamper.Machine(state, context, event),
SerializationError,
)
Deserialize a machine from a JSON string and a config. User must provide decoder functions for state, context, and event types.
pub fn serialize(
machine: scamper.Machine(state, context, event),
state_encoder: fn(state) -> json.Json,
context_encoder: fn(context) -> json.Json,
event_encoder: fn(event) -> json.Json,
) -> String
Serialize a machine’s state to a JSON string. User must provide encoder functions for state, context, and event types.