snarkvm_errors/serialization/
serialization.rs

1// Copyright (C) 2019-2021 Aleo Systems Inc.
2// This file is part of the snarkVM library.
3
4// The snarkVM library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The snarkVM library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the snarkVM library. If not, see <https://www.gnu.org/licenses/>.
16
17use std::io;
18
19#[derive(Error, Debug)]
20pub enum SerializationError {
21    /// During serialization, we didn't have enough space to write extra info.
22    #[error("the last byte does not have enough space to encode the extra info bits")]
23    NotEnoughSpace,
24    /// During serialization, the data was invalid.
25    #[error("the input buffer contained invalid data")]
26    InvalidData,
27    /// During serialization, non-empty flags were given where none were
28    /// expected.
29    #[error("the call expects empty flags")]
30    UnexpectedFlags,
31    /// During serialization, we countered an I/O error.
32    #[error("IoError: {0}")]
33    IoError(#[from] io::Error),
34    /// During serialization with bincode, we encountered a serialization issue
35    #[error(transparent)]
36    BincodeError(#[from] bincode::Error),
37}
38
39impl From<SerializationError> for std::io::Error {
40    fn from(error: SerializationError) -> Self {
41        std::io::Error::new(std::io::ErrorKind::Other, format!("{}", error))
42    }
43}