satellite_format/
advanced_cnf.rs1use satellite_base::types::VarType;
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct VariableDef {
11 pub id: u64,
13 #[serde(rename = "type")]
15 pub var_type: VarType,
16 #[serde(skip_serializing_if = "Option::is_none")]
18 pub name: Option<String>,
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct Clause {
24 pub literals: Vec<i64>,
26 #[serde(rename = "type")]
28 pub clause_type: ClauseType,
29 #[serde(skip_serializing_if = "Option::is_none")]
31 pub lbd: Option<u32>,
32}
33
34#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
36#[serde(rename_all = "lowercase")]
37pub enum ClauseType {
38 Original,
39 Learned,
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct AbiConstraint {
45 pub name: String,
47 pub inputs: Vec<u64>,
49 pub code_hash: String,
51 #[serde(default)]
53 pub cached: bool,
54}
55
56#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct AdvancedCnf {
59 pub variables: Vec<VariableDef>,
61 pub clauses: Vec<Clause>,
63 #[serde(default, skip_serializing_if = "Vec::is_empty")]
65 pub abi_constraints: Vec<AbiConstraint>,
66}
67
68impl AdvancedCnf {
69 #[must_use]
71 pub fn new() -> Self {
72 Self {
73 variables: Vec::new(),
74 clauses: Vec::new(),
75 abi_constraints: Vec::new(),
76 }
77 }
78
79 pub fn from_json(json: &str) -> Result<Self, serde_json::Error> {
81 serde_json::from_str(json)
82 }
83
84 pub fn to_json(&self) -> Result<String, serde_json::Error> {
86 serde_json::to_string_pretty(self)
87 }
88
89 pub fn from_reader<R: std::io::Read>(reader: R) -> Result<Self, serde_json::Error> {
91 serde_json::from_reader(reader)
92 }
93
94 pub fn to_writer<W: std::io::Write>(&self, writer: W) -> Result<(), serde_json::Error> {
96 serde_json::to_writer_pretty(writer, self)
97 }
98}
99
100impl Default for AdvancedCnf {
101 fn default() -> Self {
102 Self::new()
103 }
104}