import Foundation // The models for what `pet-life` prints, in a library so the contract can be // tested. Field names match its JSON exactly, and that JSON is pinned to exact // bytes by a test on the Rust side — this is the other half of the same // contract. The wire format between the daemon and the collector has drifted // twice in this project; both times a pinned fixture caught it. /// What `pet-life` prints. Field names match its JSON exactly; that contract is /// pinned to exact bytes by a test on the Rust side. public struct Grave: Decodable { public init(name: String, generation: Int, lived_days: Double) { self.name = name; self.generation = generation; self.lived_days = lived_days } public let name: String public let generation: Int public let lived_days: Double } public struct PetState: Decodable { public let alive: Bool public let name: String? public let generation: Int? public let stage: String public let face: String public let age_days: Double public let quiet_days: Double public let cemetery: [Grave] } public extension PetState { /// Decode what `pet-life` printed. static func decode(_ data: Data) throws -> PetState { try JSONDecoder().decode(PetState.self, from: data) } }