eclipse-wakaama / wakaama

Eclipse Wakaama is a C implementation of the Open Mobile Alliance's LightWeight M2M protocol (LWM2M).
BSD 3-Clause "New" or "Revised" License
498 stars 374 forks source link

Fixed buffer size in senml_json_serialize limits handling of multiple resources #772

Open sergioGras opened 5 months ago

sergioGras commented 5 months ago

Description The senml_json_serialize function uses a statically allocated buffer (uint8_t bufferJSON[PRV_JSON_BUFFER_SIZE];), which may not be sufficient for operations involving multiple resources or large data sets, for example reading an object with multiple instances.

Issue If the serialized data exceeds the PRV_JSON_BUFFER_SIZE, serialization failures occur, affecting the ability of the protocol to efficiently handle larger or multiple resource transmissions.

Suggested Enhancement Consider implementing dynamic buffer allocation or a more flexible buffer management strategy to accommodate varying payload sizes, enabling robust and scalable data management according to LwM2M specifications.

Would appreciate further insights or suggestions on this approach.

LukasWoodtli commented 4 months ago

I suppose it was implemented that way because of the use of Wakaama in embedded systems. It's often considered bad practice to dynamically allocate memory in embedded systems. Some of the reasons are memory fragmentation and out of memory problems. In some cases, dynamic memory is only allocated at startup to recognise memory problems early.

Generally we have some use of dynamic memory allocation in Wakaama. We should just use it sprasingly and with care.