F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
SerialBuffer.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title SerialBuffer.cpp
3 // \author bocchino
4 // \brief cpp file for SerialBuffer type
5 //
6 // \copyright
7 // Copyright (C) 2016 California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12 
14 #include "Fw/Types/Assert.hpp"
15 
16 namespace Fw {
17 
20  U8 *const data,
21  const U32 capacity
22  ) :
23  m_data(data),
24  m_capacity(capacity)
25  {
26 
27  }
28 
30  getBuffCapacity() const
31  {
32  return m_capacity;
33  }
34 
37  {
38  return m_data;
39  }
40 
42  getBuffAddr() const
43  {
44  return m_data;
45  }
46 
48  fill()
49  {
50  const SerializeStatus status = this->setBuffLen(this->m_capacity);
51  FW_ASSERT(status == FW_SERIALIZE_OK);
52  }
53 
55  pushBytes(const U8 *const addr, const NATIVE_UINT_TYPE n)
56  {
57  // "true" means "just push the bytes"
58  return this->serialize(const_cast<U8*>(addr), n, true);
59  }
60 
62  popBytes(U8 *const addr, NATIVE_UINT_TYPE n)
63  {
64  // "true" means "just pop the bytes"
65  return this->deserialize(addr, n, true);
66  }
67 
68 }
#define FW_ASSERT(...)
Definition: Assert.hpp:14
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:26
PlatformUIntType NATIVE_UINT_TYPE
Definition: BasicTypes.h:52
NATIVE_UINT_TYPE getBuffCapacity() const
returns capacity, not current size, of buffer
SerializeStatus popBytes(U8 *const addr, NATIVE_UINT_TYPE n)
Pop n bytes off the buffer.
SerializeStatus pushBytes(const U8 *const addr, const NATIVE_UINT_TYPE n)
Push n bytes onto the buffer.
void fill()
Fill the buffer to capacity with preexisting data.
SerialBuffer(U8 *const data, const U32 capacity)
U8 * getBuffAddr()
gets buffer address for data filling
SerializeStatus setBuffLen(NATIVE_UINT_TYPE length)
sets buffer length manually after filling with data
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
SerializeStatus serialize(U8 val)
serialize 8-bit unsigned int
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.