Skip to content

Commit 71993a3

Browse files
committed
Rename Environment proto type to TAKEnvironment
Bumps the protobufs submodule to 9b123f3 which renames the proto message type from `Environment` to `TAKEnvironment`. The bare name collided with SwiftUI's `@Environment` property wrapper, making the generated Swift module unusable in any iOS consumer that imports both SwiftUI and the proto bindings — the Meshtastic-Apple app had 78 such files. Only `TakPacketV2Serializer.kt` changes in the SDK: the Wire import and the `toWire` / `toData` bridge helpers now reference `TAKEnvironment` instead of `Environment`. The SDK's internal data class stays named `TakPacketV2Data.EnvironmentData` to match the source `<environment>` CoT XML element name (we only renamed the wire type, not the internal model). Wire format is unaffected — proto3 encoding is tag-number-based, so every fixture's compressed bytes are byte-identical before and after the rename. All 269 jvmTest cases stay green with no golden file regeneration required.
1 parent ea63645 commit 71993a3

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

kotlin/src/jvmMain/kotlin/org/meshtastic/tak/TakPacketV2Serializer.kt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import org.meshtastic.proto.CotHow
99
import org.meshtastic.proto.CotType
1010
import org.meshtastic.proto.DrawnShape
1111
import org.meshtastic.proto.EmergencyAlert
12-
import org.meshtastic.proto.Environment
12+
import org.meshtastic.proto.TAKEnvironment
1313
import org.meshtastic.proto.GeoChat
1414
import org.meshtastic.proto.GeoPointSource
1515
import org.meshtastic.proto.Marker
@@ -259,11 +259,14 @@ object TakPacketV2Serializer {
259259
is TakPacketV2Data.Payload.None -> { /* all oneof fields stay null */ }
260260
}
261261

262-
// Payload-agnostic annotations — Environment and SensorFov ride
262+
// Payload-agnostic annotations — TAKEnvironment and SensorFov ride
263263
// alongside whatever payload_variant the packet carries (or even on
264264
// an empty Payload.None). See their bridge helpers below for the
265265
// unit conventions.
266-
val environmentField: Environment? = data.environment?.toWire()
266+
//
267+
// Wire type is `TAKEnvironment` (not `Environment`) to avoid
268+
// colliding with SwiftUI's `@Environment` in iOS consumers.
269+
val environmentField: TAKEnvironment? = data.environment?.toWire()
267270
val sensorFovField: SensorFov? = data.sensorFov?.toWire()
268271

269272
// Enum .fromValue() returns null for out-of-range values — fall back
@@ -527,22 +530,27 @@ object TakPacketV2Serializer {
527530
)
528531
}
529532

530-
// -- Environment <-> wire bridge ------------------------------------------
533+
// -- TAKEnvironment <-> wire bridge ---------------------------------------
531534
//
532535
// The SDK's EnvironmentData exposes natural units (°C, whole degrees, m/s)
533536
// with nullable fields to distinguish "not set" from "zero". The wire form
534537
// packs temperature into deci-degrees Celsius (×10 sint32) and wind speed
535538
// into cm/s (×100 uint32) to match TAKPacketV2.speed's unit convention.
536539
// Absent nullable scalars encode as the proto3 default (0) and decode back
537540
// to null via the sentinel checks in toData().
541+
//
542+
// The wire type is `TAKEnvironment` (prefix added to avoid colliding with
543+
// SwiftUI's `@Environment` in iOS consumers); the SDK's data class is
544+
// still named `EnvironmentData` to match the source `<environment>` CoT
545+
// XML element name — only the proto/wire type name changed.
538546

539-
private fun TakPacketV2Data.EnvironmentData.toWire(): Environment = Environment(
547+
private fun TakPacketV2Data.EnvironmentData.toWire(): TAKEnvironment = TAKEnvironment(
540548
temperature_c_x10 = temperatureCelsius?.let { (it * 10).roundToInt() } ?: 0,
541549
wind_direction_deg = windDirectionDeg ?: 0,
542550
wind_speed_cm_s = windSpeedMetersPerSec?.let { (it * 100).roundToInt() } ?: 0,
543551
)
544552

545-
private fun Environment.toData(): TakPacketV2Data.EnvironmentData {
553+
private fun TAKEnvironment.toData(): TakPacketV2Data.EnvironmentData {
546554
// Wire scalars are always present (proto3 defaults to 0). Treat an
547555
// all-zeros field as "not set" on decode — a genuine 0° / 0 m/s wind
548556
// round-trips as null, which is acceptable for this annotation's

protobufs

0 commit comments

Comments
 (0)