#!/bin/sh
# The codec is source-shared with the iOS app: fail if the body drifted.
set -e
HERE=$(cd "$(dirname "$0")" && pwd)
IOS=${TINYAI_ID:-$HOME/tinyai-id}/ios/Tiny/Sources/TinyBeaconV2.swift
# strip our banner (first 5 lines) and the stub (from the marker) before diffing
sed -n '/^ \* TinyBeaconV2 — codec/,$p' "$HERE/TinyBeaconV2.swift" | sed "/^\/\/\/ v1 beacon (mirror/,\$d" | sed -e :a -e "/^\n*$/{$d;N;ba" -e "}" > /tmp/tinyble-mirror.swift
sed -n '/^ \* TinyBeaconV2 — codec/,$p' "$IOS" > /tmp/tinyble-ios.swift
diff -u /tmp/tinyble-ios.swift /tmp/tinyble-mirror.swift && echo "codec in sync with $IOS"
