Bytes are not your data model: the mapper layer between BLE and the database
What a device sends and what an app stores are different shapes. A mapper layer keeps firmware changes out of your database.
Surendra — Tejvon
Senior Android & BLE Engineer
A device speaks in bytes and protocol frames. An app stores records in a database and shows models on a screen. These are three different shapes of the same information, and treating them as one is a common source of fragile code.
On our BLE projects we keep a mapper layer between the protocol and Room, Android's database library. The BLE side produces protocol objects that mirror what the device sends. Mappers convert those into database entities. Nothing else in the app knows what the wire format looks like.
The reason is change. Firmware evolves. A field gets wider, a unit changes, a new value is added to a frame. If protocol objects are stored and displayed directly, every firmware change touches the database schema and the UI. With mappers, it touches one function.
Mappers are also the easiest code in the project to test. They are pure functions: bytes in, entity out. A handful of captured device frames becomes a permanent test suite that tells you immediately when a protocol change breaks an assumption.
It is a small amount of extra code up front. On any project where the hardware is still changing, it earns that back quickly.
Topics
Working on a similar challenge?
Let's discuss the architecture before you build.
BLE system design, OTA reliability, and connected product engineering — this is what TEJVON does every day.
Book a Technical Consultation