| | |
| | | package com.ard.tianyu.domain.dto.converter.realdata; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.ard.tianyu.domain.dto.state.*; |
| | | import com.ard.tianyu.netty.protobuf.TelemetryDataPB; |
| | | import com.ard.tianyu.component.netty.protobuf.TelemetryDataPB; |
| | | import com.google.protobuf.util.JsonFormat; |
| | | import org.springframework.beans.BeanUtils; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | public class UavStateConverter { |
| | | |
| | | // 将 Protobuf UavState 转换为 Java 实体类 UavState |
| | | |
| | | /** |
| | | * 将 Protobuf 格式的无人机状态转换为 Java 实体类 |
| | | * |
| | | * @param protobufUavState Protobuf 格式的无人机状态 |
| | | * @return 转换后的 Java 实体类对象 |
| | | * @throws RuntimeException 如果转换过程中发生错误,抛出运行时异常 |
| | | */ |
| | | public static UavState convertProtoToEntity(TelemetryDataPB.UavState protobufUavState) { |
| | | try { |
| | | // 将 Protobuf 对象转换为 JSON 字符串 |
| | | String json = JsonFormat.printer().includingDefaultValueFields().print(protobufUavState); |
| | | |
| | | // 使用 fastjson2 将 JSON 转换为 Java 实体类 |
| | | return JSON.parseObject(json, UavState.class); |
| | | } catch (Exception e) { |
| | | // 如果转换过程中发生异常,抛出运行时异常 |
| | | throw new RuntimeException("Protobuf 转换为实体类失败", e); |
| | | } |
| | | } |
| | | |
| | | // 将 Protobuf UavState 转换为 Java 实体类 UavState |
| | | public static UavState convertProtoToEntity1(TelemetryDataPB.UavState protobufUavState) { |
| | | UavState uavState = new UavState(); |
| | | |
| | | // 复制简单字段 |