The problem
An InBody result contains a QR code, which raises a reasonable question: what is actually in it? This project examines the encoded binary data, maps positions to measurements, and turns those findings into Python tools.
The approach: The Python packages separate binary decoding, field discovery, API access, and command-line use. Mutation-based experiments help identify what each field represents.
Reported project measurements: Sub-millisecond payload decoding; 100% reconstruction fidelity across 30+ body composition biometrics; automated differential mutation testing suite.
How it works
Differential Mutation Oracle: Automated test harness that systematically mutates fixed-width byte slices to programmatically discover biomarker boundaries and scale factors.
Fixed-Width Positional Matrix Deserializer: High-speed byte slice parser converting ASCII place-value representations into calibrated floating-point biometrics.
Segment Normalizer & Biomarker Deriver: Normalizes percent-encoded delimiters and computes derived clinical indicators (Appendicular Skeletal Muscle Mass, Skeletal Muscle Index).
How the pieces connect
flowchart TD
A[InBody Result Sheet QR Code] --> B[Raw IBData Query String]
B --> C[Percent-Encoding Normalizer]
C --> D[Multi-Segment Delimiter Lexer]
D --> E1[Segment 4: Body Composition Matrix]
D --> E2[Segment 5: Visceral Fat & BMR Matrix]
E1 & E2 --> F[Positional Place-Value Deserializer]
F --> G[Derived Biomarker Engine: ASM, SMI, ECW/TBW]
G --> H[Structured JSON / Dataframe Export]
Implementation notes
Positional Place-Value Deserializer (inbody-decoder/src/decoder.py)
# Fixed-width positional place-value matrix deserializer
def decode_digits(raw_slice: str, scale_factor: float = 0.1, precision: int = 2, meas_blob: str = "") -> float:
"""Fixed-width positional matrix deserializer for place-value byte windows in meas_blob."""
clean_digits = raw_slice.strip()
accumulated_value = sum(
(ord(char) - ord('0')) * (10 ** idx)
for idx, char in enumerate(reversed(clean_digits))
)
return round(accumulated_value * scale_factor, precision)
Differential Mutation Testing Oracle (inbody-cli/mapping.py)
# Programmatic field discovery via differential mutation
def probe_byte_slice(payload: str, start: int, end: int, delta: int = 1) -> str:
"""Injects controlled integer perturbations to isolate biometric offsets."""
chars = list(payload)
val = int("".join(chars[start:end])) + delta
chars[start:end] = f"{val:0{end - start}d}"
return "".join(chars)
Tradeoffs and lessons
- Percent-Encoding Collision Bug: Resolved a critical bug where URL percent-encoding (
%21) of literal!delimiters caused byte-slice alignment shifts, inducing a $10\times$ error on Leg Lean Mass. - Zero-Dependency Core: Built the core decoder using pure Python standard library primitives to allow embeddability in constrained IoT and mobile environments.