/// @return pointer to the first element
/// of class member data_
///
-const std::vector<uint8_t> message_t::get_data_vector(int start,int end) const
+const std::vector<uint8_t> message_t::get_data_vector(int start, int end) const
{
- std::vector<uint8_t> ret;
- if(start >= 0)
+ if ( start > length_ || end > length_ )
{
- if(end<length_)
- {
- for(int i=start;i<=end;i++)
- {
- ret.push_back(data_[i]);
- }
- }
- else
- {
- for(int i=start;i<length_;i++)
- {
- ret.push_back(data_[i]);
- }
- }
- }
- else
- {
- AFB_ERROR("Error index to get data vector, [%d-%d] - for length %d",start,end,length_);
+ AFB_ERROR("Error index to get data vector, [%d-%d] - for length %d", start, end, length_);
+ return data_;
}
+
+ std::vector<uint8_t>::const_iterator first = data_.begin() + start;
+ std::vector<uint8_t>::const_iterator last = data_.begin() + end;
+ std::vector<uint8_t> ret(first, last);
+
return ret;
}
void message_t::set_length(uint32_t length)
{
length_ = length;
-}
\ No newline at end of file
+}
+
+void message_t::frame_swap()
+{
+ int i;
+ uint8_t *temp = (uint8_t*)alloca(length_);
+
+ for(i = 0; i < length_; i++)
+ temp[i] = data_[length_ - i - 1];
+
+ memcpy(data_.data(), temp, length_);
+}