Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-test-rhel8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# events but only for the master branch
on:
push:
branches: [ devel, release/**, ci/** ]
branches: [ devel, release/** ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ devel, release/** ]
Expand All @@ -20,7 +20,7 @@
Framework:
runs-on: ubuntu-latest
container:
image: redhat/ubi8:8.10

Check notice on line 23 in .github/workflows/build-test-rhel8.yml

View workflow job for this annotation

GitHub Actions / Check Spelling

`Line` matches candidate pattern `image: [-\w./:@]+` (candidate-pattern)
steps:
- name: "Install dependencies"
run: |
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/format-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: "Code Format Check"

on:
push:
branches: [ devel, release/**, ci/** ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ devel, release/** ]
paths-ignore:
- 'docs/**'
- '**.md'
- '.github/actions/spelling/**'
- '.github/ISSUE_TEMPLATE/**'

jobs:
cpp-formatting:
name: C++ Formatting
runs-on: ubuntu-22.04
steps:
- name: "Checkout F´ Repository"
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- name: "Setup Python"
uses: actions/setup-python@v5
with:
python-version: 3.12
- uses: ./.github/actions/setup
- name: "Check C++ Formatting"
env:
CHECKED_DIRS: >-
Fw/Buffer
Fw/Cmd
Fw/Com
run: |
fprime-util format --check --dirs $CHECKED_DIRS
shell: bash
58 changes: 24 additions & 34 deletions Fw/Buffer/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,28 @@
//
// ======================================================================
#include <Fw/Buffer/Buffer.hpp>
#include <Fw/Types/Assert.hpp>
#include <Fw/FPrimeBasicTypes.hpp>
#include <Fw/Types/Assert.hpp>

#if FW_SERIALIZABLE_TO_STRING
#include <Fw/Types/String.hpp>
#include <Fw/Types/String.hpp>
#endif
#include <cstring>

namespace Fw {

Buffer::Buffer(): Serializable(),
m_serialize_repr(),
m_bufferData(nullptr),
m_size(0),
m_context(0xFFFFFFFF)
{}

Buffer::Buffer(const Buffer& src) : Serializable(),
m_serialize_repr(),
m_bufferData(src.m_bufferData),
m_size(src.m_size),
m_context(src.m_context)
{
if(src.m_bufferData != nullptr){
Buffer::Buffer() : Serializable(), m_serialize_repr(), m_bufferData(nullptr), m_size(0), m_context(0xFFFFFFFF) {}

Check notice

Code scanning / CodeQL

More than one statement per line Note

This line contains 2 statements; only one is allowed.

Buffer::Buffer(const Buffer& src)
: Serializable(), m_serialize_repr(), m_bufferData(src.m_bufferData), m_size(src.m_size), m_context(src.m_context) {
if (src.m_bufferData != nullptr) {
this->m_serialize_repr.setExtBuffer(src.m_bufferData, src.m_size);
}
}

Buffer::Buffer(U8* data, SizeType size, U32 context) : Serializable(),
m_serialize_repr(),
m_bufferData(data),
m_size(size),
m_context(context)
{
if(m_bufferData != nullptr){
Buffer::Buffer(U8* data, SizeType size, U32 context)
: Serializable(), m_serialize_repr(), m_bufferData(data), m_size(size), m_context(context) {
if (m_bufferData != nullptr) {
this->m_serialize_repr.setExtBuffer(this->m_bufferData, this->m_size);
}
}
Expand All @@ -58,7 +45,8 @@
}

bool Buffer::operator==(const Buffer& src) const {
return (this->m_bufferData == src.m_bufferData) && (this->m_size == src.m_size) && (this->m_context == src.m_context);
return (this->m_bufferData == src.m_bufferData) && (this->m_size == src.m_size) &&
(this->m_context == src.m_context);
}

bool Buffer::isValid() const {
Expand Down Expand Up @@ -106,7 +94,8 @@

Fw::ExternalSerializeBufferWithMemberCopy Buffer::getSerializer() {
if (this->isValid()) {
Fw::ExternalSerializeBufferWithMemberCopy esb(this->m_bufferData, static_cast<Fw::Serializable::SizeType>(this->m_size));
Fw::ExternalSerializeBufferWithMemberCopy esb(this->m_bufferData,
static_cast<Fw::Serializable::SizeType>(this->m_size));
esb.resetSer();
return esb;
} else {
Expand All @@ -116,7 +105,8 @@

Fw::ExternalSerializeBufferWithMemberCopy Buffer::getDeserializer() {
if (this->isValid()) {
Fw::ExternalSerializeBufferWithMemberCopy esb(this->m_bufferData, static_cast<Fw::Serializable::SizeType>(this->m_size));
Fw::ExternalSerializeBufferWithMemberCopy esb(this->m_bufferData,
static_cast<Fw::Serializable::SizeType>(this->m_size));
Fw::SerializeStatus stat = esb.setBuffLen(static_cast<Fw::Serializable::SizeType>(this->m_size));
FW_ASSERT(stat == Fw::FW_SERIALIZE_OK);
return esb;
Expand Down Expand Up @@ -187,17 +177,17 @@

#if FW_SERIALIZABLE_TO_STRING
void Buffer::toString(Fw::StringBase& text) const {
static const char * formatString = "(data = %p, size = %u, context = %u)";
static const char* formatString = "(data = %p, size = %u, context = %u)";

Check notice

Code scanning / CodeQL

Use of basic integral type Note

formatString uses the basic integral type char rather than a typedef with size and signedness.
text.format(formatString, this->m_bufferData, this->m_size, this->m_context);
}
#endif

#ifdef BUILD_UT
std::ostream& operator<<(std::ostream& os, const Buffer& obj) {
Fw::String str;
obj.toString(str);
os << str.toChar();
return os;
}
std::ostream& operator<<(std::ostream& os, const Buffer& obj) {
Fw::String str;
obj.toString(str);
os << str.toChar();
return os;
}
#endif
} // end namespace Fw
} // end namespace Fw
44 changes: 20 additions & 24 deletions Fw/Buffer/Buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
#include <Fw/FPrimeBasicTypes.hpp>
#include <Fw/Types/Serializable.hpp>
#if FW_SERIALIZABLE_TO_STRING
#include <Fw/Types/StringType.hpp>
#ifdef BUILD_UT
#include <iostream>
#include <Fw/Types/String.hpp>
#endif
#include <Fw/Types/StringType.hpp>
#ifdef BUILD_UT
#include <Fw/Types/String.hpp>
#include <iostream>
#endif
#endif

// Forward declaration for UTs
namespace Fw { class BufferTester; }
namespace Fw {
class BufferTester;
}

namespace Fw {

Expand All @@ -43,17 +45,15 @@ namespace Fw {
//! prevent excessive copying.
//!
class Buffer : public Fw::Serializable {
friend class Fw::BufferTester;

friend class Fw::BufferTester;

public:

public:
//! The size type for a buffer
using SizeType = U32;

enum {
SERIALIZED_SIZE = sizeof(SizeType) + sizeof(U32) + sizeof(U8*), //!< Size of Fw::Buffer when serialized
NO_CONTEXT = 0xFFFFFFFF //!< Value representing no context
SERIALIZED_SIZE = sizeof(SizeType) + sizeof(U32) + sizeof(U8*), //!< Size of Fw::Buffer when serialized
NO_CONTEXT = 0xFFFFFFFF //!< Value representing no context
};

//! Construct a buffer with no context nor data
Expand All @@ -73,7 +73,7 @@ friend class Fw::BufferTester;
//! \param data: data pointer to wrap
//! \param size: size of data located at data pointer
//! \param context: user-specified context to track creation. Default: no context
Buffer(U8* data, SizeType size, U32 context=NO_CONTEXT);
Buffer(U8* data, SizeType size, U32 context = NO_CONTEXT);

//! Assignment operator to set given buffer's members from another without copying wrapped data
//!
Expand Down Expand Up @@ -110,7 +110,6 @@ friend class Fw::BufferTester;
//! \return representation of the wrapped data to aid in serializing to it
ExternalSerializeBufferWithMemberCopy getSerializer();


//! Returns a ExternalSerializeBufferWithMemberCopy representation of the wrapped data for deserializing
//!
//! \warning The entire buffer (up to getSize) is available for deserialization.
Expand Down Expand Up @@ -138,7 +137,6 @@ friend class Fw::BufferTester;
//! \return: status of serialization
Fw::SerializeStatus deserialize(Fw::SerializeBufferBase& buffer);


// ----------------------------------------------------------------------
// Accessor functions
// ----------------------------------------------------------------------
Expand Down Expand Up @@ -175,7 +173,7 @@ friend class Fw::BufferTester;
//! \param data: data pointer to wrap
//! \param size: size of data located at data pointer
//! \param context: user-specified context to track creation. Default: no context
void set(U8* data, SizeType size, U32 context=NO_CONTEXT);
void set(U8* data, SizeType size, U32 context = NO_CONTEXT);

#if FW_SERIALIZABLE_TO_STRING || BUILD_UT
//! Supports writing this buffer to a string representation
Expand All @@ -188,13 +186,11 @@ friend class Fw::BufferTester;
friend std::ostream& operator<<(std::ostream& os, const Buffer& obj);
#endif

private:
Fw::ExternalSerializeBuffer m_serialize_repr; //<! Representation for serialization and deserialization functions
U8* m_bufferData; //<! data - A pointer to the data
SizeType m_size; //<! size - The data size in bytes
U32 m_context; //!< Creation context for disposal

private:
Fw::ExternalSerializeBuffer m_serialize_repr; //<! Representation for serialization and deserialization functions
U8* m_bufferData; //<! data - A pointer to the data
SizeType m_size; //<! size - The data size in bytes
U32 m_context; //!< Creation context for disposal
};
} // end namespace Fw
} // end namespace Fw
#endif /* BUFFER_HPP_ */

Loading
Loading