hiero_sdk/file/
file_contents_response.rs

1// SPDX-License-Identifier: Apache-2.0
2
3use hiero_sdk_proto::services;
4
5use crate::{
6    FileId,
7    FromProtobuf,
8};
9
10/// Response from [`FileContentsQuery`][crate::FileContentsQuery].
11#[derive(Debug, Clone)]
12pub struct FileContentsResponse {
13    /// The file ID of the file whose contents are being returned.
14    pub file_id: FileId,
15
16    // TODO: .contents vs .bytes (?)
17    /// The bytes contained in the file.
18    pub contents: Vec<u8>,
19}
20
21impl FromProtobuf<services::response::Response> for FileContentsResponse {
22    fn from_protobuf(pb: services::response::Response) -> crate::Result<Self>
23    where
24        Self: Sized,
25    {
26        let pb = pb_getv!(pb, FileGetContents, services::response::Response);
27        let file_contents = pb_getf!(pb, file_contents)?;
28        let file_id = pb_getf!(file_contents, file_id)?;
29
30        let contents = file_contents.contents;
31        let file_id = FileId::from_protobuf(file_id)?;
32
33        Ok(Self { file_id, contents })
34    }
35}