// This file was autogenerated from Opc.Ua.Types.bsd.xml by tools/schema/gen_types.js
// DO NOT EDIT THIS FILE

use std::io::{Read, Write};

use crate::encoding::*;
#[allow(unused_imports)]
use crate::basic_types::*;
use crate::service_types::impls::MessageInfo;
use crate::node_ids::ObjectId;
use crate::service_types::impls::ResponseHeader;
use crate::byte_string::ByteString;
use crate::diagnostic_info::DiagnosticInfo;
use crate::service_types::QueryDataSet;
use crate::service_types::ParsingResult;
use crate::service_types::ContentFilterResult;

#[derive(Debug, Clone, PartialEq)]
pub struct QueryFirstResponse {
    pub response_header: ResponseHeader,
    pub query_data_sets: Option<Vec<QueryDataSet>>,
    pub continuation_point: ByteString,
    pub parsing_results: Option<Vec<ParsingResult>>,
    pub diagnostic_infos: Option<Vec<DiagnosticInfo>>,
    pub filter_result: ContentFilterResult,
}

impl MessageInfo for QueryFirstResponse {
    fn object_id(&self) -> ObjectId {
        ObjectId::QueryFirstResponse_Encoding_DefaultBinary
    }
}

impl BinaryEncoder<QueryFirstResponse> for QueryFirstResponse {
    fn byte_len(&self) -> usize {
        let mut size = 0;
        size += self.response_header.byte_len();
        size += byte_len_array(&self.query_data_sets);
        size += self.continuation_point.byte_len();
        size += byte_len_array(&self.parsing_results);
        size += byte_len_array(&self.diagnostic_infos);
        size += self.filter_result.byte_len();
        size
    }

    #[allow(unused_variables)]
    fn encode<S: Write>(&self, stream: &mut S) -> EncodingResult<usize> {
        let mut size = 0;
        size += self.response_header.encode(stream)?;
        size += write_array(stream, &self.query_data_sets)?;
        size += self.continuation_point.encode(stream)?;
        size += write_array(stream, &self.parsing_results)?;
        size += write_array(stream, &self.diagnostic_infos)?;
        size += self.filter_result.encode(stream)?;
        Ok(size)
    }

    #[allow(unused_variables)]
    fn decode<S: Read>(stream: &mut S, decoding_limits: &DecodingLimits) -> EncodingResult<Self> {
        let response_header = ResponseHeader::decode(stream, decoding_limits)?;
        let query_data_sets: Option<Vec<QueryDataSet>> = read_array(stream, decoding_limits)?;
        let continuation_point = ByteString::decode(stream, decoding_limits)?;
        let parsing_results: Option<Vec<ParsingResult>> = read_array(stream, decoding_limits)?;
        let diagnostic_infos: Option<Vec<DiagnosticInfo>> = read_array(stream, decoding_limits)?;
        let filter_result = ContentFilterResult::decode(stream, decoding_limits)?;
        Ok(QueryFirstResponse {
            response_header,
            query_data_sets,
            continuation_point,
            parsing_results,
            diagnostic_infos,
            filter_result,
        })
    }
}
