// 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::RequestHeader;
use crate::service_types::AddReferencesItem;

/// Adds one or more references to the server address space.
#[derive(Debug, Clone, PartialEq)]
pub struct AddReferencesRequest {
    pub request_header: RequestHeader,
    pub references_to_add: Option<Vec<AddReferencesItem>>,
}

impl MessageInfo for AddReferencesRequest {
    fn object_id(&self) -> ObjectId {
        ObjectId::AddReferencesRequest_Encoding_DefaultBinary
    }
}

impl BinaryEncoder<AddReferencesRequest> for AddReferencesRequest {
    fn byte_len(&self) -> usize {
        let mut size = 0;
        size += self.request_header.byte_len();
        size += byte_len_array(&self.references_to_add);
        size
    }

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

    #[allow(unused_variables)]
    fn decode<S: Read>(stream: &mut S, decoding_limits: &DecodingLimits) -> EncodingResult<Self> {
        let request_header = RequestHeader::decode(stream, decoding_limits)?;
        let references_to_add: Option<Vec<AddReferencesItem>> = read_array(stream, decoding_limits)?;
        Ok(AddReferencesRequest {
            request_header,
            references_to_add,
        })
    }
}
