snarkvm_circuit_program/data/plaintext/
to_bits_raw.rs

1// Copyright (c) 2019-2025 Provable Inc.
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use super::*;
17
18impl<A: Aleo> ToBitsRaw for Plaintext<A> {
19    /// Returns this plaintext as a list of raw **little-endian** bits.
20    fn write_bits_raw_le(&self, vec: &mut Vec<Boolean<A>>) {
21        match self {
22            Self::Literal(literal, _) => {
23                // Extend the vector with the bits of the literal.
24                vec.extend_from_slice(&literal.to_bits_le());
25            }
26            Self::Struct(members, _) => {
27                // Compute the bits of the struct.
28                for (_, value) in members {
29                    vec.extend(value.to_bits_raw_le());
30                }
31            }
32            Self::Array(elements, _) => {
33                // Compute the bits of the array.
34                for value in elements {
35                    vec.extend(value.to_bits_raw_le());
36                }
37            }
38        }
39    }
40
41    /// Returns this plaintext as a list of raw **big-endian** bits.
42    fn write_bits_raw_be(&self, vec: &mut Vec<Boolean<A>>) {
43        match self {
44            Self::Literal(literal, _) => {
45                // Extend the vector with the bits of the literal.
46                vec.extend_from_slice(&literal.to_bits_be());
47            }
48            Self::Struct(members, _) => {
49                // Compute the bits of the struct.
50                for (_, value) in members {
51                    vec.extend(value.to_bits_raw_be());
52                }
53            }
54            Self::Array(elements, _) => {
55                // Compute the bits of the array.
56                for value in elements {
57                    vec.extend(value.to_bits_raw_be());
58                }
59            }
60        }
61    }
62}