exposalud-data
v0.1.3
Published
ExpoSalud health fair SDK — compact guest data encoding and health metrics
Readme
exposalud-data
Compact guest data encoding for ExpoSalud health fair events. Encodes a full guest profile into ~133 bytes (vs ~600+ bytes JSON). QR code compatible.
Install
npm install exposalud-dataProtocol — Encode/Decode Guest Data
const { encode, decode, toBase64, fromBase64 } = require('exposalud-data/protocol')
// Encode a guest profile to binary
const buf = encode({
code: 'FE689B8A',
name: 'John Doe',
age: 38,
sex: 'M',
height: 175,
weight: 80,
bmi: 26.12,
bmiCat: 'overweight',
glucose: 95,
sbp: 120,
dbp: 80,
habits: { breakfast: 1, snacks: 0.5, exercise: 1 /* ... */ },
survey: {
discovery: ['social'],
interests: ['nutrition', 'healthy-food'],
needs: ['health'],
},
// ... all other fields
})
console.log(buf.length) // ~133 bytes
// Decode back to object
const guest = decode(buf)
console.log(guest.name) // 'John Doe'
console.log(guest.bmi) // 26.12
// For QR codes — convert to/from base64
const qr = toBase64(buf) // 180 chars, fits QR v10
const restored = decode(fromBase64(qr))Schema Versioning
The protocol is version-aware. Adding new fields is safe:
- Add the field to
FIXED_FIELDSorSTRING_FIELDSat the end - Bump
SCHEMA_VERSION - Add the new count to
VERSION_FIELD_COUNTS
Old decoders skip unknown fields. New decoders fill defaults for missing fields.
// Example: adding a 'bloodType' field in v2
// In FIXED_FIELDS, append:
['bloodType', cenc.uint8, or0, identity],
// Bump version:
const SCHEMA_VERSION = 2
// Update counts:
const VERSION_FIELD_COUNTS = {
1: { fixed: 32, strings: 6 },
2: { fixed: 33, strings: 6 }, // one more fixed field
}Size Comparison
| Format | Typical Guest | 1000 Guests | |--------|--------------|-------------| | JSON | ~600 bytes | ~600 KB | | Protocol | ~133 bytes | ~133 KB | | Reduction | 78% | 78% |
QR Code Compatibility
| Guest Type | Binary | Base64 | QR Version | |-----------|--------|--------|------------| | Empty | 53 bytes | 72 chars | v3 | | Typical | 133 bytes | 180 chars | v10 | | Long strings | 373 bytes | 500 chars | v20 |
All fit within standard QR code capacity.
Performance
1000 guests: 5ms encode, 5ms decode (Node.js)
License
MIT
