// 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::node_id::NodeId;
use crate::string::UAString;
use crate::data_types::MessageSecurityMode;
use crate::byte_string::ByteString;

#[derive(Debug, Clone, PartialEq)]
pub struct SessionSecurityDiagnosticsDataType {
    pub session_id: NodeId,
    pub client_user_id_of_session: UAString,
    pub client_user_id_history: Option<Vec<UAString>>,
    pub authentication_mechanism: UAString,
    pub encoding: UAString,
    pub transport_protocol: UAString,
    pub security_mode: MessageSecurityMode,
    pub security_policy_uri: UAString,
    pub client_certificate: ByteString,
}

impl MessageInfo for SessionSecurityDiagnosticsDataType {
    fn object_id(&self) -> ObjectId {
        ObjectId::SessionSecurityDiagnosticsDataType_Encoding_DefaultBinary
    }
}

impl BinaryEncoder<SessionSecurityDiagnosticsDataType> for SessionSecurityDiagnosticsDataType {
    fn byte_len(&self) -> usize {
        let mut size = 0;
        size += self.session_id.byte_len();
        size += self.client_user_id_of_session.byte_len();
        size += byte_len_array(&self.client_user_id_history);
        size += self.authentication_mechanism.byte_len();
        size += self.encoding.byte_len();
        size += self.transport_protocol.byte_len();
        size += self.security_mode.byte_len();
        size += self.security_policy_uri.byte_len();
        size += self.client_certificate.byte_len();
        size
    }

    #[allow(unused_variables)]
    fn encode<S: Write>(&self, stream: &mut S) -> EncodingResult<usize> {
        let mut size = 0;
        size += self.session_id.encode(stream)?;
        size += self.client_user_id_of_session.encode(stream)?;
        size += write_array(stream, &self.client_user_id_history)?;
        size += self.authentication_mechanism.encode(stream)?;
        size += self.encoding.encode(stream)?;
        size += self.transport_protocol.encode(stream)?;
        size += self.security_mode.encode(stream)?;
        size += self.security_policy_uri.encode(stream)?;
        size += self.client_certificate.encode(stream)?;
        Ok(size)
    }

    #[allow(unused_variables)]
    fn decode<S: Read>(stream: &mut S, decoding_limits: &DecodingLimits) -> EncodingResult<Self> {
        let session_id = NodeId::decode(stream, decoding_limits)?;
        let client_user_id_of_session = UAString::decode(stream, decoding_limits)?;
        let client_user_id_history: Option<Vec<UAString>> = read_array(stream, decoding_limits)?;
        let authentication_mechanism = UAString::decode(stream, decoding_limits)?;
        let encoding = UAString::decode(stream, decoding_limits)?;
        let transport_protocol = UAString::decode(stream, decoding_limits)?;
        let security_mode = MessageSecurityMode::decode(stream, decoding_limits)?;
        let security_policy_uri = UAString::decode(stream, decoding_limits)?;
        let client_certificate = ByteString::decode(stream, decoding_limits)?;
        Ok(SessionSecurityDiagnosticsDataType {
            session_id,
            client_user_id_of_session,
            client_user_id_history,
            authentication_mechanism,
            encoding,
            transport_protocol,
            security_mode,
            security_policy_uri,
            client_certificate,
        })
    }
}
