Skip to content

Commit 9fe9c4b

Browse files
committed
new print flag added
LYD_PRINT_JSON_NO_NESTED_PREFIX => PrintFlags::JsonNoNestedPrefix Change-Id: I0baf5d8891452db2340539dcec3bc2d895bec30d
1 parent bac6680 commit 9fe9c4b

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

include/libyang-cpp/Enum.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ enum class PrintFlags : uint32_t {
7575
WithDefaultsAllTag = 0x40,
7676
WithDefaultsImplicitTag = 0x80,
7777
WithDefaultsMask = 0xF0,
78+
JsonNoNestedPrefix = 0x100,
7879
};
7980

8081
/**

src/utils/enum.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static_assert(LYD_PRINT_WD_IMPL_TAG == toPrintFlags(PrintFlags::WithDefaultsImpl
4242
static_assert(LYD_PRINT_WD_MASK == toPrintFlags(PrintFlags::WithDefaultsMask));
4343
static_assert(LYD_PRINT_WD_TRIM == toPrintFlags(PrintFlags::WithDefaultsTrim));
4444
static_assert(LYD_PRINT_SIBLINGS == toPrintFlags(PrintFlags::Siblings));
45+
static_assert(LYD_PRINT_JSON_NO_NESTED_PREFIX == toPrintFlags(PrintFlags::JsonNoNestedPrefix));
4546

4647
#ifndef _MSC_VER
4748
// MSVC doesn't respect the underlying enum size

tests/data_node.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ TEST_CASE("Data Node manipulation")
159159

160160
auto emptyCont = ctx.newPath("/example-schema:first");
161161
REQUIRE(emptyCont.printStr(libyang::DataFormat::XML, libyang::PrintFlags::Siblings) == std::nullopt);
162+
163+
node = ctx.parseData(data2, libyang::DataFormat::JSON);
164+
auto child = node->findPath("/example-schema:leafInt8");
165+
str = child->printStr(libyang::DataFormat::JSON, libyang::PrintFlags::Shrink | libyang::PrintFlags::JsonNoNestedPrefix);
166+
REQUIRE(str == R"({"example-schema:leafInt8":-43})");
167+
child = node->findPath("/example-schema:first/second/third/fourth/fifth");
168+
str = child->printStr(libyang::DataFormat::JSON, libyang::PrintFlags::Shrink | libyang::PrintFlags::JsonNoNestedPrefix);
169+
REQUIRE(str == R"({"fifth":"430"})");
162170
}
163171

164172
DOCTEST_SUBCASE("Overwriting a tree with a different tree")

0 commit comments

Comments
 (0)