shench3
2026-03-03 867d735635873ccef7d6e7b48cc6f0df25b9ac3d
xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/utils/MapAreaVersionProtoWriter.java
@@ -1,11 +1,9 @@
package com.xiaopeng.map.utils;
import com.google.protobuf.CodedOutputStream;
import java.io.IOException;
/**
 * 将 MapAreaVersion 序列化为与 map_area_version.proto 兼容的 Protobuf 二进制格式。
 * 将 MapAreaVersion 序列化为与 map_area_version.proto 兼容的 Protobuf 文本格式(text proto)。
 * 与 C++ xngp_area_fbs_convertor 的 DebugString() 输出一致,供 xngp_area_queryer 使用 TextFormat 解析。
 * 使用平台默认编码(非 UTF-8 强制指定),与 C++ 读取端编码保持一致。
 */
public final class MapAreaVersionProtoWriter {
@@ -13,20 +11,14 @@
    }
    /**
     * 生成 MapAreaVersion 的 protobuf 二进制
     * 生成 MapAreaVersion 的 text proto 格式,与 C++ DebugString() 输出一致。
     *
     * @param version    Unix 秒级时间戳
     * @param fileLength bin 文件字节长度
     * @return protobuf 二进制
     * @return text proto 字节(平台默认编码)
     */
    public static byte[] toByteArray(int version, int fileLength) throws IOException {
        int size = CodedOutputStream.computeUInt32Size(1, version)
                + CodedOutputStream.computeUInt32Size(2, fileLength);
        byte[] buf = new byte[size];
        CodedOutputStream cos = CodedOutputStream.newInstance(buf);
        cos.writeUInt32(1, version);
        cos.writeUInt32(2, fileLength);
        cos.checkNoSpaceLeft();
        return buf;
    public static byte[] toByteArray(int version, int fileLength) {
        String text = "version: " + version + "\nfile_length: " + fileLength + "\n";
        return text.getBytes();
    }
}