// Decode this element starting at the index in the provided buffer
size_t HLAvariableArray::decodeFrom( const std::vector<Octet>& buffer, size_t index )
	throw( EncoderException )
{
	size_t available = buffer.size();
	if( index + BitHelpers::LENGTH_INT > available )
		throw EncoderException( L"Insufficient data in buffer to decode value" );

	// Decode received array size
	HLAinteger32BE size;
	index = size.decodeFrom( buffer, index );
	size_t receivedSize = size.get();

	// Resize to the new element count. This will either add element clones, or cull the end of
	// the existing list until it is the right size
	this->_impl->resize( receivedSize );

	// Decode all the elements!
	for( size_t i = 0 ; i < receivedSize ; ++i )
	{
		DataElement* element = this->_impl->get( i );
		index = element->decodeFrom( buffer, index );
	}

	return index;
}
// Decode this element starting at the index in the provided buffer
size_t HLAfixedArray::decodeFrom( const std::vector<Octet>& buffer, size_t index )
throw( EncoderException )
{
    size_t available = buffer.size();
    if( index + BitHelpers::LENGTH_INT > available )
        throw EncoderException( L"Insufficient data in buffer to decode value" );

    // Decode received array size
    HLAinteger32BE size;
    index = size.decodeFrom( buffer, index );

    size_t receivedSize = size.get();
    if( receivedSize != this->size() )
    {
        // Received array size was different to what we were expecting, so throw an exception
        std::wstringstream stream;
        stream << L"Element count in decoded array differs. Expected[" <<
               this->size() <<
               "] Received [" <<
               receivedSize << "]";

        throw EncoderException( stream.str() );
    }

    // Decode all the elements!
    for( size_t i = 0 ; i < receivedSize ; ++i )
    {
        DataElement* element = this->_impl->get( i );
        index = element->decodeFrom( buffer, index );
    }

    return index;
}
// Decode this element starting at the index in the provided buffer
size_t HLAfixedRecord::decodeFrom( const std::vector<Octet>& buffer, size_t index )
	throw( EncoderException )
{
	// Decode all the elements!
	for( size_t i = 0 ; i < this->size() ; ++i )
	{
		DataElement* element = this->_impl->get( i );
		index = element->decodeFrom( buffer, index );
	}

	return index;
}