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-25 09:25:58 -07:00
|
|
|
if userProto.hasIsUnmessagable == true {
|
|
|
|
|
userProto.isUnmessagable = user.unmessagable
|
|
|
|
|
}
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-10-05 17:51:18 -07:00
|
|
|
|
|
|
|
|
extension UserEntity {
|
|
|
|
|
func toProto() -> User {
|
|
|
|
|
var userProto = User()
|
|
|
|
|
userProto.id = self.userId ?? ""
|
|
|
|
|
userProto.longName = self.longName ?? ""
|
|
|
|
|
userProto.shortName = self.shortName ?? ""
|
|
|
|
|
userProto.hwModel = HardwareModel(rawValue: Int(self.hwModelId)) ?? .unset
|
|
|
|
|
userProto.isLicensed = self.isLicensed
|
|
|
|
|
if userProto.hasIsUnmessagable == true {
|
|
|
|
|
userProto.isUnmessagable = self.unmessagable
|
|
|
|
|
}
|
|
|
|
|
userProto.role = Config.DeviceConfig.Role(rawValue: Int(self.role)) ?? .client
|
|
|
|
|
userProto.publicKey = self.publicKey?.subdata(in: 0..<self.publicKey!.count) ?? Data()
|
|
|
|
|
return userProto
|
|
|
|
|
}
|
|
|
|
|
}
|