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; } }