Skip to content

【llbc】探索一个最简介、易于使用的json cpp库 #160#337

Open
ericyonng wants to merge 18 commits into
lailongwei:masterfrom
ericyonng:master
Open

【llbc】探索一个最简介、易于使用的json cpp库 #160#337
ericyonng wants to merge 18 commits into
lailongwei:masterfrom
ericyonng:master

Conversation

@ericyonng
Copy link
Copy Markdown
Collaborator

nlohmann/json 支持
issue: json issue

Copy link
Copy Markdown
Owner

@lailongwei lailongwei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericyonng 大体看了一下,有一个整体的修改建议哈,惠雅可以看下的:

  • nlohmann放到llbc目录的方式建议是这样的组织,即把:nlohmann/include目录copy到core/json目录
    • /core/json/
    •     |--------/nlohmann/
      
    •                          |-----------json.hpp
      
  • copy进去后,应该只需要修改LLBC_NLOHMANN_JSON_NAMESPACE_BEGIN这个namespace,修改成::llbc::nlohmann::即可?

Copy link
Copy Markdown
Owner

@lailongwei lailongwei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericyonng 有两个主要的建议哈:

  1. LLBCJson.h感觉不是非常必要
  2. nlohmann/json修改不建议改那么大,只需要修改NLOHMANN_JSON_NAMESPACE_BEGINEND宏:最外层增加llbcnamespace即可

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

个人感觉LLBCJson.h不是非常有必要存在,因为nlohmann json已经挺方便,这里面的两个函数可以不需要?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的

#include <llbc/core/json/nlohmann/detail/conversions/to_json.hpp>
#include <llbc/core/json/nlohmann/detail/meta/identity_tag.hpp>

LLBC_NLOHMANN_JSON_NAMESPACE_BEGIN
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nlohmann/json的修改,感觉越小越好?只需要对其原有的NLOHMANN_JSON_NAMESPACE_BEGIN进行修改即可:再外加一个llbc namespace就OK?
image


#include <llbc/core/json/nlohmann/detail/abi_macros.hpp>

LLBC_NLOHMANN_JSON_NAMESPACE_BEGIN
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adl_serializer.hpp中注释:不建议修改nlohmann/json库太多,只需要修改它的一个NLOHMANN_JSON_NAMESPACE_BEGIN定义即可

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

整个abi_macros.hpp不建议修改宏名

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的

@ericyonng ericyonng requested a review from lailongwei January 11, 2025 15:50
Copy link
Copy Markdown
Owner

@lailongwei lailongwei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericyonng 辛苦惠雅,给力!
这边有一些想法哈,惠雅你看下的:

  1. LLBC_JsonInl.h感觉不是非常需要,原因:

    • LLBC_JsonToString()方法较为简单,不是非常必要
    • LLBC_AutoJson好像想不到用的情境,如果真的需要,是否用std::shared_ptrstd::unique_ptr就可代替?
  2. detail/abi_macros.hpp中对宏的修改方式初看没有问题,但在以下情况下,是有问题的:

    • 项目中有其它地方本身也有引入nlohmann/json时,宏将冲突
    • 所以,这边的改进想法是:
      • 所有里面的相关宏,需要加LLBC_prefix
  3. 当前llbc宏名已经作优化,只在common/Macro.h中有一处地方有配置,也就是说,在abi_macros.hpp中,可以不显式手写llbc,可参考tinyxml2.h

@lailongwei
Copy link
Copy Markdown
Owner

@ericyonng 麻烦惠雅继续推进推进这块,哈哈

Copy link
Copy Markdown
Owner

@lailongwei lailongwei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

辛苦惠雅提交pr,有两个主要的修改建议哈:

  1. nlohmann采用旧式的#ifndef/#define/#endif方式来防止头文件重复包含,在使用llbc的项目中,如果自身又包含了一个nlohmann,将产生不必要的包含识别问题
    这边有两个想法,需要惠雅你来选择:
    • nlohmann中所有的防止头文件误包含的#ifndef/#define/#endif的宏名前面也加LLBC_prefix
    • 统一替换成#pragma once
  2. hedley三方库的问题,在nlohmann,他们是直接文件包含引入,且整体修改了代码,将所有HEDLEY_XXX宏名加了JSON_ prefix,在 llbc 中,同样也得再加一个LLBC_前缀

Comment on lines +96 to +98
#ifndef LLBC_NLOHMANN_NS
#define LLBC_NLOHMANN_NS ::llbc::nlohmann
#endif // LLBC_NLOHMANN_NS
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个定义建议放到85行后,跟LLBC_NLOHMANN_JSON_NAMESPACE紧邻,代表是一个shortcut名,而不是夹杂在ns beginns end中间

Comment on lines +101 to +102
#define LLBC_NLOHMANN_JSON_NAMESPACE_END \
} /* namespace (inline namespace) NOLINT(readability/namespace) */ \
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

结束\未对齐

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants