Skip to content

Commit 8b0607e

Browse files
authored
Merge pull request #772 from jwest115/issue-759
Use dynamic serialized size for array records of structs and arrays
2 parents 87875ec + 0450568 commit 8b0607e

15 files changed

+77
-56
lines changed

compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentDataProducts.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,13 @@ case class ComponentDataProducts (
496496
| FW_ASSERT(sbPtr != nullptr);
497497
| sizeDelta += sbPtr->serializedTruncatedSize(stringSize);
498498
|}"""
499+
case ts: (Type.Array | Type.Struct) => {
500+
s"""|FwSizeType sizeDelta =
501+
| sizeof(FwDpIdType) + sizeof(FwSizeStoreType);
502+
|for (FwSizeType i = 0; i < size; i++) {
503+
| sizeDelta += array[i].serializedSize();
504+
|}"""
505+
}
499506
case _ =>
500507
val eltSize = if s.isPrimitive(t, typeName)
501508
then s"sizeof($typeName)"

compiler/tools/fpp-to-cpp/test/component/base/ActiveAsyncProductsComponentAc.ref.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,11 @@ Fw::SerializeStatus ActiveAsyncProductsComponentBase::DpContainer ::
103103
{
104104
FW_ASSERT(array != nullptr);
105105
// Compute the size delta
106-
const FwSizeType sizeDelta =
107-
sizeof(FwDpIdType) +
108-
sizeof(FwSizeStoreType) +
109-
size * ActiveAsyncProducts_Data::SERIALIZED_SIZE;
106+
FwSizeType sizeDelta =
107+
sizeof(FwDpIdType) + sizeof(FwSizeStoreType);
108+
for (FwSizeType i = 0; i < size; i++) {
109+
sizeDelta += array[i].serializedSize();
110+
}
110111
// Serialize the elements if they will fit
111112
Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK;
112113
if ((this->m_dataBuffer.getBuffLength() + sizeDelta) <= this->m_dataBuffer.getBuffCapacity()) {

compiler/tools/fpp-to-cpp/test/component/base/ActiveGetProductsComponentAc.ref.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ Fw::SerializeStatus ActiveGetProductsComponentBase::DpContainer ::
101101
{
102102
FW_ASSERT(array != nullptr);
103103
// Compute the size delta
104-
const FwSizeType sizeDelta =
105-
sizeof(FwDpIdType) +
106-
sizeof(FwSizeStoreType) +
107-
size * ActiveGetProducts_Data::SERIALIZED_SIZE;
104+
FwSizeType sizeDelta =
105+
sizeof(FwDpIdType) + sizeof(FwSizeStoreType);
106+
for (FwSizeType i = 0; i < size; i++) {
107+
sizeDelta += array[i].serializedSize();
108+
}
108109
// Serialize the elements if they will fit
109110
Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK;
110111
if ((this->m_dataBuffer.getBuffLength() + sizeDelta) <= this->m_dataBuffer.getBuffCapacity()) {

compiler/tools/fpp-to-cpp/test/component/base/ActiveGuardedProductsComponentAc.ref.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ Fw::SerializeStatus ActiveGuardedProductsComponentBase::DpContainer ::
101101
{
102102
FW_ASSERT(array != nullptr);
103103
// Compute the size delta
104-
const FwSizeType sizeDelta =
105-
sizeof(FwDpIdType) +
106-
sizeof(FwSizeStoreType) +
107-
size * ActiveGuardedProducts_Data::SERIALIZED_SIZE;
104+
FwSizeType sizeDelta =
105+
sizeof(FwDpIdType) + sizeof(FwSizeStoreType);
106+
for (FwSizeType i = 0; i < size; i++) {
107+
sizeDelta += array[i].serializedSize();
108+
}
108109
// Serialize the elements if they will fit
109110
Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK;
110111
if ((this->m_dataBuffer.getBuffLength() + sizeDelta) <= this->m_dataBuffer.getBuffCapacity()) {

compiler/tools/fpp-to-cpp/test/component/base/ActiveSyncProductsComponentAc.ref.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ Fw::SerializeStatus ActiveSyncProductsComponentBase::DpContainer ::
101101
{
102102
FW_ASSERT(array != nullptr);
103103
// Compute the size delta
104-
const FwSizeType sizeDelta =
105-
sizeof(FwDpIdType) +
106-
sizeof(FwSizeStoreType) +
107-
size * ActiveSyncProducts_Data::SERIALIZED_SIZE;
104+
FwSizeType sizeDelta =
105+
sizeof(FwDpIdType) + sizeof(FwSizeStoreType);
106+
for (FwSizeType i = 0; i < size; i++) {
107+
sizeDelta += array[i].serializedSize();
108+
}
108109
// Serialize the elements if they will fit
109110
Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK;
110111
if ((this->m_dataBuffer.getBuffLength() + sizeDelta) <= this->m_dataBuffer.getBuffCapacity()) {

compiler/tools/fpp-to-cpp/test/component/base/ActiveTestComponentAc.ref.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,11 @@ namespace M {
139139
{
140140
FW_ASSERT(array != nullptr);
141141
// Compute the size delta
142-
const FwSizeType sizeDelta =
143-
sizeof(FwDpIdType) +
144-
sizeof(FwSizeStoreType) +
145-
size * M::ActiveTest_Data::SERIALIZED_SIZE;
142+
FwSizeType sizeDelta =
143+
sizeof(FwDpIdType) + sizeof(FwSizeStoreType);
144+
for (FwSizeType i = 0; i < size; i++) {
145+
sizeDelta += array[i].serializedSize();
146+
}
146147
// Serialize the elements if they will fit
147148
Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK;
148149
if ((this->m_dataBuffer.getBuffLength() + sizeDelta) <= this->m_dataBuffer.getBuffCapacity()) {

compiler/tools/fpp-to-cpp/test/component/base/PassiveGetProductsComponentAc.ref.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ Fw::SerializeStatus PassiveGetProductsComponentBase::DpContainer ::
4343
{
4444
FW_ASSERT(array != nullptr);
4545
// Compute the size delta
46-
const FwSizeType sizeDelta =
47-
sizeof(FwDpIdType) +
48-
sizeof(FwSizeStoreType) +
49-
size * PassiveGetProducts_Data::SERIALIZED_SIZE;
46+
FwSizeType sizeDelta =
47+
sizeof(FwDpIdType) + sizeof(FwSizeStoreType);
48+
for (FwSizeType i = 0; i < size; i++) {
49+
sizeDelta += array[i].serializedSize();
50+
}
5051
// Serialize the elements if they will fit
5152
Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK;
5253
if ((this->m_dataBuffer.getBuffLength() + sizeDelta) <= this->m_dataBuffer.getBuffCapacity()) {

compiler/tools/fpp-to-cpp/test/component/base/PassiveGuardedProductsComponentAc.ref.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ Fw::SerializeStatus PassiveGuardedProductsComponentBase::DpContainer ::
4343
{
4444
FW_ASSERT(array != nullptr);
4545
// Compute the size delta
46-
const FwSizeType sizeDelta =
47-
sizeof(FwDpIdType) +
48-
sizeof(FwSizeStoreType) +
49-
size * PassiveGuardedProducts_Data::SERIALIZED_SIZE;
46+
FwSizeType sizeDelta =
47+
sizeof(FwDpIdType) + sizeof(FwSizeStoreType);
48+
for (FwSizeType i = 0; i < size; i++) {
49+
sizeDelta += array[i].serializedSize();
50+
}
5051
// Serialize the elements if they will fit
5152
Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK;
5253
if ((this->m_dataBuffer.getBuffLength() + sizeDelta) <= this->m_dataBuffer.getBuffCapacity()) {

compiler/tools/fpp-to-cpp/test/component/base/PassiveSyncProductsComponentAc.ref.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ Fw::SerializeStatus PassiveSyncProductsComponentBase::DpContainer ::
4343
{
4444
FW_ASSERT(array != nullptr);
4545
// Compute the size delta
46-
const FwSizeType sizeDelta =
47-
sizeof(FwDpIdType) +
48-
sizeof(FwSizeStoreType) +
49-
size * PassiveSyncProducts_Data::SERIALIZED_SIZE;
46+
FwSizeType sizeDelta =
47+
sizeof(FwDpIdType) + sizeof(FwSizeStoreType);
48+
for (FwSizeType i = 0; i < size; i++) {
49+
sizeDelta += array[i].serializedSize();
50+
}
5051
// Serialize the elements if they will fit
5152
Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK;
5253
if ((this->m_dataBuffer.getBuffLength() + sizeDelta) <= this->m_dataBuffer.getBuffCapacity()) {

compiler/tools/fpp-to-cpp/test/component/base/PassiveTestComponentAc.ref.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ Fw::SerializeStatus PassiveTestComponentBase::DpContainer ::
4343
{
4444
FW_ASSERT(array != nullptr);
4545
// Compute the size delta
46-
const FwSizeType sizeDelta =
47-
sizeof(FwDpIdType) +
48-
sizeof(FwSizeStoreType) +
49-
size * PassiveTest_Data::SERIALIZED_SIZE;
46+
FwSizeType sizeDelta =
47+
sizeof(FwDpIdType) + sizeof(FwSizeStoreType);
48+
for (FwSizeType i = 0; i < size; i++) {
49+
sizeDelta += array[i].serializedSize();
50+
}
5051
// Serialize the elements if they will fit
5152
Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK;
5253
if ((this->m_dataBuffer.getBuffLength() + sizeDelta) <= this->m_dataBuffer.getBuffCapacity()) {

0 commit comments

Comments
 (0)