snarkvm_console_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<N: Network> ToBitsRaw for Plaintext<N> {
19    /// Returns this plaintext as a list of **little-endian** bits without variant or identifier bits.
20    fn write_bits_raw_le(&self, vec: &mut Vec<bool>) {
21        match self {
22            Self::Literal(literal, _) => {
23                // Extend the vector with the bits.
24                vec.extend_from_slice(&literal.to_bits_le())
25            }
26            Self::Struct(struct_, _) => {
27                // Write each value of the struct.
28                for (_, value) in struct_ {
29                    vec.extend_from_slice(&value.to_bits_raw_le());
30                }
31            }
32            Self::Array(array, _) => {
33                // Write each element of the array.
34                for element in array {
35                    vec.extend_from_slice(&element.to_bits_raw_le());
36                }
37            }
38        }
39    }
40
41    /// Returns this plaintext as a list of **big-endian** bits without variant or identifier bits.
42    fn write_bits_raw_be(&self, vec: &mut Vec<bool>) {
43        match self {
44            Self::Literal(literal, _) => {
45                // Extend the vector with the bits.
46                vec.extend_from_slice(&literal.to_bits_be())
47            }
48            Self::Struct(struct_, _) => {
49                // Write each value of the struct.
50                for (_, value) in struct_ {
51                    vec.extend_from_slice(&value.to_bits_raw_be());
52                }
53            }
54            Self::Array(array, _) => {
55                // Write each element of the array.
56                for element in array {
57                    // Write the element.
58                    vec.extend_from_slice(&element.to_bits_raw_be());
59                }
60            }
61        }
62    }
63}