2025-05-13 19:43:43 -05:00
|
|
|
// 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
|
2025-05-13 20:03:58 -05:00
|
|
|
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
|
2025-05-13 19:43:43 -05:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|