小弧光的博客

公众号:小弧光黑板报

导航

< 2025年2月 >
26 27 28 29 30 31 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 1
2 3 4 5 6 7 8

统计

2024年4月14日 #

protobuf 和 json 互转

common.h

#ifndef COMMON_H
#define COMMON_H
#include "google/protobuf/message.h"
#include "nlohmann/json.hpp"
#include "google/protobuf/util/json_util.h"
using google::protobuf::util::MessageToJsonString;
using namespace google::protobuf::util;
google::protobuf::util::JsonOptions JsonOption();
google::protobuf::util::JsonParseOptions JsonParseOption();
nlohmann::json ProtoToJson(const google::protobuf::Message &proto);
int JsonToProto(const std::string& strJson, google::protobuf::Message *proto);
#endif

common.cpp

#include "common.h"
google::protobuf::util::JsonOptions JsonOption()
{
google::protobuf::util::JsonOptions json_option;
json_option.always_print_primitive_fields = true;
return json_option;
}
google::protobuf::util::JsonParseOptions JsonParseOption()
{
google::protobuf::util::JsonParseOptions json_option;
json_option.ignore_unknown_fields = true;
return json_option;
}
nlohmann::json ProtoToJson(const google::protobuf::Message &proto)
{
static const auto kJsonOption = JsonOption();
std::string json_string;
const auto status = MessageToJsonString(proto, &json_string, kJsonOption);
nlohmann::json json_obj = nlohmann::json::parse(json_string);
return json_obj;
}
int JsonToProto(const std::string& strJson, google::protobuf::Message *proto)
{
static const auto kJsonParseOption = JsonParseOption();
const auto status = JsonStringToMessage(strJson, proto, kJsonParseOption);
return 0;
}

posted @ 2024-04-14 13:39 小弧光 阅读(186) 评论(0) 推荐(0) 编辑

2024年3月7日 #

Understanding Systemd Units and Unit Files

摘要: https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files Introduction Increasingly, Linux distributions are adoptin 阅读全文

posted @ 2024-03-07 08:18 小弧光 阅读(9) 评论(1) 推荐(0) 编辑

2024年2月22日 #

CMake 各个版本添加的新特性

摘要: https://modern-cmake-cn.github.io/Modern-CMake-zh_CN/chapters/intro/newcmake.html CMake 修改记录的简化版本,这里仅挑了作者认为的重点。这里,每个版本的名称都由作者自行命名,不要太在意。 CMake 3.0:接口库 阅读全文

posted @ 2024-02-22 13:10 小弧光 阅读(342) 评论(0) 推荐(0) 编辑

2024年1月29日 #

写一段rust代码,两个线程共享一个bool变量,一个写,一个读

摘要: use std::sync::{Arc, Mutex}; use std::thread; fn main() { // 创建一个布尔变量并用 Arc 和 Mutex 包装,使其可在多个线程间共享和修改 let shared_bool = Arc::new(Mutex::new(false)); / 阅读全文

posted @ 2024-01-29 10:55 小弧光 阅读(73) 评论(0) 推荐(0) 编辑

2024年1月12日 #

如何快速在x64 ubuntu上搭建arm 交叉编译环境

摘要: git clone https://github.com/ApolloAuto/apollo cd docker/scripts sudo ./dev_start.sh -c aarch64 阅读全文

posted @ 2024-01-12 14:33 小弧光 阅读(55) 评论(0) 推荐(0) 编辑

2023年12月14日 #

解决多次执行 vcpkg integrate install 导致的vcpkg各种奇怪问题

摘要: 执行 vcpkg integrate install 命令后,会在 Windows 上的 %LOCALAPPDATA%\vcpkg 或 %APPDATA%\Local\vcpkg 产生一些配置。 需要删除这些配置。 阅读全文

posted @ 2023-12-14 17:45 小弧光 阅读(201) 评论(0) 推荐(0) 编辑

2023年12月11日 #

rust 实现图像绕中心点旋转任意角度

摘要: use env_logger::Env; use image::RgbaImage; use log::{info, LevelFilter}; use nalgebra as na; use std::env; use std::fs::File; use std::path::Path; use 阅读全文

posted @ 2023-12-11 13:28 小弧光 阅读(81) 评论(0) 推荐(0) 编辑

2023年12月8日 #

ubuntu 非 root用户 bind socket 80端口 失败

摘要: 在 Ubuntu 或其他类似的 Linux 系统中,非 root 用户在绑定低于 1024 的端口时会失败,这是出于安全考虑的一种行为。为了允许非 root 用户绑定低端口,您可以考虑以下几种方法: 1. 使用 CAP_NET_BIND_SERVICE 能力 您可以使用 setcap 命令,为您的可 阅读全文

posted @ 2023-12-08 11:41 小弧光 阅读(337) 评论(0) 推荐(0) 编辑

xmake 设置运行前先构建

摘要: $ xmake f --policies=run.autobuild $ xmake run https://xmake.io/mirror/guide/build_policies.html 阅读全文

posted @ 2023-12-08 10:37 小弧光 阅读(27) 评论(0) 推荐(0) 编辑

2023年12月7日 #

解决QtCreator启动失败

摘要: 在 .zshrc中加入: export QT_DEBUG_PLUGINS=1 然后再启动,发现报错: library: "/home/itfanr/Desktop/sdb/Qt/Tools/QtCreator/lib/Qt/plugins/platforms/libqxcb.so" cannot l 阅读全文

posted @ 2023-12-07 09:31 小弧光 阅读(251) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示