shench3
2026-03-03 1dc6dd42706eb2a302c585b23541088459e58652
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.xiaopeng.map.utils;
 
import com.google.protobuf.CodedOutputStream;
 
import java.io.IOException;
 
/**
 * 将 MapAreaVersion 序列化为与 map_area_version.proto 兼容的 Protobuf 二进制格式。
 */
public final class MapAreaVersionProtoWriter {
 
    private MapAreaVersionProtoWriter() {
    }
 
    /**
     * 生成 MapAreaVersion 的 protobuf 二进制
     *
     * @param version    Unix 秒级时间戳
     * @param fileLength bin 文件字节长度
     * @return protobuf 二进制
     */
    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;
    }
}