Meshtastic-Apple/Meshtastic/Extensions/CoreData/NodeInfoEntityToNodeInfo.swift

29 lines
974 B
Swift
Raw Normal View History

// NodeInfoEntityToNodeInfo.swift
// Meshtastic
//
// Utility to convert NodeInfoEntity (Core Data) to NodeInfo (protobuf)
import Foundation
import MeshtasticProtobufs
extension NodeInfoEntity {
func toProto() -> NodeInfo {
var userProto = User()
if let user = self.user {
userProto.id = user.userId ?? ""
userProto.longName = user.longName ?? ""
userProto.shortName = user.shortName ?? ""
2025-05-13 20:11:27 -05:00
userProto.hwModel = HardwareModel(rawValue: Int(user.hwModelId)) ?? .unset
userProto.isLicensed = user.isLicensed
2025-05-14 19:35:29 -05:00
userProto.isUnmessagable = false
2025-05-13 20:11:27 -05:00
userProto.role = Config.DeviceConfig.Role(rawValue: Int(user.role)) ?? .client
userProto.publicKey = user.publicKey?.subdata(in: 0..<user.publicKey!.count) ?? Data()
}
var node = NodeInfo()
node.num = UInt32(self.num)
node.user = userProto
// Add more fields as needed
return node
}
}