1#[derive(Debug, Clone, PartialEq, Eq)]
2pub enum Value {
3 MScalar { size_in_bits: usize },
4 MFloat { size_in_bits: usize },
5 MBool,
6 Scalar { size_in_bits: usize },
7 Float { size_in_bits: usize },
8 Bool,
9 Ciphertext { size_in_bits: usize },
10 PublicKey { size_in_bits: usize },
11 Point,
12 Array(Vec<Value>),
13 Tuple(Vec<Value>),
14 Struct(Vec<Value>),
15}
16
17impl Value {
18 pub fn size_in_scalars(&self) -> usize {
19 match self {
20 Self::MScalar { .. } => 1,
21 Self::MFloat { .. } => 1,
22 Self::Scalar { .. } => 1,
23 Self::Float { .. } => 1,
24 Self::MBool { .. } => 1,
25 Self::Bool { .. } => 1,
26 Self::Ciphertext { .. } => 1,
27 Self::PublicKey { .. } => 1,
28 Self::Point { .. } => 1,
29 Self::Array(c) | Self::Tuple(c) | Self::Struct(c) => {
30 c.iter().fold(0, |acc, x| acc + x.size_in_scalars())
31 }
32 }
33 }
34
35 pub fn flatten(&self) -> Vec<Value> {
36 match self {
37 Self::Array(c) | Self::Tuple(c) | Self::Struct(c) => {
38 let mut v = Vec::new();
39 for a in c {
40 v.extend(a.flatten());
41 }
42 v
43 }
44 _ => vec![self.clone()],
45 }
46 }
47}
48
49#[derive(Debug, serde::Serialize)]
50pub struct CircuitInterface {
51 pub name: String,
52 pub inputs: Vec<Value>,
53 pub outputs: Vec<Value>,
54}
55
56impl CircuitInterface {
57 pub fn new(name: String, inputs: Vec<Value>, outputs: Vec<Value>) -> Self {
58 Self {
59 name,
60 inputs,
61 outputs,
62 }
63 }
64
65 pub fn serialize(&self) -> Result<String, serde_json::Error> {
66 serde_json::to_string(self)
67 }
68
69 pub fn from_json(input: &str) -> Result<Self, serde_json::Error> {
70 serde_json::from_str(input)
71 }
72}