/ console / program / src / data / plaintext / to_bits_raw.rs
to_bits_raw.rs
 1  // Copyright (c) 2025-2026 ACDC Network
 2  // This file is part of the alphavm library.
 3  //
 4  // Alpha Chain | Delta Chain Protocol
 5  // International Monetary Graphite.
 6  //
 7  // Derived from Aleo (https://aleo.org) and ProvableHQ (https://provable.com).
 8  // They built world-class ZK infrastructure. We installed the EASY button.
 9  // Their cryptography: elegant. Our modifications: bureaucracy-compatible.
10  // Original brilliance: theirs. Robert's Rules: ours. Bugs: definitely ours.
11  //
12  // Original Aleo/ProvableHQ code subject to Apache 2.0 https://www.apache.org/licenses/LICENSE-2.0
13  // All modifications and new work: CC0 1.0 Universal Public Domain Dedication.
14  // No rights reserved. No permission required. No warranty. No refunds.
15  //
16  // https://creativecommons.org/publicdomain/zero/1.0/
17  // SPDX-License-Identifier: CC0-1.0
18  
19  use super::*;
20  
21  impl<N: Network> ToBitsRaw for Plaintext<N> {
22      /// Returns this plaintext as a list of **little-endian** bits without variant or identifier bits.
23      fn write_bits_raw_le(&self, vec: &mut Vec<bool>) {
24          match self {
25              Self::Literal(literal, _) => {
26                  // Extend the vector with the bits.
27                  vec.extend_from_slice(&literal.to_bits_le())
28              }
29              Self::Struct(struct_, _) => {
30                  // Write each value of the struct.
31                  for (_, value) in struct_ {
32                      vec.extend_from_slice(&value.to_bits_raw_le());
33                  }
34              }
35              Self::Array(array, _) => {
36                  // Write each element of the array.
37                  for element in array {
38                      vec.extend_from_slice(&element.to_bits_raw_le());
39                  }
40              }
41          }
42      }
43  
44      /// Returns this plaintext as a list of **big-endian** bits without variant or identifier bits.
45      fn write_bits_raw_be(&self, vec: &mut Vec<bool>) {
46          match self {
47              Self::Literal(literal, _) => {
48                  // Extend the vector with the bits.
49                  vec.extend_from_slice(&literal.to_bits_be())
50              }
51              Self::Struct(struct_, _) => {
52                  // Write each value of the struct.
53                  for (_, value) in struct_ {
54                      vec.extend_from_slice(&value.to_bits_raw_be());
55                  }
56              }
57              Self::Array(array, _) => {
58                  // Write each element of the array.
59                  for element in array {
60                      // Write the element.
61                      vec.extend_from_slice(&element.to_bits_raw_be());
62                  }
63              }
64          }
65      }
66  }