// 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::string::UAString;
use crate::basic_types::LocalizedText;
use crate::service_types::enums::ApplicationType;

/// The information required to register a server with a discovery server.
#[derive(Debug, Clone, PartialEq)]
pub struct RegisteredServer {
    pub server_uri: UAString,
    pub product_uri: UAString,
    pub server_names: Option<Vec<LocalizedText>>,
    pub server_type: ApplicationType,
    pub gateway_server_uri: UAString,
    pub discovery_urls: Option<Vec<UAString>>,
    pub semaphore_file_path: UAString,
    pub is_online: bool,
}

impl MessageInfo for RegisteredServer {
    fn object_id(&self) -> ObjectId {
        ObjectId::RegisteredServer_Encoding_DefaultBinary
    }
}

impl BinaryEncoder<RegisteredServer> for RegisteredServer {
    fn byte_len(&self) -> usize {
        let mut size = 0;
        size += self.server_uri.byte_len();
        size += self.product_uri.byte_len();
        size += byte_len_array(&self.server_names);
        size += self.server_type.byte_len();
        size += self.gateway_server_uri.byte_len();
        size += byte_len_array(&self.discovery_urls);
        size += self.semaphore_file_path.byte_len();
        size += self.is_online.byte_len();
        size
    }

    #[allow(unused_variables)]
    fn encode<S: Write>(&self, stream: &mut S) -> EncodingResult<usize> {
        let mut size = 0;
        size += self.server_uri.encode(stream)?;
        size += self.product_uri.encode(stream)?;
        size += write_array(stream, &self.server_names)?;
        size += self.server_type.encode(stream)?;
        size += self.gateway_server_uri.encode(stream)?;
        size += write_array(stream, &self.discovery_urls)?;
        size += self.semaphore_file_path.encode(stream)?;
        size += self.is_online.encode(stream)?;
        Ok(size)
    }

    #[allow(unused_variables)]
    fn decode<S: Read>(stream: &mut S, decoding_limits: &DecodingLimits) -> EncodingResult<Self> {
        let server_uri = UAString::decode(stream, decoding_limits)?;
        let product_uri = UAString::decode(stream, decoding_limits)?;
        let server_names: Option<Vec<LocalizedText>> = read_array(stream, decoding_limits)?;
        let server_type = ApplicationType::decode(stream, decoding_limits)?;
        let gateway_server_uri = UAString::decode(stream, decoding_limits)?;
        let discovery_urls: Option<Vec<UAString>> = read_array(stream, decoding_limits)?;
        let semaphore_file_path = UAString::decode(stream, decoding_limits)?;
        let is_online = bool::decode(stream, decoding_limits)?;
        Ok(RegisteredServer {
            server_uri,
            product_uri,
            server_names,
            server_type,
            gateway_server_uri,
            discovery_urls,
            semaphore_file_path,
            is_online,
        })
    }
}
