Commit Graph

4 Commits

Author SHA1 Message Date
Abtin Keshavarzian 8abf9667c3 [common] refactor FrameBuilder and FrameData to use templated API (#13216)
This commit refactors the `FrameBuilder` and `FrameData` modules,
replacing multiple distinct endian-specific methods with a unified,
type-safe templated API.

Key changes:
- Introduced `enum Encoding` (`kBigEndian`, `kLittleEndian`) and a
  templated `HostSwap<Encoding, UintType>` helper in `encoding.hpp` to
  centralize byte-swapping logic.
- Replaced `AppendBigEndianUint16()`, `AppendLittleEndianUint32()`,
  and other variations in `FrameBuilder` with a single templated
  method: `AppendUint<Encoding, UintType>()`.
- Replaced `ReadBigEndianUint16()`, `ReadLittleEndianUint32()`,
  and other variations in `FrameData` with a single templated
  method: `ReadUint<Encoding, UintType>()`.
- Updated all callers in `Lowpan` and `Mac` modules to use the new
  templated encoding APIs.
- Updated `test_frame_builder.cpp` to validate the new syntax.
2026-06-08 19:34:19 -07:00
Jonathan Hui 9c467a23ae [clang-format] apply v14 changes (#8490) 2022-12-07 16:23:20 -08:00
Abtin Keshavarzian e3f157402c [frame-builder] add Insert(), Remove() and other helper methods (#7964)
This commit adds `Insert()` and `Remove()` methods in `FrameBuilder`.
`Insert` can be used to insert new content in the frame at a given
offset moving any previously written content forward. `Remove()` can
be used to remove previously appended content from the frame moving
any content after the removed bytes backward. This commit also adds
`GetRemainingLength()` to get the remaining length (number of bytes
that can be appended) in the frame buffer, and `SetMaxLength()`. Unit
test `test_frame_builder` is also updated to validate all the newly
added methods.
2022-08-02 12:43:51 -07:00
Abtin Keshavarzian a282aa9f9b [core] adding FrameBuilder for constructing frames (#7935)
This commit adds a new class `FrameBuilder` which helps with
construction of frames in a given buffer. It provides helper methods
to append different items to the frame, e.g., bytes from a buffer or
`Message`, a `uint8`, `uint16` or `uint32` value assuming big or
little endian encoding, or a given object. It also provides methods
to overwrite previously appended content in the frame at a given
offset. This class is used in `Lowpan` (replacing `BufferWriter`)
which helps simplify the code. This commit also updates `Appender` to
use the `FrameBuilder` and adds a new unit test for `FrameBuidler`.
2022-07-25 19:59:55 -07:00