thesolarnomad / lora-serialization

LoraWAN serialization/deserialization library for The Things Network
MIT License
164 stars 26 forks source link

Missing LoraEncoder::getLength() #50

Closed matthias-bs closed 1 year ago

matthias-bs commented 1 year ago

I am using LoraEncoder instead of LoraMessage, because a statically allocated buffer is perfectly fine for me. Having a getLength() method would be greatly appreciated!

In my application, the data written to the buffer is configuration-dependent and I would like to avoid counting bytes in a second place.

joscha commented 1 year ago

I don't see why we can't have a method like that, do you want to open a pull request?

matthias-bs commented 1 year ago

Sure! Which approach would you prefer: keeping a variable size separately from the buffer or use a variable offset which is also used as follows:

void LoraEncoder::writeUint32(uint32_t i) {
    _intToBytes(_buffer+_offset, i, 4);
    _offset += 4;
}

I would prefer the latter.

matthias-bs commented 1 year ago

Thanks for the ultra quick reply!

joscha commented 1 year ago

I think the offset approach is a tad nicer, as the variable is actually used in all cases instead of carrying it along only for this case?

matthias-bs commented 1 year ago

Thank you very much for accepting the PR. Are you planning a new release soon?

joscha commented 1 year ago

Created 3.2.0 just now.

matthias-bs commented 1 year ago

Yes, but you did not update library.properties... ;-)

joscha commented 1 year ago

3.2.1

matthias-bs commented 1 year ago

Thanks a lot!