use satellite_base::types::VarType;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VariableDef {
pub id: u64,
#[serde(rename = "type")]
pub var_type: VarType,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Clause {
pub literals: Vec<i64>,
#[serde(rename = "type")]
pub clause_type: ClauseType,
#[serde(skip_serializing_if = "Option::is_none")]
pub lbd: Option<u32>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ClauseType {
Original,
Learned,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AbiConstraint {
pub name: String,
pub inputs: Vec<u64>,
pub code_hash: String,
#[serde(default)]
pub cached: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AdvancedCnf {
pub variables: Vec<VariableDef>,
pub clauses: Vec<Clause>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub abi_constraints: Vec<AbiConstraint>,
}
impl AdvancedCnf {
#[must_use]
pub fn new() -> Self {
Self {
variables: Vec::new(),
clauses: Vec::new(),
abi_constraints: Vec::new(),
}
}
pub fn from_json(json: &str) -> Result<Self, serde_json::Error> {
serde_json::from_str(json)
}
pub fn to_json(&self) -> Result<String, serde_json::Error> {
serde_json::to_string_pretty(self)
}
pub fn from_reader<R: std::io::Read>(reader: R) -> Result<Self, serde_json::Error> {
serde_json::from_reader(reader)
}
pub fn to_writer<W: std::io::Write>(&self, writer: W) -> Result<(), serde_json::Error> {
serde_json::to_writer_pretty(writer, self)
}
}
impl Default for AdvancedCnf {
fn default() -> Self {
Self::new()
}
}