diff --git a/internal/tlcodegen/test/codegen_test/casetests/json_read_test.go b/internal/tlcodegen/test/codegen_test/casetests/json_read_test.go index 7e4cca78..650903e7 100644 --- a/internal/tlcodegen/test/codegen_test/casetests/json_read_test.go +++ b/internal/tlcodegen/test/codegen_test/casetests/json_read_test.go @@ -9,7 +9,6 @@ package casetests import ( "encoding/json" "fmt" - "github.com/vkcom/tl/internal/utils" "math/rand" "os" @@ -213,38 +212,3 @@ func TestGeneralCases(t *testing.T) { }) } } - -func TestJson(t *testing.T) { - const PathToJsonData = "../data/test-objects-json.json" - data, readErr := os.ReadFile(PathToJsonData) - - if readErr != nil { - t.Fatalf("testing data is not provided") - return - } - - tests := allTests{map[string]mappingTestSamples{}} - err := json.Unmarshal(data, &tests) - - if err != nil { - t.Fatalf("can't unmarshall test data") - return - } - - fmt.Println("{ \"Tests\": {") - for testName, testValues := range tests.Tests { - if testValues.UseBytes { - continue - } - fmt.Printf("\"%s\": {\"TestingType\": \"%s\", \"Succesess\":[", testName, testValues.TestingType) - for _, testValue := range testValues.Successes { - testObject := factory.CreateObjectFromName(testValues.TestingType) - - _ = testObject.ReadJSON(true, &basictl.JsonLexer{Data: []byte(testValue.GoldenInput)}) - bs, _ := testObject.WriteGeneral(nil) - fmt.Printf("{\"Bytes\": \"%s\"},\n", utils.SprintHexDump(bs)) - } - fmt.Println("]},") - } - fmt.Println("}}") -} diff --git a/internal/tlcodegen/test/codegen_test/cpp/tests/test_objects_json.cpp b/internal/tlcodegen/test/codegen_test/cpp/tests/test_objects_json.cpp new file mode 100644 index 00000000..cb285993 --- /dev/null +++ b/internal/tlcodegen/test/codegen_test/cpp/tests/test_objects_json.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#include "../dependencies/json.hpp" +#include "../utils/hex.h" + +#include "../../../gen/cases_cpp/a_tlgen_helpers_code.hpp" +#include "../../../gen/cases_cpp/__meta/headers.hpp" +#include "../../../gen/cases_cpp/__factory/headers.hpp" + +// for convenience +using json = nlohmann::json; + +int main() { + tl2::factory::set_all_factories(); + + std::ifstream f("../data/test-objects-json-and-bytes.json"); + json data = json::parse(f); + + auto tests = data["Tests"]; + for (auto& [test_name, test_data]: tests.items()) { + std::cout << "Run [" << test_name << "]:" << std::endl; + for (auto& test_data_input: test_data["Successes"]) { + std::cout << "\tTestData [" << test_data_input.at("DataAsBytes") << "]: "; + + auto test_object = tl2::meta::get_item_by_name(test_data.at("TestingType")).create_object(); + auto bytes_input = hex::parse_hex_to_bytes(test_data_input.at("DataAsBytes")); + std::string expected_json_output = test_data_input.at("DataAsJson"); + + basictl::tl_istream_string input{bytes_input}; + std::stringstream output; + + bool read_result = test_object->read(input); + bool write_result = test_object->write_json(output); + + bool test_result = write_result && read_result; + if (test_result) { + test_result = output.str() == expected_json_output; + } + if (test_result) { + std::cout << "SUCCESS" << std::endl; + } else { + std::cout << "FAILED" << std::endl; + std::cout << "\t\tWrite result : " << write_result << std::endl; + std::cout << "\t\tExpected json output: " << expected_json_output << std::endl; + std::cout << "\t\tActual json result : " << output.str() << std::endl; + return 1; + } + test_object->write_json(std::cout); + std::cout << std::endl; + } + } + + std::cout << std::endl; + std::cout << "All tests are passed!" << std::endl; + + return 0; +} diff --git a/internal/tlcodegen/test/codegen_test/data/test-objects-json-and-bytes.json b/internal/tlcodegen/test/codegen_test/data/test-objects-json-and-bytes.json new file mode 100644 index 00000000..c24075bf --- /dev/null +++ b/internal/tlcodegen/test/codegen_test/data/test-objects-json-and-bytes.json @@ -0,0 +1,372 @@ +{ + "Tests": { + "TestDictionaryInt": { + "TestingType": "cases.testDictInt", + "Successes": [ + { + "DataAsBytes": "00000000", + "DataAsJson": "{}" + }, + { + "DataAsBytes": "00000002 00000001 00000001 00000002 00000002", + "DataAsJson": "{\"dict\":{\"1\":1,\"2\":2}}" + } + ] + }, + "TestUnion": { + "TestingType": "cases.testUnionContainer", + "Successes": [ + { + "DataAsBytes": "4b4f09b1 00000001", + "DataAsJson": "{\"value\":{\"type\":\"cases.testUnion1\",\"value\":{\"value\":1}}}" + }, + { + "DataAsBytes": "464f96c4 00003201", + "DataAsJson": "{\"value\":{\"type\":\"cases.testUnion2\",\"value\":{\"value\":\"2\"}}}" + }, + { + "DataAsBytes": "4b4f09b1 00000000", + "DataAsJson": "{\"value\":{\"type\":\"cases.testUnion1\",\"value\":{}}}" + } + ] + }, + "TestEnum": { + "TestingType": "cases.testEnumContainer", + "Successes": [ + { + "DataAsBytes": "6c6c55ac", + "DataAsJson": "{\"value\":\"cases.testEnum1\"}" + }, + { + "DataAsBytes": "86ea88ce", + "DataAsJson": "{\"value\":\"cases.testEnum2\"}" + } + ] + }, + "TestLocalFieldMaskRecursive": { + "TestingType": "cases.testRecursiveFieldMask", + "Successes": [ + { + "DataAsBytes": "00000001 00000002 00000004", + "DataAsJson": "{\"f0\":1,\"f1\":2,\"f2\":4,\"t1\":true,\"t2\":true,\"t3\":true}" + }, + { + "DataAsBytes": "00000001 00000002 00000000", + "DataAsJson": "{\"f0\":1,\"f1\":2,\"f2\":0,\"t1\":true,\"t2\":true}" + }, + { + "DataAsBytes": "00000000", + "DataAsJson": "{}" + }, + { + "DataAsBytes": "0000000f 00000000", + "DataAsJson": "{\"f0\":15,\"f1\":0,\"t1\":true}" + }, + { + "DataAsBytes": "00000001 0000000f 00000000", + "DataAsJson": "{\"f0\":1,\"f1\":15,\"f2\":0,\"t1\":true,\"t2\":true}" + }, + { + "DataAsBytes": "0000001f 00000002 0000000f", + "DataAsJson": "{\"f0\":31,\"f1\":2,\"f2\":15,\"t1\":true,\"t2\":true,\"t3\":true}" + }, + { + "DataAsBytes": "00000001 0000001f 0000000f", + "DataAsJson": "{\"f0\":1,\"f1\":31,\"f2\":15,\"t1\":true,\"t2\":true,\"t3\":true}" + }, + { + "DataAsBytes": "00000019 0000001f 0000000f", + "DataAsJson": "{\"f0\":25,\"f1\":31,\"f2\":15,\"t1\":true,\"t2\":true,\"t3\":true}" + } + ] + }, + "TestOuterFieldMask": { + "TestingType": "cases.testOutFieldMaskContainer", + "Successes": [ + { + "DataAsBytes": "00000001 00000001 00000001", + "DataAsJson": "{\"f\":1,\"inner\":{\"f1\":1,\"f3\":[1]}}" + }, + { + "DataAsBytes": "00000000", + "DataAsJson": "{\"inner\":{}}" + }, + { + "DataAsBytes": "00000001 00000000 00000001", + "DataAsJson": "{\"f\":1,\"inner\":{\"f1\":0,\"f3\":[1]}}" + } + ] + }, + "TestRecursiveTypes": { + "TestingType": "cases.myCycle2", + "Successes": [ + { + "DataAsBytes": "00000000", + "DataAsJson": "{}" + }, + { + "DataAsBytes": "00000001 00000000", + "DataAsJson": "{\"fields_mask\":1,\"a\":{}}" + }, + { + "DataAsBytes": "00000001 00000001 00000000", + "DataAsJson": "{\"fields_mask\":1,\"a\":{\"fields_mask\":1,\"a\":{}}}" + }, + { + "DataAsBytes": "00000001 00000001 00000001 00000002", + "DataAsJson": "{\"fields_mask\":1,\"a\":{\"fields_mask\":1,\"a\":{\"fields_mask\":1,\"a\":{\"fields_mask\":2}}}}" + }, + { + "DataAsBytes": "00000001 00000001 00000001 00000000", + "DataAsJson": "{\"fields_mask\":1,\"a\":{\"fields_mask\":1,\"a\":{\"fields_mask\":1,\"a\":{}}}}" + } + ] + }, + "TestReadOrder": { + "TestingType": "cases.replace7", + "Successes": [ + { + "DataAsBytes": "00000001 00000002 00000001 00000002", + "DataAsJson": "{\"n\":1,\"m\":2,\"a\":[[1,2]]}" + } + ] + }, + "TestTuple": { + "TestingType": "cases.testTuple", + "Successes": [ + { + "DataAsBytes": "00000001 00000002 00000003 00000004", + "DataAsJson": "{\"tpl\":[1,2,3,4]}" + } + ] + }, + "TestDictionaryString": { + "TestingType": "cases.testDictString", + "Successes": [ + { + "DataAsBytes": "00000000", + "DataAsJson": "{}" + }, + { + "DataAsBytes": "00000002 00316b02 00000001 00326b02 00000002", + "DataAsJson": "{\"dict\":{\"k1\":1,\"k2\":2}}" + } + ] + }, + "TestDictionaryAny": { + "TestingType": "cases.testDictAny", + "Successes": [ + { + "DataAsBytes": "00000000", + "DataAsJson": "{}" + }, + { + "DataAsBytes": "00000002 00000000 3ff00000 00000001 cccccccd 4000cccc 00000002", + "DataAsJson": "{\"dict\":[{\"key\":1,\"value\":1},{\"key\":2.1,\"value\":2}]}" + } + ] + }, + "TestLocalFieldMask": { + "TestingType": "cases.testLocalFieldmask", + "Successes": [ + { + "DataAsBytes": "00000003 00000002", + "DataAsJson": "{\"f1\":3,\"f2\":2,\"f3\":true,\"f4\":true}" + }, + { + "DataAsBytes": "00000002", + "DataAsJson": "{\"f1\":2}" + }, + { + "DataAsBytes": "00000001 00000002", + "DataAsJson": "{\"f1\":1,\"f2\":2,\"f3\":true,\"f4\":true}" + }, + { + "DataAsBytes": "00000001 00000000", + "DataAsJson": "{\"f1\":1,\"f2\":0}" + } + ] + }, + "TestBeforeReadBitValidation": { + "TestingType": "cases.testBeforeReadBitValidation", + "Successes": [ + { + "DataAsBytes": "00000003 00000001 00000001 00000001 00000001 00000001 00000001", + "DataAsJson": "{\"n\":3,\"a\":[1,1,1],\"b\":[1,1,1]}" + } + ] + }, + "TestArray": { + "TestingType": "cases.testArray", + "Successes": [ + { + "DataAsBytes": "00000000", + "DataAsJson": "{}" + }, + { + "DataAsBytes": "00000003 00000001 00000002 00000003", + "DataAsJson": "{\"n\":3,\"arr\":[1,2,3]}" + } + ] + }, + "TestVector": { + "TestingType": "cases.testVector", + "Successes": [ + { + "DataAsBytes": "00000000", + "DataAsJson": "{}" + }, + { + "DataAsBytes": "00000003 00000001 00000002 00000003", + "DataAsJson": "{\"arr\":[1,2,3]}" + } + ] + }, + "TestReadWithDifferentNatDependencies": { + "TestingType": "cases.testAllPossibleFieldConfigsContainer", + "Successes": [ + { + "DataAsBytes": "00000000 00000000 000000ef", + "DataAsJson": "{\"value\":{\"f00\":239}}" + }, + { + "DataAsBytes": "00000000 00000000 00000000", + "DataAsJson": "{\"value\":{}}" + }, + { + "DataAsBytes": "00000000 00000000 00000000", + "DataAsJson": "{\"value\":{}}" + }, + { + "DataAsBytes": "00000000 00000000 00000000", + "DataAsJson": "{\"value\":{}}" + }, + { + "DataAsBytes": "00000000 00000001 00000000 00000001 00000000", + "DataAsJson": "{\"value\":{\"local\":1,\"f02\":[1],\"f10\":0}}" + }, + { + "DataAsBytes": "00000000 00000000 00000000", + "DataAsJson": "{\"value\":{}}" + }, + { + "DataAsBytes": "00000001 00000000 00000000 00000001 00000000", + "DataAsJson": "{\"outer\":1,\"value\":{\"f03\":[1],\"f20\":0}}" + }, + { + "DataAsBytes": "00000000 00000000 00000000", + "DataAsJson": "{\"value\":{}}" + }, + { + "DataAsBytes": "00000000 00000001 00000000 00000001 000000ef", + "DataAsJson": "{\"value\":{\"local\":1,\"f02\":[1],\"f10\":239}}" + }, + { + "DataAsBytes": "00000000 00000001 00000000 00000001 000000ef", + "DataAsJson": "{\"value\":{\"local\":1,\"f02\":[1],\"f10\":239}}" + }, + { + "DataAsBytes": "00000000 00000001 00000000 00000001 00000000", + "DataAsJson": "{\"value\":{\"local\":1,\"f02\":[1],\"f10\":0}}" + }, + { + "DataAsBytes": "00000000 00000000 00000000", + "DataAsJson": "{\"value\":{}}" + }, + { + "DataAsBytes": "00000000 00000002 00000000 00000002 00000002", + "DataAsJson": "{\"value\":{\"local\":2,\"f02\":[2,2],\"f11\":true}}" + }, + { + "DataAsBytes": "00000000 00000003 00000000 00000003 00000003 00000003 00000000", + "DataAsJson": "{\"value\":{\"local\":3,\"f02\":[3,3,3],\"f10\":0,\"f11\":true}}" + }, + { + "DataAsBytes": "00000000 00000001 00000000 00000001 00000000", + "DataAsJson": "{\"value\":{\"local\":1,\"f02\":[1],\"f10\":0}}" + }, + { + "DataAsBytes": "00000000 00000002 00000000 00000002 00000002", + "DataAsJson": "{\"value\":{\"local\":2,\"f02\":[2,2],\"f11\":true}}" + }, + { + "DataAsBytes": "00000000 00000000 00000000", + "DataAsJson": "{\"value\":{}}" + }, + { + "DataAsBytes": "00000000 00000000 00000000", + "DataAsJson": "{\"value\":{}}" + }, + { + "DataAsBytes": "00000000 00000004 00000000 00000004 00000004 00000004 00000004 00000004 00000004 00000004 00000004", + "DataAsJson": "{\"value\":{\"local\":4,\"f02\":[4,4,4,4],\"f12\":[4,4,4,4]}}" + }, + { + "DataAsBytes": "00000000 00000002 00000000 00000002 00000002", + "DataAsJson": "{\"value\":{\"local\":2,\"f02\":[2,2],\"f11\":true}}" + }, + { + "DataAsBytes": "00000001 00000008 00000000 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000001 00000001 00000000", + "DataAsJson": "{\"outer\":1,\"value\":{\"local\":8,\"f02\":[8,8,8,8,8,8,8,8],\"f03\":[1],\"f13\":[1],\"f20\":0}}" + }, + { + "DataAsBytes": "00000000 00000002 00000000 00000002 00000002", + "DataAsJson": "{\"value\":{\"local\":2,\"f02\":[2,2],\"f11\":true}}" + }, + { + "DataAsBytes": "00000001 00000000 00000000 00000001 000000ef", + "DataAsJson": "{\"outer\":1,\"value\":{\"f03\":[1],\"f20\":239}}" + }, + { + "DataAsBytes": "00000001 00000000 00000000 00000001 00000000", + "DataAsJson": "{\"outer\":1,\"value\":{\"f03\":[1],\"f20\":0}}" + }, + { + "DataAsBytes": "00000000 00000000 00000000", + "DataAsJson": "{\"value\":{}}" + }, + { + "DataAsBytes": "00000000 00000000 00000000", + "DataAsJson": "{\"value\":{}}" + }, + { + "DataAsBytes": "00000004 00000002 00000000 00000002 00000002 00000004 00000004 00000004 00000004 00000002 00000002", + "DataAsJson": "{\"outer\":4,\"value\":{\"local\":2,\"f02\":[2,2],\"f03\":[4,4,4,4],\"f11\":true,\"f22\":[2,2]}}" + }, + { + "DataAsBytes": "00000004 00000000 00000000 00000004 00000004 00000004 00000004", + "DataAsJson": "{\"outer\":4,\"value\":{\"f03\":[4,4,4,4],\"f22\":[]}}" + }, + { + "DataAsBytes": "00000000 00000002 00000000 00000002 00000002", + "DataAsJson": "{\"value\":{\"local\":2,\"f02\":[2,2],\"f11\":true}}" + }, + { + "DataAsBytes": "00000008 00000000 00000000 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008 00000008", + "DataAsJson": "{\"outer\":8,\"value\":{\"f03\":[8,8,8,8,8,8,8,8],\"f23\":[8,8,8,8,8,8,8,8]}}" + }, + { + "DataAsBytes": "00000000 00000000 00000000", + "DataAsJson": "{\"value\":{}}" + } + ] + }, + "TestMaybe": { + "TestingType": "cases.testMaybe", + "Successes": [ + { + "DataAsBytes": "27930a7b", + "DataAsJson": "{}" + }, + { + "DataAsBytes": "3f9c8ef8 00000000", + "DataAsJson": "{\"value\":{\"ok\":true}}" + }, + { + "DataAsBytes": "3f9c8ef8 00000001", + "DataAsJson": "{\"value\":{\"ok\":true,\"value\":1}}" + } + ] + } + } +} \ No newline at end of file diff --git a/internal/tlcodegen/test/gen/cases_cpp/__common_namespace/details.cpp b/internal/tlcodegen/test/gen/cases_cpp/__common_namespace/details.cpp index e3c59fdf..bdae62d6 100644 --- a/internal/tlcodegen/test/gen/cases_cpp/__common_namespace/details.cpp +++ b/internal/tlcodegen/test/gen/cases_cpp/__common_namespace/details.cpp @@ -187,11 +187,15 @@ void tl2::details::DictionaryFieldAnyDoubleIntReset(::tl2::DictionaryFieldAny& item) { s << "{"; - s << "\"key\":"; - s << item.key; - s << ","; - s << "\"value\":"; - s << item.value; + if (item.key != 0) { + s << "\"key\":"; + s << item.key; + } + if (item.value != 0) { + s << ","; + s << "\"value\":"; + s << item.value; + } s << "}"; return true; } @@ -225,11 +229,15 @@ void tl2::details::DictionaryFieldAnyIntIntReset(::tl2::DictionaryFieldAny& item) { s << "{"; - s << "\"key\":"; - s << item.key; - s << ","; - s << "\"value\":"; - s << item.value; + if (item.key != 0) { + s << "\"key\":"; + s << item.key; + } + if (item.value != 0) { + s << ","; + s << "\"value\":"; + s << item.value; + } s << "}"; return true; } @@ -263,11 +271,15 @@ void tl2::details::DictionaryFieldIntReset(::tl2::DictionaryField& item bool tl2::details::DictionaryFieldIntWriteJSON(std::ostream& s, const ::tl2::DictionaryField& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; - s << ","; - s << "\"value\":"; - s << item.value; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } + if (item.value != 0) { + s << ","; + s << "\"value\":"; + s << item.value; + } s << "}"; return true; } diff --git a/internal/tlcodegen/test/gen/cases_cpp/benchmarks/details.cpp b/internal/tlcodegen/test/gen/cases_cpp/benchmarks/details.cpp index 1fe39b6c..735bc359 100644 --- a/internal/tlcodegen/test/gen/cases_cpp/benchmarks/details.cpp +++ b/internal/tlcodegen/test/gen/cases_cpp/benchmarks/details.cpp @@ -42,11 +42,15 @@ void tl2::details::BenchmarksVruHashReset(::tl2::benchmarks::Vruhash& item) { bool tl2::details::BenchmarksVruHashWriteJSON(std::ostream& s, const ::tl2::benchmarks::Vruhash& item) { s << "{"; - s << "\"low\":"; - s << item.low; - s << ","; - s << "\"high\":"; - s << item.high; + if (item.low != 0) { + s << "\"low\":"; + s << item.low; + } + if (item.high != 0) { + s << ","; + s << "\"high\":"; + s << item.high; + } s << "}"; return true; } @@ -114,8 +118,10 @@ void tl2::details::BenchmarksVruPositionReset(::tl2::benchmarks::Vruposition& it bool tl2::details::BenchmarksVruPositionWriteJSON(std::ostream& s, const ::tl2::benchmarks::Vruposition& item) { s << "{"; - s << "\"fields_mask\":"; - s << item.fields_mask; + if (item.fields_mask != 0) { + s << "\"fields_mask\":"; + s << item.fields_mask; + } if ((item.fields_mask & (1<<0)) != 0) { s << ","; s << "\"commit_bit\":"; @@ -141,22 +147,30 @@ bool tl2::details::BenchmarksVruPositionWriteJSON(std::ostream& s, const ::tl2:: s << "\"canonical_hash\":"; if (!::tl2::details::TrueWriteJSON(s, item.canonical_hash)) { return false; } } - s << ","; - s << "\"payload_offset\":"; - s << item.payload_offset; - s << ","; - s << "\"block_time_nano\":"; - s << item.block_time_nano; + if (item.payload_offset != 0) { + s << ","; + s << "\"payload_offset\":"; + s << item.payload_offset; + } + if (item.block_time_nano != 0) { + s << ","; + s << "\"block_time_nano\":"; + s << item.block_time_nano; + } s << ","; s << "\"hash\":"; if (!::tl2::details::BenchmarksVruHashWriteJSON(s, item.hash)) { return false; } - s << ","; - s << "\"file_offset\":"; - s << item.file_offset; - if ((item.fields_mask & (1<<14)) != 0) { + if (item.file_offset != 0) { s << ","; - s << "\"seq_number\":"; - s << item.seq_number; + s << "\"file_offset\":"; + s << item.file_offset; + } + if ((item.fields_mask & (1<<14)) != 0) { + if (item.seq_number != 0) { + s << ","; + s << "\"seq_number\":"; + s << item.seq_number; + } } s << "}"; return true; @@ -269,8 +283,10 @@ void tl2::details::BenchmarksVrutoyPositionsReset(::tl2::benchmarks::VrutoyPosit bool tl2::details::BenchmarksVrutoyPositionsWriteJSON(std::ostream& s, const ::tl2::benchmarks::VrutoyPositions& item, uint32_t nat_n) { s << "{"; - s << "\"next_positions\":"; - if (!::tl2::details::BuiltinTupleBenchmarksVruPositionWriteJSON(s, item.next_positions, nat_n)) { return false; } + if ((item.next_positions.size() != 0) || (nat_n != 0)) { + s << "\"next_positions\":"; + if (!::tl2::details::BuiltinTupleBenchmarksVruPositionWriteJSON(s, item.next_positions, nat_n)) { return false; } + } s << "}"; return true; } @@ -384,8 +400,10 @@ void tl2::details::BenchmarksVrutoyTopLevelContainerWithDependencyReset(::tl2::b bool tl2::details::BenchmarksVrutoyTopLevelContainerWithDependencyWriteJSON(std::ostream& s, const ::tl2::benchmarks::VrutoyTopLevelContainerWithDependency& item) { s << "{"; - s << "\"n\":"; - s << item.n; + if (item.n != 0) { + s << "\"n\":"; + s << item.n; + } s << ","; s << "\"value\":"; if (!::tl2::details::BenchmarksVrutoyPositionsWriteJSON(s, item.value, item.n)) { return false; } @@ -445,7 +463,7 @@ void tl2::details::BenchmarksVrutoyTopLevelUnionReset(::tl2::benchmarks::VrutoyT bool tl2::details::BenchmarksVrutoyTopLevelUnionWriteJSON(std::ostream & s, const ::tl2::benchmarks::VrutoyTopLevelUnion& item) { s << "{"; s << "\"type\":"; - s << BenchmarksVrutoyTopLevelUnion_tbl_tl_tag[item.value.index()]; + s << "\"" << BenchmarksVrutoyTopLevelUnion_tbl_tl_name[item.value.index()] << "\""; switch (item.value.index()) { case 0: s << ",\"value\":"; @@ -513,8 +531,10 @@ void tl2::details::BenchmarksVrutoytopLevelUnionBigReset(::tl2::benchmarks::Vrut bool tl2::details::BenchmarksVrutoytopLevelUnionBigWriteJSON(std::ostream& s, const ::tl2::benchmarks::VrutoytopLevelUnionBig& item) { s << "{"; - s << "\"next_positions\":"; - if (!::tl2::details::BuiltinVectorBenchmarksVruPositionWriteJSON(s, item.next_positions)) { return false; } + if (item.next_positions.size() != 0) { + s << "\"next_positions\":"; + if (!::tl2::details::BuiltinVectorBenchmarksVruPositionWriteJSON(s, item.next_positions)) { return false; } + } s << "}"; return true; } diff --git a/internal/tlcodegen/test/gen/cases_cpp/cases/details.cpp b/internal/tlcodegen/test/gen/cases_cpp/cases/details.cpp index bdd9f092..9aed71b3 100644 --- a/internal/tlcodegen/test/gen/cases_cpp/cases/details.cpp +++ b/internal/tlcodegen/test/gen/cases_cpp/cases/details.cpp @@ -217,8 +217,10 @@ void tl2::details::CasesMyCycle1Reset(::tl2::cases::MyCycle1& item) { bool tl2::details::CasesMyCycle1WriteJSON(std::ostream& s, const ::tl2::cases::MyCycle1& item) { s << "{"; - s << "\"fields_mask\":"; - s << item.fields_mask; + if (item.fields_mask != 0) { + s << "\"fields_mask\":"; + s << item.fields_mask; + } if ((item.fields_mask & (1<<0)) != 0) { s << ","; s << "\"a\":"; @@ -288,8 +290,10 @@ void tl2::details::CasesMyCycle2Reset(::tl2::cases::MyCycle2& item) { bool tl2::details::CasesMyCycle2WriteJSON(std::ostream& s, const ::tl2::cases::MyCycle2& item) { s << "{"; - s << "\"fields_mask\":"; - s << item.fields_mask; + if (item.fields_mask != 0) { + s << "\"fields_mask\":"; + s << item.fields_mask; + } if ((item.fields_mask & (1<<0)) != 0) { s << ","; s << "\"a\":"; @@ -362,8 +366,10 @@ void tl2::details::CasesMyCycle3Reset(::tl2::cases::MyCycle3& item) { bool tl2::details::CasesMyCycle3WriteJSON(std::ostream& s, const ::tl2::cases::MyCycle3& item) { s << "{"; - s << "\"fields_mask\":"; - s << item.fields_mask; + if (item.fields_mask != 0) { + s << "\"fields_mask\":"; + s << item.fields_mask; + } if ((item.fields_mask & (1<<0)) != 0) { s << ","; s << "\"a\":"; @@ -437,14 +443,20 @@ void tl2::details::CasesReplace7Reset(::tl2::cases::Replace7& item) { bool tl2::details::CasesReplace7WriteJSON(std::ostream& s, const ::tl2::cases::Replace7& item) { s << "{"; - s << "\"n\":"; - s << item.n; - s << ","; - s << "\"m\":"; - s << item.m; - s << ","; - s << "\"a\":"; - if (!::tl2::details::BuiltinTupleTupleIntWriteJSON(s, item.a, item.n, item.m)) { return false; } + if (item.n != 0) { + s << "\"n\":"; + s << item.n; + } + if (item.m != 0) { + s << ","; + s << "\"m\":"; + s << item.m; + } + if ((item.a.size() != 0) || (item.n != 0)) { + s << ","; + s << "\"a\":"; + if (!::tl2::details::BuiltinTupleTupleIntWriteJSON(s, item.a, item.n, item.m)) { return false; } + } s << "}"; return true; } @@ -506,15 +518,21 @@ void tl2::details::CasesReplace7plusReset(::tl2::cases::Replace7plus& item) { bool tl2::details::CasesReplace7plusWriteJSON(std::ostream& s, const ::tl2::cases::Replace7plus& item) { s << "{"; - s << "\"n\":"; - s << item.n; - s << ","; - s << "\"m\":"; - s << item.m; - if ((item.n & (1<<0)) != 0) { + if (item.n != 0) { + s << "\"n\":"; + s << item.n; + } + if (item.m != 0) { s << ","; - s << "\"a\":"; - if (!::tl2::details::BuiltinTupleTupleIntWriteJSON(s, item.a, item.n, item.m)) { return false; } + s << "\"m\":"; + s << item.m; + } + if ((item.n & (1<<0)) != 0) { + if ((item.a.size() != 0) || (item.n != 0)) { + s << ","; + s << "\"a\":"; + if (!::tl2::details::BuiltinTupleTupleIntWriteJSON(s, item.a, item.n, item.m)) { return false; } + } } s << "}"; return true; @@ -583,15 +601,21 @@ void tl2::details::CasesReplace7plusplusReset(::tl2::cases::Replace7plusplus& it bool tl2::details::CasesReplace7plusplusWriteJSON(std::ostream& s, const ::tl2::cases::Replace7plusplus& item) { s << "{"; - s << "\"N\":"; - s << item.N; - s << ","; - s << "\"M\":"; - s << item.M; - if ((item.N & (1<<0)) != 0) { + if (item.N != 0) { + s << "\"N\":"; + s << item.N; + } + if (item.M != 0) { s << ","; - s << "\"A\":"; - if (!::tl2::details::BuiltinTupleTupleIntWriteJSON(s, item.A, item.N, item.M)) { return false; } + s << "\"M\":"; + s << item.M; + } + if ((item.N & (1<<0)) != 0) { + if ((item.A.size() != 0) || (item.N != 0)) { + s << ","; + s << "\"A\":"; + if (!::tl2::details::BuiltinTupleTupleIntWriteJSON(s, item.A, item.N, item.M)) { return false; } + } } s << "}"; return true; @@ -670,24 +694,34 @@ void tl2::details::CasesTestAllPossibleFieldConfigsReset(::tl2::cases::TestAllPo bool tl2::details::CasesTestAllPossibleFieldConfigsWriteJSON(std::ostream& s, const ::tl2::cases::TestAllPossibleFieldConfigs& item, uint32_t nat_outer) { s << "{"; - s << "\"local\":"; - s << item.local; - s << ","; - s << "\"f00\":"; - s << item.f00; + if (item.local != 0) { + s << "\"local\":"; + s << item.local; + } + if (item.f00 != 0) { + s << ","; + s << "\"f00\":"; + s << item.f00; + } s << ","; s << "\"f01\":"; if (!::tl2::details::TrueWriteJSON(s, item.f01)) { return false; } - s << ","; - s << "\"f02\":"; - if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.f02, item.local)) { return false; } - s << ","; - s << "\"f03\":"; - if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.f03, nat_outer)) { return false; } - if ((item.local & (1<<0)) != 0) { + if ((item.f02.size() != 0) || (item.local != 0)) { s << ","; - s << "\"f10\":"; - s << item.f10; + s << "\"f02\":"; + if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.f02, item.local)) { return false; } + } + if ((item.f03.size() != 0) || (nat_outer != 0)) { + s << ","; + s << "\"f03\":"; + if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.f03, nat_outer)) { return false; } + } + if ((item.local & (1<<0)) != 0) { + if (item.f10 != 0) { + s << ","; + s << "\"f10\":"; + s << item.f10; + } } if ((item.local & (1<<1)) != 0) { s << ","; @@ -695,19 +729,25 @@ bool tl2::details::CasesTestAllPossibleFieldConfigsWriteJSON(std::ostream& s, co if (!::tl2::details::TrueWriteJSON(s, item.f11)) { return false; } } if ((item.local & (1<<2)) != 0) { - s << ","; - s << "\"f12\":"; - if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.f12, item.local)) { return false; } + if ((item.f12.size() != 0) || (item.local != 0)) { + s << ","; + s << "\"f12\":"; + if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.f12, item.local)) { return false; } + } } if ((item.local & (1<<3)) != 0) { - s << ","; - s << "\"f13\":"; - if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.f13, nat_outer)) { return false; } + if ((item.f13.size() != 0) || (nat_outer != 0)) { + s << ","; + s << "\"f13\":"; + if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.f13, nat_outer)) { return false; } + } } if ((nat_outer & (1<<0)) != 0) { - s << ","; - s << "\"f20\":"; - s << item.f20; + if (item.f20 != 0) { + s << ","; + s << "\"f20\":"; + s << item.f20; + } } if ((nat_outer & (1<<1)) != 0) { s << ","; @@ -715,14 +755,18 @@ bool tl2::details::CasesTestAllPossibleFieldConfigsWriteJSON(std::ostream& s, co if (!::tl2::details::TrueWriteJSON(s, item.f21)) { return false; } } if ((nat_outer & (1<<2)) != 0) { - s << ","; - s << "\"f22\":"; - if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.f22, item.local)) { return false; } + if ((item.f22.size() != 0) || (item.local != 0)) { + s << ","; + s << "\"f22\":"; + if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.f22, item.local)) { return false; } + } } if ((nat_outer & (1<<3)) != 0) { - s << ","; - s << "\"f23\":"; - if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.f23, nat_outer)) { return false; } + if ((item.f23.size() != 0) || (nat_outer != 0)) { + s << ","; + s << "\"f23\":"; + if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.f23, nat_outer)) { return false; } + } } s << "}"; return true; @@ -852,8 +896,10 @@ void tl2::details::CasesTestAllPossibleFieldConfigsContainerReset(::tl2::cases:: bool tl2::details::CasesTestAllPossibleFieldConfigsContainerWriteJSON(std::ostream& s, const ::tl2::cases::TestAllPossibleFieldConfigsContainer& item) { s << "{"; - s << "\"outer\":"; - s << item.outer; + if (item.outer != 0) { + s << "\"outer\":"; + s << item.outer; + } s << ","; s << "\"value\":"; if (!::tl2::details::CasesTestAllPossibleFieldConfigsWriteJSON(s, item.value, item.outer)) { return false; } @@ -915,11 +961,15 @@ void tl2::details::CasesTestArrayReset(::tl2::cases::TestArray& item) { bool tl2::details::CasesTestArrayWriteJSON(std::ostream& s, const ::tl2::cases::TestArray& item) { s << "{"; - s << "\"n\":"; - s << item.n; - s << ","; - s << "\"arr\":"; - if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.arr, item.n)) { return false; } + if (item.n != 0) { + s << "\"n\":"; + s << item.n; + } + if ((item.arr.size() != 0) || (item.n != 0)) { + s << ","; + s << "\"arr\":"; + if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.arr, item.n)) { return false; } + } s << "}"; return true; } @@ -979,17 +1029,23 @@ void tl2::details::CasesTestBeforeReadBitValidationReset(::tl2::cases::TestBefor bool tl2::details::CasesTestBeforeReadBitValidationWriteJSON(std::ostream& s, const ::tl2::cases::TestBeforeReadBitValidation& item) { s << "{"; - s << "\"n\":"; - s << item.n; + if (item.n != 0) { + s << "\"n\":"; + s << item.n; + } if ((item.n & (1<<0)) != 0) { - s << ","; - s << "\"a\":"; - if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.a, item.n)) { return false; } + if ((item.a.size() != 0) || (item.n != 0)) { + s << ","; + s << "\"a\":"; + if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.a, item.n)) { return false; } + } } if ((item.n & (1<<1)) != 0) { - s << ","; - s << "\"b\":"; - if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.b, item.n)) { return false; } + if ((item.b.size() != 0) || (item.n != 0)) { + s << ","; + s << "\"b\":"; + if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.b, item.n)) { return false; } + } } s << "}"; return true; @@ -1062,8 +1118,10 @@ void tl2::details::CasesTestDictAnyReset(::tl2::cases::TestDictAny& item) { bool tl2::details::CasesTestDictAnyWriteJSON(std::ostream& s, const ::tl2::cases::TestDictAny& item) { s << "{"; - s << "\"dict\":"; - if (!::tl2::details::DictionaryAnyDoubleIntWriteJSON(s, item.dict)) { return false; } + if (item.dict.size() != 0) { + s << "\"dict\":"; + if (!::tl2::details::DictionaryAnyDoubleIntWriteJSON(s, item.dict)) { return false; } + } s << "}"; return true; } @@ -1119,8 +1177,10 @@ void tl2::details::CasesTestDictIntReset(::tl2::cases::TestDictInt& item) { bool tl2::details::CasesTestDictIntWriteJSON(std::ostream& s, const ::tl2::cases::TestDictInt& item) { s << "{"; - s << "\"dict\":"; - if (!::tl2::details::BuiltinVectorDictionaryFieldAnyIntIntWriteJSON(s, item.dict)) { return false; } + if (item.dict.size() != 0) { + s << "\"dict\":"; + if (!::tl2::details::BuiltinVectorDictionaryFieldAnyIntIntWriteJSON(s, item.dict)) { return false; } + } s << "}"; return true; } @@ -1176,8 +1236,10 @@ void tl2::details::CasesTestDictStringReset(::tl2::cases::TestDictString& item) bool tl2::details::CasesTestDictStringWriteJSON(std::ostream& s, const ::tl2::cases::TestDictString& item) { s << "{"; - s << "\"dict\":"; - if (!::tl2::details::DictionaryIntWriteJSON(s, item.dict)) { return false; } + if (item.dict.size() != 0) { + s << "\"dict\":"; + if (!::tl2::details::DictionaryIntWriteJSON(s, item.dict)) { return false; } + } s << "}"; return true; } @@ -1230,12 +1292,7 @@ void tl2::details::CasesTestEnumReset(::tl2::cases::TestEnum& item) { } bool tl2::details::CasesTestEnumWriteJSON(std::ostream & s, const ::tl2::cases::TestEnum& item) { - s << "{"; - s << "\"type\":"; - s << CasesTestEnum_tbl_tl_tag[item.value.index()]; - switch (item.value.index()) { - } - s << "}"; + s << "\"" << CasesTestEnum_tbl_tl_name[item.value.index()] << "\""; return true; } bool tl2::details::CasesTestEnumReadBoxed(::basictl::tl_istream & s, ::tl2::cases::TestEnum& item) { @@ -1511,12 +1568,16 @@ void tl2::details::CasesTestLocalFieldmaskReset(::tl2::cases::TestLocalFieldmask bool tl2::details::CasesTestLocalFieldmaskWriteJSON(std::ostream& s, const ::tl2::cases::TestLocalFieldmask& item) { s << "{"; - s << "\"f1\":"; - s << item.f1; + if (item.f1 != 0) { + s << "\"f1\":"; + s << item.f1; + } if ((item.f1 & (1<<0)) != 0) { - s << ","; - s << "\"f2\":"; - s << item.f2; + if (item.f2 != 0) { + s << ","; + s << "\"f2\":"; + s << item.f2; + } } if ((item.f2 & (1<<1)) != 0) { s << ","; @@ -1607,8 +1668,10 @@ void tl2::details::CasesTestMaybeReset(::tl2::cases::TestMaybe& item) { bool tl2::details::CasesTestMaybeWriteJSON(std::ostream& s, const ::tl2::cases::TestMaybe& item) { s << "{"; - s << "\"value\":"; - if (!::tl2::details::IntMaybeWriteJSON(s, item.value)) { return false; } + if (item.value.has_value()) { + s << "\"value\":"; + if (!::tl2::details::IntMaybeWriteJSON(s, item.value)) { return false; } + } s << "}"; return true; } @@ -1667,17 +1730,21 @@ void tl2::details::CasesTestOutFieldMaskReset(::tl2::cases::TestOutFieldMask& it bool tl2::details::CasesTestOutFieldMaskWriteJSON(std::ostream& s, const ::tl2::cases::TestOutFieldMask& item, uint32_t nat_f) { s << "{"; if ((nat_f & (1<<0)) != 0) { - s << "\"f1\":"; - s << item.f1; + if (item.f1 != 0) { + s << "\"f1\":"; + s << item.f1; + } } if ((nat_f & (1<<3)) != 0) { s << ","; s << "\"f2\":"; if (!::tl2::details::TrueWriteJSON(s, item.f2)) { return false; } } - s << ","; - s << "\"f3\":"; - if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.f3, nat_f)) { return false; } + if ((item.f3.size() != 0) || (nat_f != 0)) { + s << ","; + s << "\"f3\":"; + if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.f3, nat_f)) { return false; } + } s << "}"; return true; } @@ -1750,8 +1817,10 @@ void tl2::details::CasesTestOutFieldMaskContainerReset(::tl2::cases::TestOutFiel bool tl2::details::CasesTestOutFieldMaskContainerWriteJSON(std::ostream& s, const ::tl2::cases::TestOutFieldMaskContainer& item) { s << "{"; - s << "\"f\":"; - s << item.f; + if (item.f != 0) { + s << "\"f\":"; + s << item.f; + } s << ","; s << "\"inner\":"; if (!::tl2::details::CasesTestOutFieldMaskWriteJSON(s, item.inner, item.f)) { return false; } @@ -1817,17 +1886,23 @@ void tl2::details::CasesTestRecursiveFieldmaskReset(::tl2::cases::TestRecursiveF bool tl2::details::CasesTestRecursiveFieldmaskWriteJSON(std::ostream& s, const ::tl2::cases::TestRecursiveFieldMask& item) { s << "{"; - s << "\"f0\":"; - s << item.f0; + if (item.f0 != 0) { + s << "\"f0\":"; + s << item.f0; + } if ((item.f0 & (1<<0)) != 0) { - s << ","; - s << "\"f1\":"; - s << item.f1; + if (item.f1 != 0) { + s << ","; + s << "\"f1\":"; + s << item.f1; + } } if ((item.f1 & (1<<1)) != 0) { - s << ","; - s << "\"f2\":"; - s << item.f2; + if (item.f2 != 0) { + s << ","; + s << "\"f2\":"; + s << item.f2; + } } if ((item.f0 & (1<<0)) != 0) { s << ","; @@ -1995,7 +2070,7 @@ void tl2::details::CasesTestUnionReset(::tl2::cases::TestUnion& item) { bool tl2::details::CasesTestUnionWriteJSON(std::ostream & s, const ::tl2::cases::TestUnion& item) { s << "{"; s << "\"type\":"; - s << CasesTestUnion_tbl_tl_tag[item.value.index()]; + s << "\"" << CasesTestUnion_tbl_tl_name[item.value.index()] << "\""; switch (item.value.index()) { case 0: s << ",\"value\":"; @@ -2071,8 +2146,10 @@ void tl2::details::CasesTestUnion1Reset(::tl2::cases::TestUnion1& item) { bool tl2::details::CasesTestUnion1WriteJSON(std::ostream& s, const ::tl2::cases::TestUnion1& item) { s << "{"; - s << "\"value\":"; - s << item.value; + if (item.value != 0) { + s << "\"value\":"; + s << item.value; + } s << "}"; return true; } @@ -2128,8 +2205,10 @@ void tl2::details::CasesTestUnion2Reset(::tl2::cases::TestUnion2& item) { bool tl2::details::CasesTestUnion2WriteJSON(std::ostream& s, const ::tl2::cases::TestUnion2& item) { s << "{"; - s << "\"value\":"; - s << "\"" << item.value << "\""; + if (item.value.size() != 0) { + s << "\"value\":"; + s << "\"" << item.value << "\""; + } s << "}"; return true; } @@ -2242,8 +2321,10 @@ void tl2::details::CasesTestVectorReset(::tl2::cases::TestVector& item) { bool tl2::details::CasesTestVectorWriteJSON(std::ostream& s, const ::tl2::cases::TestVector& item) { s << "{"; - s << "\"arr\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.arr)) { return false; } + if (item.arr.size() != 0) { + s << "\"arr\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.arr)) { return false; } + } s << "}"; return true; } diff --git a/internal/tlcodegen/test/gen/cases_cpp/cases_bytes/details.cpp b/internal/tlcodegen/test/gen/cases_cpp/cases_bytes/details.cpp index 56e607fe..7b24cf60 100644 --- a/internal/tlcodegen/test/gen/cases_cpp/cases_bytes/details.cpp +++ b/internal/tlcodegen/test/gen/cases_cpp/cases_bytes/details.cpp @@ -199,11 +199,15 @@ void tl2::details::CasesBytesTestArrayReset(::tl2::cases_bytes::TestArray& item) bool tl2::details::CasesBytesTestArrayWriteJSON(std::ostream& s, const ::tl2::cases_bytes::TestArray& item) { s << "{"; - s << "\"n\":"; - s << item.n; - s << ","; - s << "\"arr\":"; - if (!::tl2::details::BuiltinTupleStringWriteJSON(s, item.arr, item.n)) { return false; } + if (item.n != 0) { + s << "\"n\":"; + s << item.n; + } + if ((item.arr.size() != 0) || (item.n != 0)) { + s << ","; + s << "\"arr\":"; + if (!::tl2::details::BuiltinTupleStringWriteJSON(s, item.arr, item.n)) { return false; } + } s << "}"; return true; } @@ -261,8 +265,10 @@ void tl2::details::CasesBytesTestDictAnyReset(::tl2::cases_bytes::TestDictAny& i bool tl2::details::CasesBytesTestDictAnyWriteJSON(std::ostream& s, const ::tl2::cases_bytes::TestDictAny& item) { s << "{"; - s << "\"dict\":"; - if (!::tl2::details::DictionaryAnyDoubleIntWriteJSON(s, item.dict)) { return false; } + if (item.dict.size() != 0) { + s << "\"dict\":"; + if (!::tl2::details::DictionaryAnyDoubleIntWriteJSON(s, item.dict)) { return false; } + } s << "}"; return true; } @@ -318,8 +324,10 @@ void tl2::details::CasesBytesTestDictIntReset(::tl2::cases_bytes::TestDictInt& i bool tl2::details::CasesBytesTestDictIntWriteJSON(std::ostream& s, const ::tl2::cases_bytes::TestDictInt& item) { s << "{"; - s << "\"dict\":"; - if (!::tl2::details::BuiltinVectorDictionaryFieldAnyIntIntWriteJSON(s, item.dict)) { return false; } + if (item.dict.size() != 0) { + s << "\"dict\":"; + if (!::tl2::details::BuiltinVectorDictionaryFieldAnyIntIntWriteJSON(s, item.dict)) { return false; } + } s << "}"; return true; } @@ -375,8 +383,10 @@ void tl2::details::CasesBytesTestDictStringReset(::tl2::cases_bytes::TestDictStr bool tl2::details::CasesBytesTestDictStringWriteJSON(std::ostream& s, const ::tl2::cases_bytes::TestDictString& item) { s << "{"; - s << "\"dict\":"; - if (!::tl2::details::DictionaryIntWriteJSON(s, item.dict)) { return false; } + if (item.dict.size() != 0) { + s << "\"dict\":"; + if (!::tl2::details::DictionaryIntWriteJSON(s, item.dict)) { return false; } + } s << "}"; return true; } @@ -432,8 +442,10 @@ void tl2::details::CasesBytesTestDictStringStringReset(::tl2::cases_bytes::TestD bool tl2::details::CasesBytesTestDictStringStringWriteJSON(std::ostream& s, const ::tl2::cases_bytes::TestDictStringString& item) { s << "{"; - s << "\"dict\":"; - if (!::tl2::details::DictionaryStringWriteJSON(s, item.dict)) { return false; } + if (item.dict.size() != 0) { + s << "\"dict\":"; + if (!::tl2::details::DictionaryStringWriteJSON(s, item.dict)) { return false; } + } s << "}"; return true; } @@ -486,12 +498,7 @@ void tl2::details::CasesBytesTestEnumReset(::tl2::cases_bytes::TestEnum& item) { } bool tl2::details::CasesBytesTestEnumWriteJSON(std::ostream & s, const ::tl2::cases_bytes::TestEnum& item) { - s << "{"; - s << "\"type\":"; - s << CasesBytesTestEnum_tbl_tl_tag[item.value.index()]; - switch (item.value.index()) { - } - s << "}"; + s << "\"" << CasesBytesTestEnum_tbl_tl_name[item.value.index()] << "\""; return true; } bool tl2::details::CasesBytesTestEnumReadBoxed(::basictl::tl_istream & s, ::tl2::cases_bytes::TestEnum& item) { @@ -821,8 +828,10 @@ void tl2::details::CasesBytesTestVectorReset(::tl2::cases_bytes::TestVector& ite bool tl2::details::CasesBytesTestVectorWriteJSON(std::ostream& s, const ::tl2::cases_bytes::TestVector& item) { s << "{"; - s << "\"arr\":"; - if (!::tl2::details::BuiltinVectorStringWriteJSON(s, item.arr)) { return false; } + if (item.arr.size() != 0) { + s << "\"arr\":"; + if (!::tl2::details::BuiltinVectorStringWriteJSON(s, item.arr)) { return false; } + } s << "}"; return true; } @@ -854,11 +863,15 @@ void tl2::details::DictionaryFieldStringReset(::tl2::DictionaryField& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; - s << ","; - s << "\"value\":"; - s << "\"" << item.value << "\""; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } + if (item.value.size() != 0) { + s << ","; + s << "\"value\":"; + s << "\"" << item.value << "\""; + } s << "}"; return true; } diff --git a/internal/tlcodegen/test/gen/schema_cpp/__common_namespace/details.cpp b/internal/tlcodegen/test/gen/schema_cpp/__common_namespace/details.cpp index cc89b13d..3d3108e1 100644 --- a/internal/tlcodegen/test/gen/schema_cpp/__common_namespace/details.cpp +++ b/internal/tlcodegen/test/gen/schema_cpp/__common_namespace/details.cpp @@ -100,11 +100,15 @@ void tl2::details::BenchObjectReset(::tl2::BenchObject& item) { bool tl2::details::BenchObjectWriteJSON(std::ostream& s, const ::tl2::BenchObject& item) { s << "{"; - s << "\"xs\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.xs)) { return false; } - s << ","; - s << "\"ys\":"; - if (!::tl2::details::BuiltinVectorIntegerWriteJSON(s, item.ys)) { return false; } + if (item.xs.size() != 0) { + s << "\"xs\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.xs)) { return false; } + } + if (item.ys.size() != 0) { + s << ","; + s << "\"ys\":"; + if (!::tl2::details::BuiltinVectorIntegerWriteJSON(s, item.ys)) { return false; } + } s << "}"; return true; } @@ -252,8 +256,10 @@ void tl2::details::BoxedIntReset(::tl2::BoxedInt& item) { bool tl2::details::BoxedIntWriteJSON(std::ostream& s, const ::tl2::BoxedInt& item) { s << "{"; - s << "\"x\":"; - s << item.x; + if (item.x != 0) { + s << "\"x\":"; + s << item.x; + } s << "}"; return true; } @@ -329,8 +335,10 @@ void tl2::details::BoxedStringReset(::tl2::BoxedString& item) { bool tl2::details::BoxedStringWriteJSON(std::ostream& s, const ::tl2::BoxedString& item) { s << "{"; - s << "\"x\":"; - s << "\"" << item.x << "\""; + if (item.x.size() != 0) { + s << "\"x\":"; + s << "\"" << item.x << "\""; + } s << "}"; return true; } @@ -484,11 +492,15 @@ void tl2::details::BoxedTupleSlice1Reset(::tl2::BoxedTupleSlice1& item) { bool tl2::details::BoxedTupleSlice1WriteJSON(std::ostream& s, const ::tl2::BoxedTupleSlice1& item) { s << "{"; - s << "\"n\":"; - s << item.n; - s << ","; - s << "\"x\":"; - if (!::tl2::details::BuiltinTupleIntBoxedWriteJSON(s, item.x, item.n)) { return false; } + if (item.n != 0) { + s << "\"n\":"; + s << item.n; + } + if ((item.x.size() != 0) || (item.n != 0)) { + s << ","; + s << "\"x\":"; + if (!::tl2::details::BuiltinTupleIntBoxedWriteJSON(s, item.x, item.n)) { return false; } + } s << "}"; return true; } @@ -640,11 +652,15 @@ void tl2::details::BoxedTupleSlice3Reset(::tl2::BoxedTupleSlice3& item) { bool tl2::details::BoxedTupleSlice3WriteJSON(std::ostream& s, const ::tl2::BoxedTupleSlice3& item) { s << "{"; - s << "\"n\":"; - s << item.n; - s << ","; - s << "\"x\":"; - if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.x, item.n)) { return false; } + if (item.n != 0) { + s << "\"n\":"; + s << item.n; + } + if ((item.x.size() != 0) || (item.n != 0)) { + s << ","; + s << "\"x\":"; + if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.x, item.n)) { return false; } + } s << "}"; return true; } @@ -722,8 +738,10 @@ void tl2::details::BoxedVector32Reset(::tl2::BoxedVector32& item) { bool tl2::details::BoxedVector32WriteJSON(std::ostream& s, const ::tl2::BoxedVector32& item) { s << "{"; - s << "\"x\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.x)) { return false; } + if (item.x.size() != 0) { + s << "\"x\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.x)) { return false; } + } s << "}"; return true; } @@ -799,8 +817,10 @@ void tl2::details::BoxedVector32BoxedElemReset(::tl2::BoxedVector32BoxedElem& it bool tl2::details::BoxedVector32BoxedElemWriteJSON(std::ostream& s, const ::tl2::BoxedVector32BoxedElem& item) { s << "{"; - s << "\"x\":"; - if (!::tl2::details::BuiltinVectorIntBoxedWriteJSON(s, item.x)) { return false; } + if (item.x.size() != 0) { + s << "\"x\":"; + if (!::tl2::details::BuiltinVectorIntBoxedWriteJSON(s, item.x)) { return false; } + } s << "}"; return true; } @@ -876,8 +896,10 @@ void tl2::details::BoxedVector64Reset(::tl2::BoxedVector64& item) { bool tl2::details::BoxedVector64WriteJSON(std::ostream& s, const ::tl2::BoxedVector64& item) { s << "{"; - s << "\"x\":"; - if (!::tl2::details::BuiltinVectorLongBoxedWriteJSON(s, item.x)) { return false; } + if (item.x.size() != 0) { + s << "\"x\":"; + if (!::tl2::details::BuiltinVectorLongBoxedWriteJSON(s, item.x)) { return false; } + } s << "}"; return true; } @@ -1488,11 +1510,15 @@ void tl2::details::DictionaryFieldIntReset(::tl2::DictionaryField& item bool tl2::details::DictionaryFieldIntWriteJSON(std::ostream& s, const ::tl2::DictionaryField& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; - s << ","; - s << "\"value\":"; - s << item.value; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } + if (item.value != 0) { + s << ","; + s << "\"value\":"; + s << item.value; + } s << "}"; return true; } @@ -1587,7 +1613,7 @@ void tl2::details::EitherIntVectorService6FindWithBoundsResultReset(::tl2::Eithe bool tl2::details::EitherIntVectorService6FindWithBoundsResultWriteJSON(std::ostream & s, const ::tl2::Either>& item) { s << "{"; s << "\"type\":"; - s << EitherIntVectorService6FindWithBoundsResult_tbl_tl_tag[item.value.index()]; + s << "\"" << EitherIntVectorService6FindWithBoundsResult_tbl_tl_name[item.value.index()] << "\""; switch (item.value.index()) { case 0: s << ",\"value\":"; @@ -1642,7 +1668,7 @@ void tl2::details::EitherService6ErrorVectorService6FindResultRowReset(::tl2::Ei bool tl2::details::EitherService6ErrorVectorService6FindResultRowWriteJSON(std::ostream & s, const ::tl2::Either<::tl2::service6::Error, std::vector<::tl2::service6::FindResultRow>>& item) { s << "{"; s << "\"type\":"; - s << EitherService6ErrorVectorService6FindResultRow_tbl_tl_tag[item.value.index()]; + s << "\"" << EitherService6ErrorVectorService6FindResultRow_tbl_tl_name[item.value.index()] << "\""; switch (item.value.index()) { case 0: s << ",\"value\":"; @@ -1719,11 +1745,15 @@ void tl2::details::FieldConflict1Reset(::tl2::FieldConflict1& item) { bool tl2::details::FieldConflict1WriteJSON(std::ostream& s, const ::tl2::FieldConflict1& item) { s << "{"; - s << "\"x\":"; - s << item.x; - s << ","; - s << "\"set_x\":"; - s << item.set_x; + if (item.x != 0) { + s << "\"x\":"; + s << item.x; + } + if (item.set_x != 0) { + s << ","; + s << "\"set_x\":"; + s << item.set_x; + } s << "}"; return true; } @@ -1782,11 +1812,15 @@ void tl2::details::FieldConflict2Reset(::tl2::FieldConflict2& item) { bool tl2::details::FieldConflict2WriteJSON(std::ostream& s, const ::tl2::FieldConflict2& item) { s << "{"; - s << "\"x\":"; - s << item.x; - s << ","; - s << "\"setX\":"; - s << item.setX; + if (item.x != 0) { + s << "\"x\":"; + s << item.x; + } + if (item.setX != 0) { + s << ","; + s << "\"setX\":"; + s << item.setX; + } s << "}"; return true; } @@ -1845,11 +1879,15 @@ void tl2::details::FieldConflict3Reset(::tl2::FieldConflict3& item) { bool tl2::details::FieldConflict3WriteJSON(std::ostream& s, const ::tl2::FieldConflict3& item) { s << "{"; - s << "\"x\":"; - s << item.x; - s << ","; - s << "\"SetX\":"; - s << item.SetX; + if (item.x != 0) { + s << "\"x\":"; + s << item.x; + } + if (item.SetX != 0) { + s << ","; + s << "\"SetX\":"; + s << item.SetX; + } s << "}"; return true; } @@ -1908,11 +1946,15 @@ void tl2::details::FieldConflict4Reset(::tl2::FieldConflict4& item) { bool tl2::details::FieldConflict4WriteJSON(std::ostream& s, const ::tl2::FieldConflict4& item) { s << "{"; - s << "\"X\":"; - s << item.X; - s << ","; - s << "\"SetX\":"; - s << item.SetX; + if (item.X != 0) { + s << "\"X\":"; + s << item.X; + } + if (item.SetX != 0) { + s << ","; + s << "\"SetX\":"; + s << item.SetX; + } s << "}"; return true; } @@ -2001,11 +2043,15 @@ void tl2::details::GetArraysReset(::tl2::Get_arrays& item) { bool tl2::details::GetArraysWriteJSON(std::ostream& s, const ::tl2::Get_arrays& item) { s << "{"; - s << "\"n\":"; - s << item.n; - s << ","; - s << "\"a\":"; - if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.a, item.n)) { return false; } + if (item.n != 0) { + s << "\"n\":"; + s << item.n; + } + if ((item.a.size() != 0) || (item.n != 0)) { + s << ","; + s << "\"a\":"; + if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.a, item.n)) { return false; } + } s << ","; s << "\"b\":"; if (!::tl2::details::BuiltinTuple5IntWriteJSON(s, item.b)) { return false; } @@ -2086,8 +2132,10 @@ void tl2::details::GetDoubleReset(::tl2::GetDouble& item) { bool tl2::details::GetDoubleWriteJSON(std::ostream& s, const ::tl2::GetDouble& item) { s << "{"; - s << "\"x\":"; - s << item.x; + if (item.x != 0) { + s << "\"x\":"; + s << item.x; + } s << "}"; return true; } @@ -2163,8 +2211,10 @@ void tl2::details::GetFloatReset(::tl2::GetFloat& item) { bool tl2::details::GetFloatWriteJSON(std::ostream& s, const ::tl2::GetFloat& item) { s << "{"; - s << "\"x\":"; - s << item.x; + if (item.x != 0) { + s << "\"x\":"; + s << item.x; + } s << "}"; return true; } @@ -2311,8 +2361,10 @@ void tl2::details::GetMyDictOfIntReset(::tl2::GetMyDictOfInt& item) { bool tl2::details::GetMyDictOfIntWriteJSON(std::ostream& s, const ::tl2::GetMyDictOfInt& item) { s << "{"; - s << "\"x\":"; - if (!::tl2::details::MyDictOfIntWriteJSON(s, item.x)) { return false; } + if (item.x.size() != 0) { + s << "\"x\":"; + if (!::tl2::details::MyDictOfIntWriteJSON(s, item.x)) { return false; } + } s << "}"; return true; } @@ -2384,8 +2436,10 @@ void tl2::details::GetMyDoubleReset(::tl2::GetMyDouble& item) { bool tl2::details::GetMyDoubleWriteJSON(std::ostream& s, const ::tl2::GetMyDouble& item) { s << "{"; - s << "\"x\":"; - if (!::tl2::details::MyDoubleWriteJSON(s, item.x)) { return false; } + if (item.x != 0) { + s << "\"x\":"; + if (!::tl2::details::MyDoubleWriteJSON(s, item.x)) { return false; } + } s << "}"; return true; } @@ -2531,11 +2585,15 @@ void tl2::details::GetNonOptNatReset(::tl2::GetNonOptNat& item) { bool tl2::details::GetNonOptNatWriteJSON(std::ostream& s, const ::tl2::GetNonOptNat& item) { s << "{"; - s << "\"n\":"; - s << item.n; - s << ","; - s << "\"xs\":"; - if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.xs, item.n)) { return false; } + if (item.n != 0) { + s << "\"n\":"; + s << item.n; + } + if ((item.xs.size() != 0) || (item.n != 0)) { + s << ","; + s << "\"xs\":"; + if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.xs, item.n)) { return false; } + } s << "}"; return true; } @@ -2747,8 +2805,10 @@ void tl2::details::IntegerReset(::tl2::Integer& item) { bool tl2::details::IntegerWriteJSON(std::ostream& s, const ::tl2::Integer& item) { s << "{"; - s << "\"value\":"; - s << item.value; + if (item.value != 0) { + s << "\"value\":"; + s << item.value; + } s << "}"; return true; } @@ -2804,8 +2864,10 @@ void tl2::details::Issue3498Reset(::tl2::Issue3498& item) { bool tl2::details::Issue3498WriteJSON(std::ostream& s, const ::tl2::Issue3498& item) { s << "{"; - s << "\"x\":"; - if (!::tl2::details::BuiltinVectorEitherService6ErrorVectorService6FindResultRowWriteJSON(s, item.x)) { return false; } + if (item.x.size() != 0) { + s << "\"x\":"; + if (!::tl2::details::BuiltinVectorEitherService6ErrorVectorService6FindResultRowWriteJSON(s, item.x)) { return false; } + } s << "}"; return true; } @@ -2838,8 +2900,10 @@ void tl2::details::LeftIntVectorService6FindWithBoundsResultReset(::tl2::Left>& item) { s << "{"; - s << "\"value\":"; - s << item.value; + if (item.value != 0) { + s << "\"value\":"; + s << item.value; + } s << "}"; return true; } @@ -2932,11 +2996,15 @@ void tl2::details::MapStringStringReset(::tl2::Map& it bool tl2::details::MapStringStringWriteJSON(std::ostream& s, const ::tl2::Map& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; - s << ","; - s << "\"value\":"; - s << "\"" << item.value << "\""; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } + if (item.value.size() != 0) { + s << ","; + s << "\"value\":"; + s << "\"" << item.value << "\""; + } s << "}"; return true; } @@ -3083,11 +3151,15 @@ void tl2::details::MyBoxedTupleSliceReset(::tl2::MyBoxedTupleSlice& item) { bool tl2::details::MyBoxedTupleSliceWriteJSON(std::ostream& s, const ::tl2::MyBoxedTupleSlice& item) { s << "{"; - s << "\"n\":"; - s << item.n; - s << ","; - s << "\"data\":"; - if (!::tl2::details::BuiltinTupleIntBoxedWriteJSON(s, item.data, item.n)) { return false; } + if (item.n != 0) { + s << "\"n\":"; + s << item.n; + } + if ((item.data.size() != 0) || (item.n != 0)) { + s << ","; + s << "\"data\":"; + if (!::tl2::details::BuiltinTupleIntBoxedWriteJSON(s, item.data, item.n)) { return false; } + } s << "}"; return true; } @@ -3147,8 +3219,10 @@ void tl2::details::MyBoxedVectorSliceReset(::tl2::MyBoxedVectorSlice& item) { bool tl2::details::MyBoxedVectorSliceWriteJSON(std::ostream& s, const ::tl2::MyBoxedVectorSlice& item) { s << "{"; - s << "\"data\":"; - if (!::tl2::details::BuiltinVectorIntBoxedWriteJSON(s, item.data)) { return false; } + if (item.data.size() != 0) { + s << "\"data\":"; + if (!::tl2::details::BuiltinVectorIntBoxedWriteJSON(s, item.data)) { return false; } + } s << "}"; return true; } @@ -3266,8 +3340,10 @@ void tl2::details::MyIntReset(::tl2::MyInt& item) { bool tl2::details::MyIntWriteJSON(std::ostream& s, const ::tl2::MyInt& item) { s << "{"; - s << "\"val1\":"; - s << item.val1; + if (item.val1 != 0) { + s << "\"val1\":"; + s << item.val1; + } s << "}"; return true; } @@ -3497,8 +3573,10 @@ void tl2::details::MyMcValueVectorReset(::tl2::MyMcValueVector& item) { bool tl2::details::MyMcValueVectorWriteJSON(std::ostream& s, const ::tl2::MyMcValueVector& item) { s << "{"; - s << "\"xs\":"; - if (!::tl2::details::BuiltinVectorService1ValueWriteJSON(s, item.xs)) { return false; } + if (item.xs.size() != 0) { + s << "\"xs\":"; + if (!::tl2::details::BuiltinVectorService1ValueWriteJSON(s, item.xs)) { return false; } + } s << "}"; return true; } @@ -3554,8 +3632,10 @@ void tl2::details::MyStringReset(::tl2::MyString& item) { bool tl2::details::MyStringWriteJSON(std::ostream& s, const ::tl2::MyString& item) { s << "{"; - s << "\"val2\":"; - s << "\"" << item.val2 << "\""; + if (item.val2.size() != 0) { + s << "\"val2\":"; + s << "\"" << item.val2 << "\""; + } s << "}"; return true; } @@ -3677,11 +3757,15 @@ void tl2::details::MyTwoDictsReset(::tl2::MyTwoDicts& item) { bool tl2::details::MyTwoDictsWriteJSON(std::ostream& s, const ::tl2::MyTwoDicts& item) { s << "{"; - s << "\"a\":"; - if (!::tl2::details::DictionaryIntWriteJSON(s, item.a)) { return false; } - s << ","; - s << "\"b\":"; - if (!::tl2::details::DictionaryIntWriteJSON(s, item.b)) { return false; } + if (item.a.size() != 0) { + s << "\"a\":"; + if (!::tl2::details::DictionaryIntWriteJSON(s, item.a)) { return false; } + } + if (item.b.size() != 0) { + s << ","; + s << "\"b\":"; + if (!::tl2::details::DictionaryIntWriteJSON(s, item.b)) { return false; } + } s << "}"; return true; } @@ -3738,7 +3822,7 @@ void tl2::details::MyValueReset(::tl2::MyValue& item) { bool tl2::details::MyValueWriteJSON(std::ostream & s, const ::tl2::MyValue& item) { s << "{"; s << "\"type\":"; - s << MyValue_tbl_tl_tag[item.value.index()]; + s << "\"" << MyValue_tbl_tl_name[item.value.index()] << "\""; switch (item.value.index()) { case 0: s << ",\"value\":"; @@ -3815,11 +3899,15 @@ void tl2::details::NonOptNatReset(::tl2::NonOptNat& item) { bool tl2::details::NonOptNatWriteJSON(std::ostream& s, const ::tl2::NonOptNat& item) { s << "{"; - s << "\"n\":"; - s << item.n; - s << ","; - s << "\"xs\":"; - if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.xs, item.n)) { return false; } + if (item.n != 0) { + s << "\"n\":"; + s << item.n; + } + if ((item.xs.size() != 0) || (item.n != 0)) { + s << ","; + s << "\"xs\":"; + if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.xs, item.n)) { return false; } + } s << "}"; return true; } @@ -3854,8 +3942,10 @@ void tl2::details::RightIntVectorService6FindWithBoundsResultReset(::tl2::Right< bool tl2::details::RightIntVectorService6FindWithBoundsResultWriteJSON(std::ostream& s, const ::tl2::Right>& item) { s << "{"; - s << "\"value\":"; - if (!::tl2::details::BuiltinVectorService6FindWithBoundsResultWriteJSON(s, item.value)) { return false; } + if (item.value.size() != 0) { + s << "\"value\":"; + if (!::tl2::details::BuiltinVectorService6FindWithBoundsResultWriteJSON(s, item.value)) { return false; } + } s << "}"; return true; } @@ -3886,8 +3976,10 @@ void tl2::details::RightService6ErrorVectorService6FindResultRowReset(::tl2::Rig bool tl2::details::RightService6ErrorVectorService6FindResultRowWriteJSON(std::ostream& s, const ::tl2::Right<::tl2::service6::Error, std::vector<::tl2::service6::FindResultRow>>& item) { s << "{"; - s << "\"value\":"; - if (!::tl2::details::BuiltinVectorService6FindResultRowWriteJSON(s, item.value)) { return false; } + if (item.value.size() != 0) { + s << "\"value\":"; + if (!::tl2::details::BuiltinVectorService6FindResultRowWriteJSON(s, item.value)) { return false; } + } s << "}"; return true; } @@ -3948,8 +4040,10 @@ void tl2::details::RpcInvokeReqExtraReset(::tl2::RpcInvokeReqExtra& item) { bool tl2::details::RpcInvokeReqExtraWriteJSON(std::ostream& s, const ::tl2::RpcInvokeReqExtra& item) { s << "{"; - s << "\"fields_mask\":"; - s << item.fields_mask; + if (item.fields_mask != 0) { + s << "\"fields_mask\":"; + s << item.fields_mask; + } if ((item.fields_mask & (1<<0)) != 0) { s << ","; s << "\"query\":"; @@ -3966,14 +4060,18 @@ bool tl2::details::RpcInvokeReqExtraWriteJSON(std::ostream& s, const ::tl2::RpcI if (!::tl2::details::TrueWriteJSON(s, item.sort_reverse)) { return false; } } if ((item.fields_mask & (1<<16)) != 0) { - s << ","; - s << "\"wait_binlog_pos\":"; - s << item.wait_binlog_pos; + if (item.wait_binlog_pos != 0) { + s << ","; + s << "\"wait_binlog_pos\":"; + s << item.wait_binlog_pos; + } } if ((item.fields_mask & (1<<18)) != 0) { - s << ","; - s << "\"string_forward_keys\":"; - if (!::tl2::details::BuiltinVectorStringWriteJSON(s, item.string_forward_keys)) { return false; } + if (item.string_forward_keys.size() != 0) { + s << ","; + s << "\"string_forward_keys\":"; + if (!::tl2::details::BuiltinVectorStringWriteJSON(s, item.string_forward_keys)) { return false; } + } } s << "}"; return true; @@ -4071,11 +4169,15 @@ void tl2::details::StatOneReset(::tl2::StatOne& item) { bool tl2::details::StatOneWriteJSON(std::ostream& s, const ::tl2::StatOne& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; - s << ","; - s << "\"value\":"; - s << "\"" << item.value << "\""; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } + if (item.value.size() != 0) { + s << ","; + s << "\"value\":"; + s << "\"" << item.value << "\""; + } s << "}"; return true; } @@ -4825,14 +4927,20 @@ void tl2::details::WithFloatReset(::tl2::WithFloat& item) { bool tl2::details::WithFloatWriteJSON(std::ostream& s, const ::tl2::WithFloat& item) { s << "{"; - s << "\"x\":"; - s << item.x; - s << ","; - s << "\"y\":"; - s << item.y; - s << ","; - s << "\"z\":"; - s << item.z; + if (item.x != 0) { + s << "\"x\":"; + s << item.x; + } + if (item.y != 0) { + s << ","; + s << "\"y\":"; + s << item.y; + } + if (item.z != 0) { + s << ","; + s << "\"z\":"; + s << item.z; + } s << "}"; return true; } diff --git a/internal/tlcodegen/test/gen/schema_cpp/antispam/details.cpp b/internal/tlcodegen/test/gen/schema_cpp/antispam/details.cpp index 63383b8d..abb6555b 100644 --- a/internal/tlcodegen/test/gen/schema_cpp/antispam/details.cpp +++ b/internal/tlcodegen/test/gen/schema_cpp/antispam/details.cpp @@ -35,8 +35,10 @@ void tl2::details::AntispamGetPatternReset(::tl2::antispam::GetPattern& item) { bool tl2::details::AntispamGetPatternWriteJSON(std::ostream& s, const ::tl2::antispam::GetPattern& item) { s << "{"; - s << "\"id\":"; - s << item.id; + if (item.id != 0) { + s << "\"id\":"; + s << item.id; + } s << "}"; return true; } @@ -112,20 +114,30 @@ void tl2::details::AntispamPatternFoundReset(::tl2::antispam::PatternFound& item bool tl2::details::AntispamPatternFoundWriteJSON(std::ostream& s, const ::tl2::antispam::PatternFound& item) { s << "{"; - s << "\"ip\":"; - s << item.ip; - s << ","; - s << "\"uahash\":"; - s << item.uahash; - s << ","; - s << "\"flags\":"; - s << item.flags; - s << ","; - s << "\"type\":"; - s << item.type; - s << ","; - s << "\"text\":"; - s << "\"" << item.text << "\""; + if (item.ip != 0) { + s << "\"ip\":"; + s << item.ip; + } + if (item.uahash != 0) { + s << ","; + s << "\"uahash\":"; + s << item.uahash; + } + if (item.flags != 0) { + s << ","; + s << "\"flags\":"; + s << item.flags; + } + if (item.type != 0) { + s << ","; + s << "\"type\":"; + s << item.type; + } + if (item.text.size() != 0) { + s << ","; + s << "\"text\":"; + s << "\"" << item.text << "\""; + } s << "}"; return true; } @@ -188,7 +200,7 @@ void tl2::details::AntispamPatternFullReset(::tl2::antispam::PatternFull& item) bool tl2::details::AntispamPatternFullWriteJSON(std::ostream & s, const ::tl2::antispam::PatternFull& item) { s << "{"; s << "\"type\":"; - s << AntispamPatternFull_tbl_tl_tag[item.value.index()]; + s << "\"" << AntispamPatternFull_tbl_tl_name[item.value.index()] << "\""; switch (item.value.index()) { case 0: s << ",\"value\":"; diff --git a/internal/tlcodegen/test/gen/schema_cpp/pkg2/details.cpp b/internal/tlcodegen/test/gen/schema_cpp/pkg2/details.cpp index 3c165bc0..124c1ac8 100644 --- a/internal/tlcodegen/test/gen/schema_cpp/pkg2/details.cpp +++ b/internal/tlcodegen/test/gen/schema_cpp/pkg2/details.cpp @@ -34,8 +34,10 @@ void tl2::details::Pkg2FooReset(::tl2::pkg2::Foo& item) { bool tl2::details::Pkg2FooWriteJSON(std::ostream& s, const ::tl2::pkg2::Foo& item) { s << "{"; - s << "\"x\":"; - s << item.x; + if (item.x != 0) { + s << "\"x\":"; + s << item.x; + } s << "}"; return true; } diff --git a/internal/tlcodegen/test/gen/schema_cpp/service1/details.cpp b/internal/tlcodegen/test/gen/schema_cpp/service1/details.cpp index 1cf7450a..094223ad 100644 --- a/internal/tlcodegen/test/gen/schema_cpp/service1/details.cpp +++ b/internal/tlcodegen/test/gen/schema_cpp/service1/details.cpp @@ -259,11 +259,15 @@ void tl2::details::DictionaryFieldDictionaryIntReset(::tl2::DictionaryField<::tl bool tl2::details::DictionaryFieldDictionaryIntWriteJSON(std::ostream& s, const ::tl2::DictionaryField<::tl2::Dictionary>& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; - s << ","; - s << "\"value\":"; - if (!::tl2::details::DictionaryIntWriteJSON(s, item.value)) { return false; } + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } + if (item.value.size() != 0) { + s << ","; + s << "\"value\":"; + if (!::tl2::details::DictionaryIntWriteJSON(s, item.value)) { return false; } + } s << "}"; return true; } @@ -297,8 +301,10 @@ void tl2::details::DictionaryFieldService1ValueReset(::tl2::DictionaryField<::tl bool tl2::details::DictionaryFieldService1ValueWriteJSON(std::ostream& s, const ::tl2::DictionaryField<::tl2::service1::Value>& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } s << ","; s << "\"value\":"; if (!::tl2::details::Service1ValueWriteJSON(s, item.value)) { return false; } @@ -335,11 +341,15 @@ void tl2::details::DictionaryFieldStringReset(::tl2::DictionaryField& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; - s << ","; - s << "\"value\":"; - s << "\"" << item.value << "\""; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } + if (item.value.size() != 0) { + s << ","; + s << "\"value\":"; + s << "\"" << item.value << "\""; + } s << "}"; return true; } @@ -458,17 +468,25 @@ void tl2::details::Service1AddReset(::tl2::service1::Add& item) { bool tl2::details::Service1AddWriteJSON(std::ostream& s, const ::tl2::service1::Add& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; - s << ","; - s << "\"flags\":"; - s << item.flags; - s << ","; - s << "\"delay\":"; - s << item.delay; - s << ","; - s << "\"value\":"; - s << "\"" << item.value << "\""; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } + if (item.flags != 0) { + s << ","; + s << "\"flags\":"; + s << item.flags; + } + if (item.delay != 0) { + s << ","; + s << "\"delay\":"; + s << item.delay; + } + if (item.value.size() != 0) { + s << ","; + s << "\"value\":"; + s << "\"" << item.value << "\""; + } s << "}"; return true; } @@ -549,17 +567,25 @@ void tl2::details::Service1AddOrGetReset(::tl2::service1::AddOrGet& item) { bool tl2::details::Service1AddOrGetWriteJSON(std::ostream& s, const ::tl2::service1::AddOrGet& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; - s << ","; - s << "\"flags\":"; - s << item.flags; - s << ","; - s << "\"delay\":"; - s << item.delay; - s << ","; - s << "\"value\":"; - s << "\"" << item.value << "\""; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } + if (item.flags != 0) { + s << ","; + s << "\"flags\":"; + s << item.flags; + } + if (item.delay != 0) { + s << ","; + s << "\"delay\":"; + s << item.delay; + } + if (item.value.size() != 0) { + s << ","; + s << "\"value\":"; + s << "\"" << item.value << "\""; + } s << "}"; return true; } @@ -640,17 +666,25 @@ void tl2::details::Service1AddOrIncrReset(::tl2::service1::AddOrIncr& item) { bool tl2::details::Service1AddOrIncrWriteJSON(std::ostream& s, const ::tl2::service1::AddOrIncr& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; - s << ","; - s << "\"flags\":"; - s << item.flags; - s << ","; - s << "\"delay\":"; - s << item.delay; - s << ","; - s << "\"value\":"; - s << item.value; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } + if (item.flags != 0) { + s << ","; + s << "\"flags\":"; + s << item.flags; + } + if (item.delay != 0) { + s << ","; + s << "\"delay\":"; + s << item.delay; + } + if (item.value != 0) { + s << ","; + s << "\"value\":"; + s << item.value; + } s << "}"; return true; } @@ -731,17 +765,25 @@ void tl2::details::Service1AppendReset(::tl2::service1::Append& item) { bool tl2::details::Service1AppendWriteJSON(std::ostream& s, const ::tl2::service1::Append& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; - s << ","; - s << "\"flags\":"; - s << item.flags; - s << ","; - s << "\"delay\":"; - s << item.delay; - s << ","; - s << "\"suffix\":"; - s << "\"" << item.suffix << "\""; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } + if (item.flags != 0) { + s << ","; + s << "\"flags\":"; + s << item.flags; + } + if (item.delay != 0) { + s << ","; + s << "\"delay\":"; + s << item.delay; + } + if (item.suffix.size() != 0) { + s << ","; + s << "\"suffix\":"; + s << "\"" << item.suffix << "\""; + } s << "}"; return true; } @@ -823,20 +865,30 @@ void tl2::details::Service1CasReset(::tl2::service1::Cas& item) { bool tl2::details::Service1CasWriteJSON(std::ostream& s, const ::tl2::service1::Cas& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; - s << ","; - s << "\"flags\":"; - s << item.flags; - s << ","; - s << "\"delay\":"; - s << item.delay; - s << ","; - s << "\"casToken\":"; - s << "\"" << item.casToken << "\""; - s << ","; - s << "\"newValue\":"; - s << "\"" << item.newValue << "\""; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } + if (item.flags != 0) { + s << ","; + s << "\"flags\":"; + s << item.flags; + } + if (item.delay != 0) { + s << ","; + s << "\"delay\":"; + s << item.delay; + } + if (item.casToken.size() != 0) { + s << ","; + s << "\"casToken\":"; + s << "\"" << item.casToken << "\""; + } + if (item.newValue.size() != 0) { + s << ","; + s << "\"newValue\":"; + s << "\"" << item.newValue << "\""; + } s << "}"; return true; } @@ -917,11 +969,15 @@ void tl2::details::Service1DecrReset(::tl2::service1::Decr& item) { bool tl2::details::Service1DecrWriteJSON(std::ostream& s, const ::tl2::service1::Decr& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; - s << ","; - s << "\"value\":"; - s << item.value; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } + if (item.value != 0) { + s << ","; + s << "\"value\":"; + s << item.value; + } s << "}"; return true; } @@ -995,8 +1051,10 @@ void tl2::details::Service1DeleteReset(::tl2::service1::Delete& item) { bool tl2::details::Service1DeleteWriteJSON(std::ostream& s, const ::tl2::service1::Delete& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } s << "}"; return true; } @@ -1068,8 +1126,10 @@ void tl2::details::Service1DisableExpirationReset(::tl2::service1::DisableExpira bool tl2::details::Service1DisableExpirationWriteJSON(std::ostream& s, const ::tl2::service1::DisableExpiration& item) { s << "{"; - s << "\"prefix\":"; - s << "\"" << item.prefix << "\""; + if (item.prefix.size() != 0) { + s << "\"prefix\":"; + s << "\"" << item.prefix << "\""; + } s << "}"; return true; } @@ -1141,8 +1201,10 @@ void tl2::details::Service1DisableKeysStatReset(::tl2::service1::DisableKeysStat bool tl2::details::Service1DisableKeysStatWriteJSON(std::ostream& s, const ::tl2::service1::DisableKeysStat& item) { s << "{"; - s << "\"period\":"; - s << item.period; + if (item.period != 0) { + s << "\"period\":"; + s << item.period; + } s << "}"; return true; } @@ -1214,8 +1276,10 @@ void tl2::details::Service1EnableExpirationReset(::tl2::service1::EnableExpirati bool tl2::details::Service1EnableExpirationWriteJSON(std::ostream& s, const ::tl2::service1::EnableExpiration& item) { s << "{"; - s << "\"prefix\":"; - s << "\"" << item.prefix << "\""; + if (item.prefix.size() != 0) { + s << "\"prefix\":"; + s << "\"" << item.prefix << "\""; + } s << "}"; return true; } @@ -1287,8 +1351,10 @@ void tl2::details::Service1EnableKeysStatReset(::tl2::service1::EnableKeysStat& bool tl2::details::Service1EnableKeysStatWriteJSON(std::ostream& s, const ::tl2::service1::EnableKeysStat& item) { s << "{"; - s << "\"period\":"; - s << item.period; + if (item.period != 0) { + s << "\"period\":"; + s << item.period; + } s << "}"; return true; } @@ -1360,8 +1426,10 @@ void tl2::details::Service1ExistsReset(::tl2::service1::Exists& item) { bool tl2::details::Service1ExistsWriteJSON(std::ostream& s, const ::tl2::service1::Exists& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } s << "}"; return true; } @@ -1433,8 +1501,10 @@ void tl2::details::Service1GetReset(::tl2::service1::Get& item) { bool tl2::details::Service1GetWriteJSON(std::ostream& s, const ::tl2::service1::Get& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } s << "}"; return true; } @@ -1506,8 +1576,10 @@ void tl2::details::Service1GetExpireTimeReset(::tl2::service1::GetExpireTime& it bool tl2::details::Service1GetExpireTimeWriteJSON(std::ostream& s, const ::tl2::service1::GetExpireTime& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } s << "}"; return true; } @@ -1579,8 +1651,10 @@ void tl2::details::Service1GetKeysStatReset(::tl2::service1::GetKeysStat& item) bool tl2::details::Service1GetKeysStatWriteJSON(std::ostream& s, const ::tl2::service1::GetKeysStat& item) { s << "{"; - s << "\"period\":"; - s << item.period; + if (item.period != 0) { + s << "\"period\":"; + s << item.period; + } s << "}"; return true; } @@ -1722,8 +1796,10 @@ void tl2::details::Service1GetWildcardReset(::tl2::service1::GetWildcard& item) bool tl2::details::Service1GetWildcardWriteJSON(std::ostream& s, const ::tl2::service1::GetWildcard& item) { s << "{"; - s << "\"prefix\":"; - s << "\"" << item.prefix << "\""; + if (item.prefix.size() != 0) { + s << "\"prefix\":"; + s << "\"" << item.prefix << "\""; + } s << "}"; return true; } @@ -1797,8 +1873,10 @@ void tl2::details::Service1GetWildcardDictReset(::tl2::service1::GetWildcardDict bool tl2::details::Service1GetWildcardDictWriteJSON(std::ostream& s, const ::tl2::service1::GetWildcardDict& item) { s << "{"; - s << "\"prefix\":"; - s << "\"" << item.prefix << "\""; + if (item.prefix.size() != 0) { + s << "\"prefix\":"; + s << "\"" << item.prefix << "\""; + } s << "}"; return true; } @@ -1870,8 +1948,10 @@ void tl2::details::Service1GetWildcardListReset(::tl2::service1::GetWildcardList bool tl2::details::Service1GetWildcardListWriteJSON(std::ostream& s, const ::tl2::service1::GetWildcardList& item) { s << "{"; - s << "\"prefix\":"; - s << "\"" << item.prefix << "\""; + if (item.prefix.size() != 0) { + s << "\"prefix\":"; + s << "\"" << item.prefix << "\""; + } s << "}"; return true; } @@ -1945,8 +2025,10 @@ void tl2::details::Service1GetWildcardWithFlagsReset(::tl2::service1::GetWildcar bool tl2::details::Service1GetWildcardWithFlagsWriteJSON(std::ostream& s, const ::tl2::service1::GetWildcardWithFlags& item) { s << "{"; - s << "\"prefix\":"; - s << "\"" << item.prefix << "\""; + if (item.prefix.size() != 0) { + s << "\"prefix\":"; + s << "\"" << item.prefix << "\""; + } s << "}"; return true; } @@ -2019,11 +2101,15 @@ void tl2::details::Service1IncrReset(::tl2::service1::Incr& item) { bool tl2::details::Service1IncrWriteJSON(std::ostream& s, const ::tl2::service1::Incr& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; - s << ","; - s << "\"value\":"; - s << item.value; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } + if (item.value != 0) { + s << ","; + s << "\"value\":"; + s << item.value; + } s << "}"; return true; } @@ -2098,11 +2184,15 @@ void tl2::details::Service1KeysStatReset(::tl2::service1::KeysStat& item) { bool tl2::details::Service1KeysStatWriteJSON(std::ostream& s, const ::tl2::service1::KeysStat& item) { s << "{"; - s << "\"start_time\":"; - s << item.start_time; - s << ","; - s << "\"keys_tops\":"; - if (!::tl2::details::DictionaryDictionaryIntWriteJSON(s, item.keys_tops)) { return false; } + if (item.start_time != 0) { + s << "\"start_time\":"; + s << item.start_time; + } + if (item.keys_tops.size() != 0) { + s << ","; + s << "\"keys_tops\":"; + if (!::tl2::details::DictionaryDictionaryIntWriteJSON(s, item.keys_tops)) { return false; } + } s << "}"; return true; } @@ -2193,11 +2283,15 @@ void tl2::details::Service1LongvalueReset(::tl2::service1::Longvalue& item) { bool tl2::details::Service1LongvalueWriteJSON(std::ostream& s, const ::tl2::service1::Longvalue& item) { s << "{"; - s << "\"value\":"; - s << item.value; - s << ","; - s << "\"flags\":"; - s << item.flags; + if (item.value != 0) { + s << "\"value\":"; + s << item.value; + } + if (item.flags != 0) { + s << ","; + s << "\"flags\":"; + s << item.flags; + } s << "}"; return true; } @@ -2257,14 +2351,20 @@ void tl2::details::Service1LongvalueWithTimeReset(::tl2::service1::LongvalueWith bool tl2::details::Service1LongvalueWithTimeWriteJSON(std::ostream& s, const ::tl2::service1::LongvalueWithTime& item) { s << "{"; - s << "\"value\":"; - s << item.value; - s << ","; - s << "\"flags\":"; - s << item.flags; - s << ","; - s << "\"modificationTime\":"; - s << item.modificationTime; + if (item.value != 0) { + s << "\"value\":"; + s << item.value; + } + if (item.flags != 0) { + s << ","; + s << "\"flags\":"; + s << item.flags; + } + if (item.modificationTime != 0) { + s << ","; + s << "\"modificationTime\":"; + s << item.modificationTime; + } s << "}"; return true; } @@ -2379,17 +2479,25 @@ void tl2::details::Service1ReplaceReset(::tl2::service1::Replace& item) { bool tl2::details::Service1ReplaceWriteJSON(std::ostream& s, const ::tl2::service1::Replace& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; - s << ","; - s << "\"flags\":"; - s << item.flags; - s << ","; - s << "\"delay\":"; - s << item.delay; - s << ","; - s << "\"value\":"; - s << "\"" << item.value << "\""; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } + if (item.flags != 0) { + s << ","; + s << "\"flags\":"; + s << item.flags; + } + if (item.delay != 0) { + s << ","; + s << "\"delay\":"; + s << item.delay; + } + if (item.value.size() != 0) { + s << ","; + s << "\"value\":"; + s << "\"" << item.value << "\""; + } s << "}"; return true; } @@ -2470,17 +2578,25 @@ void tl2::details::Service1ReplaceOrIncrReset(::tl2::service1::ReplaceOrIncr& it bool tl2::details::Service1ReplaceOrIncrWriteJSON(std::ostream& s, const ::tl2::service1::ReplaceOrIncr& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; - s << ","; - s << "\"flags\":"; - s << item.flags; - s << ","; - s << "\"delay\":"; - s << item.delay; - s << ","; - s << "\"value\":"; - s << item.value; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } + if (item.flags != 0) { + s << ","; + s << "\"flags\":"; + s << item.flags; + } + if (item.delay != 0) { + s << ","; + s << "\"delay\":"; + s << item.delay; + } + if (item.value != 0) { + s << ","; + s << "\"value\":"; + s << item.value; + } s << "}"; return true; } @@ -2561,17 +2677,25 @@ void tl2::details::Service1SetReset(::tl2::service1::Set& item) { bool tl2::details::Service1SetWriteJSON(std::ostream& s, const ::tl2::service1::Set& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; - s << ","; - s << "\"flags\":"; - s << item.flags; - s << ","; - s << "\"delay\":"; - s << item.delay; - s << ","; - s << "\"value\":"; - s << "\"" << item.value << "\""; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } + if (item.flags != 0) { + s << ","; + s << "\"flags\":"; + s << item.flags; + } + if (item.delay != 0) { + s << ","; + s << "\"delay\":"; + s << item.delay; + } + if (item.value.size() != 0) { + s << ","; + s << "\"value\":"; + s << "\"" << item.value << "\""; + } s << "}"; return true; } @@ -2652,17 +2776,25 @@ void tl2::details::Service1SetOrIncrReset(::tl2::service1::SetOrIncr& item) { bool tl2::details::Service1SetOrIncrWriteJSON(std::ostream& s, const ::tl2::service1::SetOrIncr& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; - s << ","; - s << "\"flags\":"; - s << item.flags; - s << ","; - s << "\"delay\":"; - s << item.delay; - s << ","; - s << "\"value\":"; - s << item.value; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } + if (item.flags != 0) { + s << ","; + s << "\"flags\":"; + s << item.flags; + } + if (item.delay != 0) { + s << ","; + s << "\"delay\":"; + s << item.delay; + } + if (item.value != 0) { + s << ","; + s << "\"value\":"; + s << item.value; + } s << "}"; return true; } @@ -2741,11 +2873,15 @@ void tl2::details::Service1StrvalueReset(::tl2::service1::Strvalue& item) { bool tl2::details::Service1StrvalueWriteJSON(std::ostream& s, const ::tl2::service1::Strvalue& item) { s << "{"; - s << "\"value\":"; - s << "\"" << item.value << "\""; - s << ","; - s << "\"flags\":"; - s << item.flags; + if (item.value.size() != 0) { + s << "\"value\":"; + s << "\"" << item.value << "\""; + } + if (item.flags != 0) { + s << ","; + s << "\"flags\":"; + s << item.flags; + } s << "}"; return true; } @@ -2805,14 +2941,20 @@ void tl2::details::Service1StrvalueWithTimeReset(::tl2::service1::StrvalueWithTi bool tl2::details::Service1StrvalueWithTimeWriteJSON(std::ostream& s, const ::tl2::service1::StrvalueWithTime& item) { s << "{"; - s << "\"value\":"; - s << "\"" << item.value << "\""; - s << ","; - s << "\"flags\":"; - s << item.flags; - s << ","; - s << "\"modificationTime\":"; - s << item.modificationTime; + if (item.value.size() != 0) { + s << "\"value\":"; + s << "\"" << item.value << "\""; + } + if (item.flags != 0) { + s << ","; + s << "\"flags\":"; + s << item.flags; + } + if (item.modificationTime != 0) { + s << ","; + s << "\"modificationTime\":"; + s << item.modificationTime; + } s << "}"; return true; } @@ -2873,11 +3015,15 @@ void tl2::details::Service1TouchReset(::tl2::service1::Touch& item) { bool tl2::details::Service1TouchWriteJSON(std::ostream& s, const ::tl2::service1::Touch& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; - s << ","; - s << "\"delay\":"; - s << item.delay; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } + if (item.delay != 0) { + s << ","; + s << "\"delay\":"; + s << item.delay; + } s << "}"; return true; } @@ -2950,7 +3096,7 @@ void tl2::details::Service1ValueReset(::tl2::service1::Value& item) { bool tl2::details::Service1ValueWriteJSON(std::ostream & s, const ::tl2::service1::Value& item) { s << "{"; s << "\"type\":"; - s << Service1Value_tbl_tl_tag[item.value.index()]; + s << "\"" << Service1Value_tbl_tl_name[item.value.index()] << "\""; switch (item.value.index()) { case 1: s << ",\"value\":"; diff --git a/internal/tlcodegen/test/gen/schema_cpp/service2/details.cpp b/internal/tlcodegen/test/gen/schema_cpp/service2/details.cpp index f0100b8d..0ae396c2 100644 --- a/internal/tlcodegen/test/gen/schema_cpp/service2/details.cpp +++ b/internal/tlcodegen/test/gen/schema_cpp/service2/details.cpp @@ -167,26 +167,40 @@ void tl2::details::Service2AddOrIncrManyReset(::tl2::service2::AddOrIncrMany& it bool tl2::details::Service2AddOrIncrManyWriteJSON(std::ostream& s, const ::tl2::service2::AddOrIncrMany& item) { s << "{"; - s << "\"objectIdLength\":"; - s << item.objectIdLength; - s << ","; - s << "\"intCountersNum\":"; - s << item.intCountersNum; - s << ","; - s << "\"floatCountersNum\":"; - s << item.floatCountersNum; - s << ","; - s << "\"objectsNum\":"; - s << item.objectsNum; - s << ","; - s << "\"intCounters\":"; - if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.intCounters, item.intCountersNum)) { return false; } - s << ","; - s << "\"floatCounters\":"; - if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.floatCounters, item.floatCountersNum)) { return false; } - s << ","; - s << "\"deltas\":"; - if (!::tl2::details::BuiltinTupleService2DeltaSetWriteJSON(s, item.deltas, item.objectsNum, item.objectIdLength, item.intCountersNum, item.floatCountersNum)) { return false; } + if (item.objectIdLength != 0) { + s << "\"objectIdLength\":"; + s << item.objectIdLength; + } + if (item.intCountersNum != 0) { + s << ","; + s << "\"intCountersNum\":"; + s << item.intCountersNum; + } + if (item.floatCountersNum != 0) { + s << ","; + s << "\"floatCountersNum\":"; + s << item.floatCountersNum; + } + if (item.objectsNum != 0) { + s << ","; + s << "\"objectsNum\":"; + s << item.objectsNum; + } + if ((item.intCounters.size() != 0) || (item.intCountersNum != 0)) { + s << ","; + s << "\"intCounters\":"; + if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.intCounters, item.intCountersNum)) { return false; } + } + if ((item.floatCounters.size() != 0) || (item.floatCountersNum != 0)) { + s << ","; + s << "\"floatCounters\":"; + if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.floatCounters, item.floatCountersNum)) { return false; } + } + if ((item.deltas.size() != 0) || (item.objectIdLength != 0)) { + s << ","; + s << "\"deltas\":"; + if (!::tl2::details::BuiltinTupleService2DeltaSetWriteJSON(s, item.deltas, item.objectsNum, item.objectIdLength, item.intCountersNum, item.floatCountersNum)) { return false; } + } s << "}"; return true; } @@ -273,11 +287,15 @@ void tl2::details::Service2CounterSetReset(::tl2::service2::CounterSet& item) { bool tl2::details::Service2CounterSetWriteJSON(std::ostream& s, const ::tl2::service2::CounterSet& item, uint32_t nat_intCountersNum, uint32_t nat_floatCountersNum) { s << "{"; - s << "\"intCounters\":"; - if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.intCounters, nat_intCountersNum)) { return false; } - s << ","; - s << "\"floatCounters\":"; - if (!::tl2::details::BuiltinTupleDoubleWriteJSON(s, item.floatCounters, nat_floatCountersNum)) { return false; } + if ((item.intCounters.size() != 0) || (nat_intCountersNum != 0)) { + s << "\"intCounters\":"; + if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.intCounters, nat_intCountersNum)) { return false; } + } + if ((item.floatCounters.size() != 0) || (nat_floatCountersNum != 0)) { + s << ","; + s << "\"floatCounters\":"; + if (!::tl2::details::BuiltinTupleDoubleWriteJSON(s, item.floatCounters, nat_floatCountersNum)) { return false; } + } s << "}"; return true; } @@ -398,8 +416,10 @@ void tl2::details::Service2ObjectIdReset(::tl2::service2::ObjectId& item) { bool tl2::details::Service2ObjectIdWriteJSON(std::ostream& s, const ::tl2::service2::ObjectId& item, uint32_t nat_objectIdLength) { s << "{"; - s << "\"id\":"; - if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.id, nat_objectIdLength)) { return false; } + if ((item.id.size() != 0) || (nat_objectIdLength != 0)) { + s << "\"id\":"; + if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.id, nat_objectIdLength)) { return false; } + } s << "}"; return true; } @@ -460,20 +480,30 @@ void tl2::details::Service2SetReset(::tl2::service2::Set& item) { bool tl2::details::Service2SetWriteJSON(std::ostream& s, const ::tl2::service2::Set& item) { s << "{"; - s << "\"objectIdLength\":"; - s << item.objectIdLength; - s << ","; - s << "\"intCountersNum\":"; - s << item.intCountersNum; - s << ","; - s << "\"floatCountersNum\":"; - s << item.floatCountersNum; - s << ","; - s << "\"intCounters\":"; - if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.intCounters, item.intCountersNum)) { return false; } - s << ","; - s << "\"floatCounters\":"; - if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.floatCounters, item.floatCountersNum)) { return false; } + if (item.objectIdLength != 0) { + s << "\"objectIdLength\":"; + s << item.objectIdLength; + } + if (item.intCountersNum != 0) { + s << ","; + s << "\"intCountersNum\":"; + s << item.intCountersNum; + } + if (item.floatCountersNum != 0) { + s << ","; + s << "\"floatCountersNum\":"; + s << item.floatCountersNum; + } + if ((item.intCounters.size() != 0) || (item.intCountersNum != 0)) { + s << ","; + s << "\"intCounters\":"; + if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.intCounters, item.intCountersNum)) { return false; } + } + if ((item.floatCounters.size() != 0) || (item.floatCountersNum != 0)) { + s << ","; + s << "\"floatCounters\":"; + if (!::tl2::details::BuiltinTupleIntWriteJSON(s, item.floatCounters, item.floatCountersNum)) { return false; } + } s << ","; s << "\"newValues\":"; if (!::tl2::details::Service2DeltaSetWriteJSON(s, item.newValues, item.objectIdLength, item.intCountersNum, item.floatCountersNum)) { return false; } @@ -560,14 +590,18 @@ void tl2::details::Service2SetObjectTtlReset(::tl2::service2::SetObjectTtl& item bool tl2::details::Service2SetObjectTtlWriteJSON(std::ostream& s, const ::tl2::service2::SetObjectTtl& item) { s << "{"; - s << "\"objectIdLength\":"; - s << item.objectIdLength; + if (item.objectIdLength != 0) { + s << "\"objectIdLength\":"; + s << item.objectIdLength; + } s << ","; s << "\"objectId\":"; if (!::tl2::details::Service2ObjectIdWriteJSON(s, item.objectId, item.objectIdLength)) { return false; } - s << ","; - s << "\"ttl\":"; - s << item.ttl; + if (item.ttl != 0) { + s << ","; + s << "\"ttl\":"; + s << item.ttl; + } s << "}"; return true; } diff --git a/internal/tlcodegen/test/gen/schema_cpp/service3/details.cpp b/internal/tlcodegen/test/gen/schema_cpp/service3/details.cpp index 4c114107..eaf3fbe7 100644 --- a/internal/tlcodegen/test/gen/schema_cpp/service3/details.cpp +++ b/internal/tlcodegen/test/gen/schema_cpp/service3/details.cpp @@ -56,14 +56,20 @@ void tl2::details::BoolStatReset(::tl2::BoolStat& item) { bool tl2::details::BoolStatWriteJSON(std::ostream& s, const ::tl2::BoolStat& item) { s << "{"; - s << "\"statTrue\":"; - s << item.statTrue; - s << ","; - s << "\"statFalse\":"; - s << item.statFalse; - s << ","; - s << "\"statUnknown\":"; - s << item.statUnknown; + if (item.statTrue != 0) { + s << "\"statTrue\":"; + s << item.statTrue; + } + if (item.statFalse != 0) { + s << ","; + s << "\"statFalse\":"; + s << item.statFalse; + } + if (item.statUnknown != 0) { + s << ","; + s << "\"statUnknown\":"; + s << item.statUnknown; + } s << "}"; return true; } @@ -313,23 +319,35 @@ void tl2::details::Service3CreateProductReset(::tl2::service3::CreateProduct& it bool tl2::details::Service3CreateProductWriteJSON(std::ostream& s, const ::tl2::service3::CreateProduct& item) { s << "{"; - s << "\"user_id\":"; - s << item.user_id; - s << ","; - s << "\"type\":"; - s << item.type; - s << ","; - s << "\"id\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.id)) { return false; } - s << ","; - s << "\"info\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.info)) { return false; } - s << ","; - s << "\"date\":"; - s << item.date; - s << ","; - s << "\"expiration_date\":"; - s << item.expiration_date; + if (item.user_id != 0) { + s << "\"user_id\":"; + s << item.user_id; + } + if (item.type != 0) { + s << ","; + s << "\"type\":"; + s << item.type; + } + if (item.id.size() != 0) { + s << ","; + s << "\"id\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.id)) { return false; } + } + if (item.info.size() != 0) { + s << ","; + s << "\"info\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.info)) { return false; } + } + if (item.date != 0) { + s << ","; + s << "\"date\":"; + s << item.date; + } + if (item.expiration_date != 0) { + s << ","; + s << "\"expiration_date\":"; + s << item.expiration_date; + } s << "}"; return true; } @@ -414,17 +432,25 @@ void tl2::details::Service3DeleteAllProductsReset(::tl2::service3::DeleteAllProd bool tl2::details::Service3DeleteAllProductsWriteJSON(std::ostream& s, const ::tl2::service3::DeleteAllProducts& item) { s << "{"; - s << "\"user_id\":"; - s << item.user_id; - s << ","; - s << "\"type\":"; - s << item.type; - s << ","; - s << "\"start_date\":"; - s << item.start_date; - s << ","; - s << "\"end_date\":"; - s << item.end_date; + if (item.user_id != 0) { + s << "\"user_id\":"; + s << item.user_id; + } + if (item.type != 0) { + s << ","; + s << "\"type\":"; + s << item.type; + } + if (item.start_date != 0) { + s << ","; + s << "\"start_date\":"; + s << item.start_date; + } + if (item.end_date != 0) { + s << ","; + s << "\"end_date\":"; + s << item.end_date; + } s << "}"; return true; } @@ -506,20 +532,30 @@ void tl2::details::Service3DeleteGroupedProductsReset(::tl2::service3::DeleteGro bool tl2::details::Service3DeleteGroupedProductsWriteJSON(std::ostream& s, const ::tl2::service3::DeleteGroupedProducts& item) { s << "{"; - s << "\"user_id\":"; - s << item.user_id; - s << ","; - s << "\"type\":"; - s << item.type; - s << ","; - s << "\"id\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.id)) { return false; } - s << ","; - s << "\"start_date\":"; - s << item.start_date; - s << ","; - s << "\"end_date\":"; - s << item.end_date; + if (item.user_id != 0) { + s << "\"user_id\":"; + s << item.user_id; + } + if (item.type != 0) { + s << ","; + s << "\"type\":"; + s << item.type; + } + if (item.id.size() != 0) { + s << ","; + s << "\"id\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.id)) { return false; } + } + if (item.start_date != 0) { + s << ","; + s << "\"start_date\":"; + s << item.start_date; + } + if (item.end_date != 0) { + s << ","; + s << "\"end_date\":"; + s << item.end_date; + } s << "}"; return true; } @@ -602,17 +638,25 @@ void tl2::details::Service3DeleteProductReset(::tl2::service3::DeleteProduct& it bool tl2::details::Service3DeleteProductWriteJSON(std::ostream& s, const ::tl2::service3::DeleteProduct& item) { s << "{"; - s << "\"user_id\":"; - s << item.user_id; - s << ","; - s << "\"type\":"; - s << item.type; - s << ","; - s << "\"id\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.id)) { return false; } - s << ","; - s << "\"info\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.info)) { return false; } + if (item.user_id != 0) { + s << "\"user_id\":"; + s << item.user_id; + } + if (item.type != 0) { + s << ","; + s << "\"type\":"; + s << item.type; + } + if (item.id.size() != 0) { + s << ","; + s << "\"id\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.id)) { return false; } + } + if (item.info.size() != 0) { + s << ","; + s << "\"info\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.info)) { return false; } + } s << "}"; return true; } @@ -690,8 +734,10 @@ void tl2::details::Service3GetLastVisitTimestampReset(::tl2::service3::GetLastVi bool tl2::details::Service3GetLastVisitTimestampWriteJSON(std::ostream& s, const ::tl2::service3::GetLastVisitTimestamp& item) { s << "{"; - s << "\"user_id\":"; - s << item.user_id; + if (item.user_id != 0) { + s << "\"user_id\":"; + s << item.user_id; + } s << "}"; return true; } @@ -832,11 +878,15 @@ void tl2::details::Service3GetProductStatsReset(::tl2::service3::GetProductStats bool tl2::details::Service3GetProductStatsWriteJSON(std::ostream& s, const ::tl2::service3::GetProductStats& item) { s << "{"; - s << "\"user_id\":"; - s << item.user_id; - s << ","; - s << "\"types\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.types)) { return false; } + if (item.user_id != 0) { + s << "\"user_id\":"; + s << item.user_id; + } + if (item.types.size() != 0) { + s << ","; + s << "\"types\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.types)) { return false; } + } s << "}"; return true; } @@ -917,29 +967,45 @@ void tl2::details::Service3GetProductsReset(::tl2::service3::GetProducts& item) bool tl2::details::Service3GetProductsWriteJSON(std::ostream& s, const ::tl2::service3::GetProducts& item) { s << "{"; - s << "\"user_id\":"; - s << item.user_id; - s << ","; - s << "\"mode\":"; - s << item.mode; - s << ","; - s << "\"types\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.types)) { return false; } - s << ","; - s << "\"start_date\":"; - s << item.start_date; - s << ","; - s << "\"end_date\":"; - s << item.end_date; - s << ","; - s << "\"offset\":"; - s << item.offset; - s << ","; - s << "\"limit\":"; - s << item.limit; - s << ","; - s << "\"allowed_info0\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.allowed_info0)) { return false; } + if (item.user_id != 0) { + s << "\"user_id\":"; + s << item.user_id; + } + if (item.mode != 0) { + s << ","; + s << "\"mode\":"; + s << item.mode; + } + if (item.types.size() != 0) { + s << ","; + s << "\"types\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.types)) { return false; } + } + if (item.start_date != 0) { + s << ","; + s << "\"start_date\":"; + s << item.start_date; + } + if (item.end_date != 0) { + s << ","; + s << "\"end_date\":"; + s << item.end_date; + } + if (item.offset != 0) { + s << ","; + s << "\"offset\":"; + s << item.offset; + } + if (item.limit != 0) { + s << ","; + s << "\"limit\":"; + s << item.limit; + } + if (item.allowed_info0.size() != 0) { + s << ","; + s << "\"allowed_info0\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.allowed_info0)) { return false; } + } s << "}"; return true; } @@ -1026,11 +1092,15 @@ void tl2::details::Service3GetScheduledProductsReset(::tl2::service3::GetSchedul bool tl2::details::Service3GetScheduledProductsWriteJSON(std::ostream& s, const ::tl2::service3::GetScheduledProducts& item) { s << "{"; - s << "\"user_id\":"; - s << item.user_id; - s << ","; - s << "\"types\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.types)) { return false; } + if (item.user_id != 0) { + s << "\"user_id\":"; + s << item.user_id; + } + if (item.types.size() != 0) { + s << ","; + s << "\"types\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.types)) { return false; } + } s << "}"; return true; } @@ -1105,11 +1175,15 @@ void tl2::details::Service3GroupCountLimitReset(::tl2::service3::GroupCountLimit bool tl2::details::Service3GroupCountLimitWriteJSON(std::ostream& s, const ::tl2::service3::GroupCountLimit& item) { s << "{"; - s << "\"types\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.types)) { return false; } - s << ","; - s << "\"limit\":"; - s << item.limit; + if (item.types.size() != 0) { + s << "\"types\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.types)) { return false; } + } + if (item.limit != 0) { + s << ","; + s << "\"limit\":"; + s << item.limit; + } s << "}"; return true; } @@ -1168,11 +1242,15 @@ void tl2::details::Service3GroupSizeLimitReset(::tl2::service3::GroupSizeLimit& bool tl2::details::Service3GroupSizeLimitWriteJSON(std::ostream& s, const ::tl2::service3::GroupSizeLimit& item) { s << "{"; - s << "\"type\":"; - s << item.type; - s << ","; - s << "\"limit\":"; - s << item.limit; + if (item.type != 0) { + s << "\"type\":"; + s << item.type; + } + if (item.limit != 0) { + s << ","; + s << "\"limit\":"; + s << item.limit; + } s << "}"; return true; } @@ -1233,17 +1311,25 @@ void tl2::details::Service3LimitsReset(::tl2::service3::Limits& item) { bool tl2::details::Service3LimitsWriteJSON(std::ostream& s, const ::tl2::service3::Limits& item) { s << "{"; - s << "\"default_group_size_limit\":"; - s << item.default_group_size_limit; - s << ","; - s << "\"custom_group_size_limits\":"; - if (!::tl2::details::BuiltinVectorService3GroupSizeLimitWriteJSON(s, item.custom_group_size_limits)) { return false; } - s << ","; - s << "\"default_group_count_limit\":"; - s << item.default_group_count_limit; - s << ","; - s << "\"custom_group_count_limits\":"; - if (!::tl2::details::BuiltinVectorService3GroupCountLimitWriteJSON(s, item.custom_group_count_limits)) { return false; } + if (item.default_group_size_limit != 0) { + s << "\"default_group_size_limit\":"; + s << item.default_group_size_limit; + } + if (item.custom_group_size_limits.size() != 0) { + s << ","; + s << "\"custom_group_size_limits\":"; + if (!::tl2::details::BuiltinVectorService3GroupSizeLimitWriteJSON(s, item.custom_group_size_limits)) { return false; } + } + if (item.default_group_count_limit != 0) { + s << ","; + s << "\"default_group_count_limit\":"; + s << item.default_group_count_limit; + } + if (item.custom_group_count_limits.size() != 0) { + s << ","; + s << "\"custom_group_count_limits\":"; + if (!::tl2::details::BuiltinVectorService3GroupCountLimitWriteJSON(s, item.custom_group_count_limits)) { return false; } + } s << "}"; return true; } @@ -1310,24 +1396,36 @@ void tl2::details::Service3ProductReset(::tl2::service3::Product& item) { bool tl2::details::Service3ProductWriteJSON(std::ostream& s, const ::tl2::service3::Product& item, uint32_t nat_mode) { s << "{"; - s << "\"type\":"; - s << item.type; - s << ","; - s << "\"id\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.id)) { return false; } - s << ","; - s << "\"info\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.info)) { return false; } - s << ","; - s << "\"date\":"; - s << item.date; - s << ","; - s << "\"expiration_date\":"; - s << item.expiration_date; - if ((nat_mode & (1<<0)) != 0) { + if (item.type != 0) { + s << "\"type\":"; + s << item.type; + } + if (item.id.size() != 0) { s << ","; - s << "\"removed\":"; - if (!::tl2::details::BoolWriteJSON(s, item.removed)) { return false; } + s << "\"id\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.id)) { return false; } + } + if (item.info.size() != 0) { + s << ","; + s << "\"info\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.info)) { return false; } + } + if (item.date != 0) { + s << ","; + s << "\"date\":"; + s << item.date; + } + if (item.expiration_date != 0) { + s << ","; + s << "\"expiration_date\":"; + s << item.expiration_date; + } + if ((nat_mode & (1<<0)) != 0) { + if (item.removed) { + s << ","; + s << "\"removed\":"; + if (!::tl2::details::BoolWriteJSON(s, item.removed)) { return false; } + } } s << "}"; return true; @@ -1380,24 +1478,36 @@ void tl2::details::Service3Product0Reset(::tl2::service3::Productmode<0>& item) bool tl2::details::Service3Product0WriteJSON(std::ostream& s, const ::tl2::service3::Productmode<0>& item) { s << "{"; - s << "\"type\":"; - s << item.type; - s << ","; - s << "\"id\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.id)) { return false; } - s << ","; - s << "\"info\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.info)) { return false; } - s << ","; - s << "\"date\":"; - s << item.date; - s << ","; - s << "\"expiration_date\":"; - s << item.expiration_date; - if ((0 & (1<<0)) != 0) { + if (item.type != 0) { + s << "\"type\":"; + s << item.type; + } + if (item.id.size() != 0) { + s << ","; + s << "\"id\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.id)) { return false; } + } + if (item.info.size() != 0) { + s << ","; + s << "\"info\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.info)) { return false; } + } + if (item.date != 0) { s << ","; - s << "\"removed\":"; - if (!::tl2::details::BoolWriteJSON(s, item.removed)) { return false; } + s << "\"date\":"; + s << item.date; + } + if (item.expiration_date != 0) { + s << ","; + s << "\"expiration_date\":"; + s << item.expiration_date; + } + if ((0 & (1<<0)) != 0) { + if (item.removed) { + s << ","; + s << "\"removed\":"; + if (!::tl2::details::BoolWriteJSON(s, item.removed)) { return false; } + } } s << "}"; return true; @@ -1474,20 +1584,30 @@ void tl2::details::Service3ProductStatsOldReset(::tl2::service3::ProductStatsOld bool tl2::details::Service3ProductStatsOldWriteJSON(std::ostream& s, const ::tl2::service3::ProductStatsOld& item) { s << "{"; - s << "\"type\":"; - s << item.type; - s << ","; - s << "\"count_new\":"; - s << item.count_new; - s << ","; - s << "\"count_total\":"; - s << item.count_total; - s << ","; - s << "\"count_scheduled\":"; - s << item.count_scheduled; - s << ","; - s << "\"next_scheduled_at\":"; - s << item.next_scheduled_at; + if (item.type != 0) { + s << "\"type\":"; + s << item.type; + } + if (item.count_new != 0) { + s << ","; + s << "\"count_new\":"; + s << item.count_new; + } + if (item.count_total != 0) { + s << ","; + s << "\"count_total\":"; + s << item.count_total; + } + if (item.count_scheduled != 0) { + s << ","; + s << "\"count_scheduled\":"; + s << item.count_scheduled; + } + if (item.next_scheduled_at != 0) { + s << ","; + s << "\"next_scheduled_at\":"; + s << item.next_scheduled_at; + } s << "}"; return true; } @@ -1554,17 +1674,25 @@ void tl2::details::Service3RestoreAllProductsReset(::tl2::service3::RestoreAllPr bool tl2::details::Service3RestoreAllProductsWriteJSON(std::ostream& s, const ::tl2::service3::RestoreAllProducts& item) { s << "{"; - s << "\"user_id\":"; - s << item.user_id; - s << ","; - s << "\"type\":"; - s << item.type; - s << ","; - s << "\"start_date\":"; - s << item.start_date; - s << ","; - s << "\"end_date\":"; - s << item.end_date; + if (item.user_id != 0) { + s << "\"user_id\":"; + s << item.user_id; + } + if (item.type != 0) { + s << ","; + s << "\"type\":"; + s << item.type; + } + if (item.start_date != 0) { + s << ","; + s << "\"start_date\":"; + s << item.start_date; + } + if (item.end_date != 0) { + s << ","; + s << "\"end_date\":"; + s << item.end_date; + } s << "}"; return true; } @@ -1646,20 +1774,30 @@ void tl2::details::Service3RestoreGroupedProductsReset(::tl2::service3::RestoreG bool tl2::details::Service3RestoreGroupedProductsWriteJSON(std::ostream& s, const ::tl2::service3::RestoreGroupedProducts& item) { s << "{"; - s << "\"user_id\":"; - s << item.user_id; - s << ","; - s << "\"type\":"; - s << item.type; - s << ","; - s << "\"id\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.id)) { return false; } - s << ","; - s << "\"start_date\":"; - s << item.start_date; - s << ","; - s << "\"end_date\":"; - s << item.end_date; + if (item.user_id != 0) { + s << "\"user_id\":"; + s << item.user_id; + } + if (item.type != 0) { + s << ","; + s << "\"type\":"; + s << item.type; + } + if (item.id.size() != 0) { + s << ","; + s << "\"id\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.id)) { return false; } + } + if (item.start_date != 0) { + s << ","; + s << "\"start_date\":"; + s << item.start_date; + } + if (item.end_date != 0) { + s << ","; + s << "\"end_date\":"; + s << item.end_date; + } s << "}"; return true; } @@ -1742,17 +1880,25 @@ void tl2::details::Service3RestoreProductReset(::tl2::service3::RestoreProduct& bool tl2::details::Service3RestoreProductWriteJSON(std::ostream& s, const ::tl2::service3::RestoreProduct& item) { s << "{"; - s << "\"user_id\":"; - s << item.user_id; - s << ","; - s << "\"type\":"; - s << item.type; - s << ","; - s << "\"id\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.id)) { return false; } - s << ","; - s << "\"info\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.info)) { return false; } + if (item.user_id != 0) { + s << "\"user_id\":"; + s << item.user_id; + } + if (item.type != 0) { + s << ","; + s << "\"type\":"; + s << item.type; + } + if (item.id.size() != 0) { + s << ","; + s << "\"id\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.id)) { return false; } + } + if (item.info.size() != 0) { + s << ","; + s << "\"info\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.info)) { return false; } + } s << "}"; return true; } @@ -1831,11 +1977,15 @@ void tl2::details::Service3SetLastVisitTimestampReset(::tl2::service3::SetLastVi bool tl2::details::Service3SetLastVisitTimestampWriteJSON(std::ostream& s, const ::tl2::service3::SetLastVisitTimestamp& item) { s << "{"; - s << "\"user_id\":"; - s << item.user_id; - s << ","; - s << "\"timestamp\":"; - s << item.timestamp; + if (item.user_id != 0) { + s << "\"user_id\":"; + s << item.user_id; + } + if (item.timestamp != 0) { + s << ","; + s << "\"timestamp\":"; + s << item.timestamp; + } s << "}"; return true; } diff --git a/internal/tlcodegen/test/gen/schema_cpp/service4/details.cpp b/internal/tlcodegen/test/gen/schema_cpp/service4/details.cpp index a02d7713..8805c854 100644 --- a/internal/tlcodegen/test/gen/schema_cpp/service4/details.cpp +++ b/internal/tlcodegen/test/gen/schema_cpp/service4/details.cpp @@ -42,26 +42,36 @@ bool tl2::details::Service4ModifiedNewsEntryWriteJSON(std::ostream& s, const ::t s << "{"; s << "\"object\":"; if (!::tl2::details::Service4ObjectWriteJSON(s, item.object)) { return false; } - s << ","; - s << "\"creation_date\":"; - s << item.creation_date; - s << ","; - s << "\"fields_mask\":"; - s << item.fields_mask; - if ((item.fields_mask & (1<<0)) != 0) { + if (item.creation_date != 0) { s << ","; - s << "\"restoration_date\":"; - s << item.restoration_date; + s << "\"creation_date\":"; + s << item.creation_date; } - if ((item.fields_mask & (1<<1)) != 0) { + if (item.fields_mask != 0) { s << ","; - s << "\"deletion_date\":"; - s << item.deletion_date; + s << "\"fields_mask\":"; + s << item.fields_mask; + } + if ((item.fields_mask & (1<<0)) != 0) { + if (item.restoration_date != 0) { + s << ","; + s << "\"restoration_date\":"; + s << item.restoration_date; + } + } + if ((item.fields_mask & (1<<1)) != 0) { + if (item.deletion_date != 0) { + s << ","; + s << "\"deletion_date\":"; + s << item.deletion_date; + } } if ((item.fields_mask & (1<<16)) != 0) { - s << ","; - s << "\"hidden_by_privacy\":"; - if (!::tl2::details::BoolWriteJSON(s, item.hidden_by_privacy)) { return false; } + if (item.hidden_by_privacy) { + s << ","; + s << "\"hidden_by_privacy\":"; + if (!::tl2::details::BoolWriteJSON(s, item.hidden_by_privacy)) { return false; } + } } s << "}"; return true; @@ -148,14 +158,20 @@ void tl2::details::Service4ObjectReset(::tl2::service4::Object& item) { bool tl2::details::Service4ObjectWriteJSON(std::ostream& s, const ::tl2::service4::Object& item) { s << "{"; - s << "\"type\":"; - s << item.type; - s << ","; - s << "\"joint_id\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.joint_id)) { return false; } - s << ","; - s << "\"object_id\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.object_id)) { return false; } + if (item.type != 0) { + s << "\"type\":"; + s << item.type; + } + if (item.joint_id.size() != 0) { + s << ","; + s << "\"joint_id\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.joint_id)) { return false; } + } + if (item.object_id.size() != 0) { + s << ","; + s << "\"object_id\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.object_id)) { return false; } + } s << "}"; return true; } diff --git a/internal/tlcodegen/test/gen/schema_cpp/service5/details.cpp b/internal/tlcodegen/test/gen/schema_cpp/service5/details.cpp index b0c63f6f..184bcefe 100644 --- a/internal/tlcodegen/test/gen/schema_cpp/service5/details.cpp +++ b/internal/tlcodegen/test/gen/schema_cpp/service5/details.cpp @@ -91,11 +91,15 @@ void tl2::details::Service5InsertReset(::tl2::service5::Insert& item) { bool tl2::details::Service5InsertWriteJSON(std::ostream& s, const ::tl2::service5::Insert& item) { s << "{"; - s << "\"table\":"; - s << "\"" << item.table << "\""; - s << ","; - s << "\"data\":"; - s << "\"" << item.data << "\""; + if (item.table.size() != 0) { + s << "\"table\":"; + s << "\"" << item.table << "\""; + } + if (item.data.size() != 0) { + s << ","; + s << "\"data\":"; + s << "\"" << item.data << "\""; + } s << "}"; return true; } @@ -168,7 +172,7 @@ void tl2::details::Service5OutputReset(::tl2::service5::Output& item) { bool tl2::details::Service5OutputWriteJSON(std::ostream & s, const ::tl2::service5::Output& item) { s << "{"; s << "\"type\":"; - s << Service5Output_tbl_tl_tag[item.value.index()]; + s << "\"" << Service5Output_tbl_tl_name[item.value.index()] << "\""; switch (item.value.index()) { case 1: s << ",\"value\":"; @@ -238,17 +242,23 @@ void tl2::details::Service5ParamsReset(::tl2::service5::Params& item) { bool tl2::details::Service5ParamsWriteJSON(std::ostream& s, const ::tl2::service5::Params& item) { s << "{"; - s << "\"fields_mask\":"; - s << item.fields_mask; + if (item.fields_mask != 0) { + s << "\"fields_mask\":"; + s << item.fields_mask; + } if ((item.fields_mask & (1<<0)) != 0) { - s << ","; - s << "\"max_execution_speed\":"; - s << item.max_execution_speed; + if (item.max_execution_speed != 0) { + s << ","; + s << "\"max_execution_speed\":"; + s << item.max_execution_speed; + } } if ((item.fields_mask & (1<<1)) != 0) { - s << ","; - s << "\"max_execution_speed_bytes\":"; - s << item.max_execution_speed_bytes; + if (item.max_execution_speed_bytes != 0) { + s << ","; + s << "\"max_execution_speed_bytes\":"; + s << item.max_execution_speed_bytes; + } } s << "}"; return true; @@ -321,8 +331,10 @@ void tl2::details::Service5PerformQueryReset(::tl2::service5::PerformQuery& item bool tl2::details::Service5PerformQueryWriteJSON(std::ostream& s, const ::tl2::service5::PerformQuery& item) { s << "{"; - s << "\"query\":"; - s << "\"" << item.query << "\""; + if (item.query.size() != 0) { + s << "\"query\":"; + s << "\"" << item.query << "\""; + } s << "}"; return true; } @@ -395,8 +407,10 @@ void tl2::details::Service5QueryReset(::tl2::service5::Query& item) { bool tl2::details::Service5QueryWriteJSON(std::ostream& s, const ::tl2::service5::Query& item) { s << "{"; - s << "\"query\":"; - s << "\"" << item.query << "\""; + if (item.query.size() != 0) { + s << "\"query\":"; + s << "\"" << item.query << "\""; + } s << ","; s << "\"params\":"; if (!::tl2::details::Service5ParamsWriteJSON(s, item.params)) { return false; } @@ -474,11 +488,15 @@ void tl2::details::Service5StringOutputReset(::tl2::service5::StringOutput& item bool tl2::details::Service5StringOutputWriteJSON(std::ostream& s, const ::tl2::service5::StringOutput& item) { s << "{"; - s << "\"http_code\":"; - s << item.http_code; - s << ","; - s << "\"response\":"; - s << "\"" << item.response << "\""; + if (item.http_code != 0) { + s << "\"http_code\":"; + s << item.http_code; + } + if (item.response.size() != 0) { + s << ","; + s << "\"response\":"; + s << "\"" << item.response << "\""; + } s << "}"; return true; } diff --git a/internal/tlcodegen/test/gen/schema_cpp/service6/details.cpp b/internal/tlcodegen/test/gen/schema_cpp/service6/details.cpp index 61783503..0a8aa9a8 100644 --- a/internal/tlcodegen/test/gen/schema_cpp/service6/details.cpp +++ b/internal/tlcodegen/test/gen/schema_cpp/service6/details.cpp @@ -112,8 +112,10 @@ void tl2::details::Service6ErrorReset(::tl2::service6::Error& item) { bool tl2::details::Service6ErrorWriteJSON(std::ostream& s, const ::tl2::service6::Error& item) { s << "{"; - s << "\"code\":"; - s << item.code; + if (item.code != 0) { + s << "\"code\":"; + s << item.code; + } s << "}"; return true; } @@ -169,8 +171,10 @@ void tl2::details::Service6FindResultRowReset(::tl2::service6::FindResultRow& it bool tl2::details::Service6FindResultRowWriteJSON(std::ostream& s, const ::tl2::service6::FindResultRow& item) { s << "{"; - s << "\"x\":"; - s << item.x; + if (item.x != 0) { + s << "\"x\":"; + s << item.x; + } s << "}"; return true; } @@ -226,8 +230,10 @@ void tl2::details::Service6FindWithBoundsResultReset(::tl2::service6::FindWithBo bool tl2::details::Service6FindWithBoundsResultWriteJSON(std::ostream& s, const ::tl2::service6::FindWithBoundsResult& item) { s << "{"; - s << "\"x\":"; - s << item.x; + if (item.x != 0) { + s << "\"x\":"; + s << item.x; + } s << "}"; return true; } @@ -285,14 +291,20 @@ void tl2::details::Service6MultiFindReset(::tl2::service6::MultiFind& item) { bool tl2::details::Service6MultiFindWriteJSON(std::ostream& s, const ::tl2::service6::MultiFind& item) { s << "{"; - s << "\"clusters\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.clusters)) { return false; } - s << ","; - s << "\"limit\":"; - s << item.limit; - s << ","; - s << "\"eq_threshold\":"; - s << item.eq_threshold; + if (item.clusters.size() != 0) { + s << "\"clusters\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.clusters)) { return false; } + } + if (item.limit != 0) { + s << ","; + s << "\"limit\":"; + s << item.limit; + } + if (item.eq_threshold != 0) { + s << ","; + s << "\"eq_threshold\":"; + s << item.eq_threshold; + } s << "}"; return true; } @@ -370,8 +382,10 @@ void tl2::details::Service6MultiFindWithBoundsReset(::tl2::service6::MultiFindWi bool tl2::details::Service6MultiFindWithBoundsWriteJSON(std::ostream& s, const ::tl2::service6::MultiFindWithBounds& item) { s << "{"; - s << "\"clusters\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.clusters)) { return false; } + if (item.clusters.size() != 0) { + s << "\"clusters\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.clusters)) { return false; } + } s << "}"; return true; } diff --git a/internal/tlcodegen/test/gen/schema_cpp/tasks/details.cpp b/internal/tlcodegen/test/gen/schema_cpp/tasks/details.cpp index a3467ff4..75c9b630 100644 --- a/internal/tlcodegen/test/gen/schema_cpp/tasks/details.cpp +++ b/internal/tlcodegen/test/gen/schema_cpp/tasks/details.cpp @@ -89,11 +89,15 @@ void tl2::details::TasksAddTaskReset(::tl2::tasks::AddTask& item) { bool tl2::details::TasksAddTaskWriteJSON(std::ostream& s, const ::tl2::tasks::AddTask& item) { s << "{"; - s << "\"type_name\":"; - s << "\"" << item.type_name << "\""; - s << ","; - s << "\"queue_id\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.queue_id)) { return false; } + if (item.type_name.size() != 0) { + s << "\"type_name\":"; + s << "\"" << item.type_name << "\""; + } + if (item.queue_id.size() != 0) { + s << ","; + s << "\"queue_id\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.queue_id)) { return false; } + } s << ","; s << "\"task\":"; if (!::tl2::details::TasksTaskWriteJSON(s, item.task)) { return false; } @@ -177,11 +181,15 @@ void tl2::details::TasksCronTaskReset(::tl2::tasks::CronTask& item) { bool tl2::details::TasksCronTaskWriteJSON(std::ostream& s, const ::tl2::tasks::CronTask& item) { s << "{"; - s << "\"type_name\":"; - s << "\"" << item.type_name << "\""; - s << ","; - s << "\"queue_id\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.queue_id)) { return false; } + if (item.type_name.size() != 0) { + s << "\"type_name\":"; + s << "\"" << item.type_name << "\""; + } + if (item.queue_id.size() != 0) { + s << ","; + s << "\"queue_id\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.queue_id)) { return false; } + } s << ","; s << "\"task\":"; if (!::tl2::details::TasksTaskWriteJSON(s, item.task)) { return false; } @@ -251,11 +259,15 @@ void tl2::details::TasksCronTaskWithIdReset(::tl2::tasks::CronTaskWithId& item) bool tl2::details::TasksCronTaskWithIdWriteJSON(std::ostream& s, const ::tl2::tasks::CronTaskWithId& item) { s << "{"; - s << "\"id\":"; - s << item.id; - s << ","; - s << "\"next_time\":"; - s << item.next_time; + if (item.id != 0) { + s << "\"id\":"; + s << item.id; + } + if (item.next_time != 0) { + s << ","; + s << "\"next_time\":"; + s << item.next_time; + } s << ","; s << "\"task\":"; if (!::tl2::details::TasksCronTaskWriteJSON(s, item.task)) { return false; } @@ -324,37 +336,51 @@ void tl2::details::TasksCronTimeReset(::tl2::tasks::CronTime& item) { bool tl2::details::TasksCronTimeWriteJSON(std::ostream& s, const ::tl2::tasks::CronTime& item) { s << "{"; - s << "\"fields_mask\":"; - s << item.fields_mask; + if (item.fields_mask != 0) { + s << "\"fields_mask\":"; + s << item.fields_mask; + } if ((item.fields_mask & (1<<0)) != 0) { - s << ","; - s << "\"seconds\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.seconds)) { return false; } + if (item.seconds.size() != 0) { + s << ","; + s << "\"seconds\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.seconds)) { return false; } + } } if ((item.fields_mask & (1<<1)) != 0) { - s << ","; - s << "\"minutes\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.minutes)) { return false; } + if (item.minutes.size() != 0) { + s << ","; + s << "\"minutes\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.minutes)) { return false; } + } } if ((item.fields_mask & (1<<2)) != 0) { - s << ","; - s << "\"hours\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.hours)) { return false; } + if (item.hours.size() != 0) { + s << ","; + s << "\"hours\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.hours)) { return false; } + } } if ((item.fields_mask & (1<<3)) != 0) { - s << ","; - s << "\"days_of_week\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.days_of_week)) { return false; } + if (item.days_of_week.size() != 0) { + s << ","; + s << "\"days_of_week\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.days_of_week)) { return false; } + } } if ((item.fields_mask & (1<<4)) != 0) { - s << ","; - s << "\"days\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.days)) { return false; } + if (item.days.size() != 0) { + s << ","; + s << "\"days\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.days)) { return false; } + } } if ((item.fields_mask & (1<<5)) != 0) { - s << ","; - s << "\"months\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.months)) { return false; } + if (item.months.size() != 0) { + s << ","; + s << "\"months\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.months)) { return false; } + } } s << "}"; return true; @@ -529,14 +555,20 @@ void tl2::details::TasksGetQueueSizeReset(::tl2::tasks::GetQueueSize& item) { bool tl2::details::TasksGetQueueSizeWriteJSON(std::ostream& s, const ::tl2::tasks::GetQueueSize& item) { s << "{"; - s << "\"type_name\":"; - s << "\"" << item.type_name << "\""; - s << ","; - s << "\"queue_id\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.queue_id)) { return false; } - s << ","; - s << "\"fields_mask\":"; - s << item.fields_mask; + if (item.type_name.size() != 0) { + s << "\"type_name\":"; + s << "\"" << item.type_name << "\""; + } + if (item.queue_id.size() != 0) { + s << ","; + s << "\"queue_id\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.queue_id)) { return false; } + } + if (item.fields_mask != 0) { + s << ","; + s << "\"fields_mask\":"; + s << item.fields_mask; + } s << "}"; return true; } @@ -613,11 +645,15 @@ void tl2::details::TasksGetQueueTypesReset(::tl2::tasks::GetQueueTypes& item) { bool tl2::details::TasksGetQueueTypesWriteJSON(std::ostream& s, const ::tl2::tasks::GetQueueTypes& item) { s << "{"; - s << "\"settings_mask\":"; - s << item.settings_mask; - s << ","; - s << "\"stats_mask\":"; - s << item.stats_mask; + if (item.settings_mask != 0) { + s << "\"settings_mask\":"; + s << item.settings_mask; + } + if (item.stats_mask != 0) { + s << ","; + s << "\"stats_mask\":"; + s << item.stats_mask; + } s << "}"; return true; } @@ -694,11 +730,15 @@ void tl2::details::TasksGetTaskFromQueueReset(::tl2::tasks::GetTaskFromQueue& it bool tl2::details::TasksGetTaskFromQueueWriteJSON(std::ostream& s, const ::tl2::tasks::GetTaskFromQueue& item) { s << "{"; - s << "\"type_name\":"; - s << "\"" << item.type_name << "\""; - s << ","; - s << "\"queue_id\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.queue_id)) { return false; } + if (item.type_name.size() != 0) { + s << "\"type_name\":"; + s << "\"" << item.type_name << "\""; + } + if (item.queue_id.size() != 0) { + s << ","; + s << "\"queue_id\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.queue_id)) { return false; } + } s << "}"; return true; } @@ -775,18 +815,24 @@ void tl2::details::TasksQueueStatsReset(::tl2::tasks::QueueStats& item) { bool tl2::details::TasksQueueStatsWriteJSON(std::ostream& s, const ::tl2::tasks::QueueStats& item, uint32_t nat_fields_mask) { s << "{"; if ((nat_fields_mask & (1<<0)) != 0) { - s << "\"waiting_size\":"; - s << item.waiting_size; + if (item.waiting_size != 0) { + s << "\"waiting_size\":"; + s << item.waiting_size; + } } if ((nat_fields_mask & (1<<1)) != 0) { - s << ","; - s << "\"scheduled_size\":"; - s << item.scheduled_size; + if (item.scheduled_size != 0) { + s << ","; + s << "\"scheduled_size\":"; + s << item.scheduled_size; + } } if ((nat_fields_mask & (1<<2)) != 0) { - s << ","; - s << "\"in_progress_size\":"; - s << item.in_progress_size; + if (item.in_progress_size != 0) { + s << ","; + s << "\"in_progress_size\":"; + s << item.in_progress_size; + } } s << "}"; return true; @@ -867,8 +913,10 @@ void tl2::details::TasksQueueTypeInfoReset(::tl2::tasks::QueueTypeInfo& item) { bool tl2::details::TasksQueueTypeInfoWriteJSON(std::ostream& s, const ::tl2::tasks::QueueTypeInfo& item) { s << "{"; - s << "\"type_name\":"; - s << "\"" << item.type_name << "\""; + if (item.type_name.size() != 0) { + s << "\"type_name\":"; + s << "\"" << item.type_name << "\""; + } s << ","; s << "\"settings\":"; if (!::tl2::details::TasksQueueTypeSettingsWriteJSON(s, item.settings)) { return false; } @@ -943,52 +991,72 @@ void tl2::details::TasksQueueTypeSettingsReset(::tl2::tasks::QueueTypeSettings& bool tl2::details::TasksQueueTypeSettingsWriteJSON(std::ostream& s, const ::tl2::tasks::QueueTypeSettings& item) { s << "{"; - s << "\"fields_mask\":"; - s << item.fields_mask; + if (item.fields_mask != 0) { + s << "\"fields_mask\":"; + s << item.fields_mask; + } if ((item.fields_mask & (1<<0)) != 0) { - s << ","; - s << "\"is_enabled\":"; - if (!::tl2::details::BoolWriteJSON(s, item.is_enabled)) { return false; } + if (item.is_enabled) { + s << ","; + s << "\"is_enabled\":"; + if (!::tl2::details::BoolWriteJSON(s, item.is_enabled)) { return false; } + } } if ((item.fields_mask & (1<<1)) != 0) { - s << ","; - s << "\"is_persistent\":"; - if (!::tl2::details::BoolWriteJSON(s, item.is_persistent)) { return false; } + if (item.is_persistent) { + s << ","; + s << "\"is_persistent\":"; + if (!::tl2::details::BoolWriteJSON(s, item.is_persistent)) { return false; } + } } if ((item.fields_mask & (1<<2)) != 0) { - s << ","; - s << "\"priority\":"; - s << item.priority; + if (item.priority != 0) { + s << ","; + s << "\"priority\":"; + s << item.priority; + } } if ((item.fields_mask & (1<<3)) != 0) { - s << ","; - s << "\"default_retry_time\":"; - s << item.default_retry_time; + if (item.default_retry_time != 0) { + s << ","; + s << "\"default_retry_time\":"; + s << item.default_retry_time; + } } if ((item.fields_mask & (1<<3)) != 0) { - s << ","; - s << "\"default_retry_num\":"; - s << item.default_retry_num; + if (item.default_retry_num != 0) { + s << ","; + s << "\"default_retry_num\":"; + s << item.default_retry_num; + } } if ((item.fields_mask & (1<<4)) != 0) { - s << ","; - s << "\"move_to_queue_type_on_error\":"; - s << "\"" << item.move_to_queue_type_on_error << "\""; + if (item.move_to_queue_type_on_error.size() != 0) { + s << ","; + s << "\"move_to_queue_type_on_error\":"; + s << "\"" << item.move_to_queue_type_on_error << "\""; + } } if ((item.fields_mask & (1<<5)) != 0) { - s << ","; - s << "\"is_blocking\":"; - if (!::tl2::details::BoolWriteJSON(s, item.is_blocking)) { return false; } + if (item.is_blocking) { + s << ","; + s << "\"is_blocking\":"; + if (!::tl2::details::BoolWriteJSON(s, item.is_blocking)) { return false; } + } } if ((item.fields_mask & (1<<6)) != 0) { - s << ","; - s << "\"timelimit\":"; - s << item.timelimit; + if (item.timelimit != 0) { + s << ","; + s << "\"timelimit\":"; + s << item.timelimit; + } } if ((item.fields_mask & (1<<7)) != 0) { - s << ","; - s << "\"max_queue_size\":"; - s << item.max_queue_size; + if (item.max_queue_size != 0) { + s << ","; + s << "\"max_queue_size\":"; + s << item.max_queue_size; + } } s << "}"; return true; @@ -1121,27 +1189,37 @@ void tl2::details::TasksQueueTypeStatsReset(::tl2::tasks::QueueTypeStats& item) bool tl2::details::TasksQueueTypeStatsWriteJSON(std::ostream& s, const ::tl2::tasks::QueueTypeStats& item) { s << "{"; - s << "\"fields_mask\":"; - s << item.fields_mask; + if (item.fields_mask != 0) { + s << "\"fields_mask\":"; + s << item.fields_mask; + } if ((item.fields_mask & (1<<0)) != 0) { - s << ","; - s << "\"waiting_size\":"; - s << item.waiting_size; + if (item.waiting_size != 0) { + s << ","; + s << "\"waiting_size\":"; + s << item.waiting_size; + } } if ((item.fields_mask & (1<<1)) != 0) { - s << ","; - s << "\"scheduled_size\":"; - s << item.scheduled_size; + if (item.scheduled_size != 0) { + s << ","; + s << "\"scheduled_size\":"; + s << item.scheduled_size; + } } if ((item.fields_mask & (1<<2)) != 0) { - s << ","; - s << "\"in_progress_size\":"; - s << item.in_progress_size; + if (item.in_progress_size != 0) { + s << ","; + s << "\"in_progress_size\":"; + s << item.in_progress_size; + } } if ((item.fields_mask & (1<<3)) != 0) { - s << ","; - s << "\"num_queues\":"; - s << item.num_queues; + if (item.num_queues != 0) { + s << ","; + s << "\"num_queues\":"; + s << item.num_queues; + } } s << "}"; return true; @@ -1237,36 +1315,52 @@ void tl2::details::TasksTaskReset(::tl2::tasks::Task& item) { bool tl2::details::TasksTaskWriteJSON(std::ostream& s, const ::tl2::tasks::Task& item) { s << "{"; - s << "\"fields_mask\":"; - s << item.fields_mask; - s << ","; - s << "\"flags\":"; - s << item.flags; - s << ","; - s << "\"tag\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.tag)) { return false; } - s << ","; - s << "\"data\":"; - s << "\"" << item.data << "\""; - if ((item.fields_mask & (1<<0)) != 0) { + if (item.fields_mask != 0) { + s << "\"fields_mask\":"; + s << item.fields_mask; + } + if (item.flags != 0) { s << ","; - s << "\"id\":"; - s << item.id; + s << "\"flags\":"; + s << item.flags; } - if ((item.fields_mask & (1<<1)) != 0) { + if (item.tag.size() != 0) { s << ","; - s << "\"retries\":"; - s << item.retries; + s << "\"tag\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.tag)) { return false; } } - if ((item.fields_mask & (1<<2)) != 0) { + if (item.data.size() != 0) { s << ","; - s << "\"scheduled_time\":"; - s << item.scheduled_time; + s << "\"data\":"; + s << "\"" << item.data << "\""; + } + if ((item.fields_mask & (1<<0)) != 0) { + if (item.id != 0) { + s << ","; + s << "\"id\":"; + s << item.id; + } + } + if ((item.fields_mask & (1<<1)) != 0) { + if (item.retries != 0) { + s << ","; + s << "\"retries\":"; + s << item.retries; + } + } + if ((item.fields_mask & (1<<2)) != 0) { + if (item.scheduled_time != 0) { + s << ","; + s << "\"scheduled_time\":"; + s << item.scheduled_time; + } } if ((item.fields_mask & (1<<3)) != 0) { - s << ","; - s << "\"deadline\":"; - s << item.deadline; + if (item.deadline != 0) { + s << ","; + s << "\"deadline\":"; + s << item.deadline; + } } s << "}"; return true; @@ -1363,11 +1457,15 @@ void tl2::details::TasksTaskInfoReset(::tl2::tasks::TaskInfo& item) { bool tl2::details::TasksTaskInfoWriteJSON(std::ostream& s, const ::tl2::tasks::TaskInfo& item) { s << "{"; - s << "\"type_name\":"; - s << "\"" << item.type_name << "\""; - s << ","; - s << "\"queue_id\":"; - if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.queue_id)) { return false; } + if (item.type_name.size() != 0) { + s << "\"type_name\":"; + s << "\"" << item.type_name << "\""; + } + if (item.queue_id.size() != 0) { + s << ","; + s << "\"queue_id\":"; + if (!::tl2::details::BuiltinVectorIntWriteJSON(s, item.queue_id)) { return false; } + } s << ","; s << "\"task\":"; if (!::tl2::details::TasksTaskWriteJSON(s, item.task)) { return false; } @@ -1459,12 +1557,7 @@ void tl2::details::TasksTaskStatusReset(::tl2::tasks::TaskStatus& item) { } bool tl2::details::TasksTaskStatusWriteJSON(std::ostream & s, const ::tl2::tasks::TaskStatus& item) { - s << "{"; - s << "\"type\":"; - s << TasksTaskStatus_tbl_tl_tag[item.value.index()]; - switch (item.value.index()) { - } - s << "}"; + s << "\"" << TasksTaskStatus_tbl_tl_name[item.value.index()] << "\""; return true; } bool tl2::details::TasksTaskStatusReadBoxed(::basictl::tl_istream & s, ::tl2::tasks::TaskStatus& item) { diff --git a/internal/tlcodegen/test/gen/schema_cpp/tree_stats/details.cpp b/internal/tlcodegen/test/gen/schema_cpp/tree_stats/details.cpp index 45f16920..4636fd0f 100644 --- a/internal/tlcodegen/test/gen/schema_cpp/tree_stats/details.cpp +++ b/internal/tlcodegen/test/gen/schema_cpp/tree_stats/details.cpp @@ -33,7 +33,7 @@ void tl2::details::TreeStatsObjectLimitValueReset(::tl2::tree_stats::ObjectLimit bool tl2::details::TreeStatsObjectLimitValueWriteJSON(std::ostream & s, const ::tl2::tree_stats::ObjectLimitValue& item) { s << "{"; s << "\"type\":"; - s << TreeStatsObjectLimitValue_tbl_tl_tag[item.value.index()]; + s << "\"" << TreeStatsObjectLimitValue_tbl_tl_name[item.value.index()] << "\""; switch (item.value.index()) { case 1: s << ",\"value\":"; diff --git a/internal/tlcodegen/test/gen/schema_cpp/unique/details.cpp b/internal/tlcodegen/test/gen/schema_cpp/unique/details.cpp index 2cb72277..ec8aad80 100644 --- a/internal/tlcodegen/test/gen/schema_cpp/unique/details.cpp +++ b/internal/tlcodegen/test/gen/schema_cpp/unique/details.cpp @@ -34,8 +34,10 @@ void tl2::details::UniqueGetReset(::tl2::unique::Get& item) { bool tl2::details::UniqueGetWriteJSON(std::ostream& s, const ::tl2::unique::Get& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } s << "}"; return true; } @@ -107,8 +109,10 @@ void tl2::details::UniqueStringToIntReset(::tl2::unique::StringToInt& item) { bool tl2::details::UniqueStringToIntWriteJSON(std::ostream& s, const ::tl2::unique::StringToInt& item) { s << "{"; - s << "\"key\":"; - s << "\"" << item.key << "\""; + if (item.key.size() != 0) { + s << "\"key\":"; + s << "\"" << item.key << "\""; + } s << "}"; return true; } diff --git a/internal/tlcodegen/type_rw.go b/internal/tlcodegen/type_rw.go index be0bdaff..9428806c 100644 --- a/internal/tlcodegen/type_rw.go +++ b/internal/tlcodegen/type_rw.go @@ -740,6 +740,7 @@ type TypeRW interface { CPPTypeWritingJsonCode(bytesVersion bool, val string, bare bool, natArgs []string, last bool) string CPPTypeWritingCode(bytesVersion bool, val string, bare bool, natArgs []string, last bool) string CPPTypeReadingCode(bytesVersion bool, val string, bare bool, natArgs []string, last bool) string + CPPTypeJSONEmptyCondition(bytesVersion bool, val string, ref bool, deps []string) string CPPGenerateCode(hpp *strings.Builder, hppInc *DirectIncludesCPP, hppIncFwd *DirectIncludesCPP, hppDet *strings.Builder, hppDetInc *DirectIncludesCPP, cppDet *strings.Builder, cppDetInc *DirectIncludesCPP, bytesVersion bool, forwardDeclaration bool) } diff --git a/internal/tlcodegen/type_rw_bool_cpp.go b/internal/tlcodegen/type_rw_bool_cpp.go index 8abed73e..b3aa2e2f 100644 --- a/internal/tlcodegen/type_rw_bool_cpp.go +++ b/internal/tlcodegen/type_rw_bool_cpp.go @@ -11,6 +11,10 @@ import ( "strings" ) +func (trw *TypeRWBool) CPPTypeJSONEmptyCondition(bytesVersion bool, val string, ref bool, deps []string) string { + return addAsterisk(ref, val) +} + func (trw *TypeRWBool) CPPFillRecursiveChildren(visitedNodes map[*TypeRWWrapper]bool) { } diff --git a/internal/tlcodegen/type_rw_maybe_cpp.go b/internal/tlcodegen/type_rw_maybe_cpp.go index bcec4f04..b3f53244 100644 --- a/internal/tlcodegen/type_rw_maybe_cpp.go +++ b/internal/tlcodegen/type_rw_maybe_cpp.go @@ -11,6 +11,10 @@ import ( "strings" ) +func (trw *TypeRWMaybe) CPPTypeJSONEmptyCondition(bytesVersion bool, val string, ref bool, deps []string) string { + return val + ".has_value()" +} + func (trw *TypeRWMaybe) CPPFillRecursiveChildren(visitedNodes map[*TypeRWWrapper]bool) { trw.element.t.CPPFillRecursiveChildren(visitedNodes) } diff --git a/internal/tlcodegen/type_rw_primitive_cpp.go b/internal/tlcodegen/type_rw_primitive_cpp.go index b67c740b..0c41ffc7 100644 --- a/internal/tlcodegen/type_rw_primitive_cpp.go +++ b/internal/tlcodegen/type_rw_primitive_cpp.go @@ -11,6 +11,13 @@ import ( "strings" ) +func (trw *TypeRWPrimitive) CPPTypeJSONEmptyCondition(bytesVersion bool, val string, ref bool, deps []string) string { + if trw.tlType == "string" { + return fmt.Sprintf("%s.size() != 0", addAsterisk(ref, val)) + } + return fmt.Sprintf("%s != 0", addAsterisk(ref, val)) +} + func (trw *TypeRWPrimitive) CPPFillRecursiveChildren(visitedNodes map[*TypeRWWrapper]bool) { } diff --git a/internal/tlcodegen/type_rw_struct_cpp.go b/internal/tlcodegen/type_rw_struct_cpp.go index bb187a7b..1b395163 100644 --- a/internal/tlcodegen/type_rw_struct_cpp.go +++ b/internal/tlcodegen/type_rw_struct_cpp.go @@ -13,6 +13,13 @@ import ( "strings" ) +func (trw *TypeRWStruct) CPPTypeJSONEmptyCondition(bytesVersion bool, val string, ref bool, deps []string) string { + if trw.isTypeDef() { + return trw.Fields[0].t.trw.CPPTypeJSONEmptyCondition(bytesVersion, val, ref, deps) + } + return "" +} + func (trw *TypeRWStruct) CPPFillRecursiveChildren(visitedNodes map[*TypeRWWrapper]bool) { for _, f := range trw.Fields { if !f.recursive { @@ -514,6 +521,11 @@ func (trw *TypeRWStruct) CPPWriteJsonFields(bytesVersion bool) string { s.WriteString(fmt.Sprintf("\tif ((%s & (1<<%d)) != 0) {\n", formatNatArgCPP(trw.Fields, *field.fieldMask), field.BitNumber)) indent++ } + emptyCheck := field.t.trw.CPPTypeJSONEmptyCondition(bytesVersion, fmt.Sprintf("item.%s", field.cppName), field.recursive, formatNatArgsCPP(trw.Fields, field.natArgs)) + if emptyCheck != "" { + s.WriteString(fmt.Sprintf("%sif (%s) {\n", strings.Repeat("\t", indent+1), emptyCheck)) + indent++ + } if i != 0 { // append s.WriteString(fmt.Sprintf(`%ss << ","; @@ -530,6 +542,9 @@ func (trw *TypeRWStruct) CPPWriteJsonFields(bytesVersion bool) string { s.WriteString( field.t.trw.CPPTypeWritingJsonCode(bytesVersion, addAsterisk(field.recursive, fmt.Sprintf("item.%s", field.cppName)), field.Bare(), formatNatArgsCPP(trw.Fields, field.natArgs), false) + "\n") + if emptyCheck != "" { + s.WriteString(fmt.Sprintf("%s}\n", strings.Repeat("\t", indent))) + } if field.fieldMask != nil { s.WriteString("\t}\n") } diff --git a/internal/tlcodegen/type_rw_tuple_cpp.go b/internal/tlcodegen/type_rw_tuple_cpp.go index 23c62ae7..2fe49595 100644 --- a/internal/tlcodegen/type_rw_tuple_cpp.go +++ b/internal/tlcodegen/type_rw_tuple_cpp.go @@ -11,6 +11,16 @@ import ( "strings" ) +func (trw *TypeRWBrackets) CPPTypeJSONEmptyCondition(bytesVersion bool, val string, ref bool, deps []string) string { + if trw.dictLike || trw.vectorLike || trw.dynamicSize { + if trw.dynamicSize { + return fmt.Sprintf("(%s.size() != 0) || (%s != 0)", addAsterisk(ref, val), deps[0]) + } + return fmt.Sprintf("%s.size() != 0", addAsterisk(ref, val)) + } + return "" +} + func (trw *TypeRWBrackets) CPPFillRecursiveChildren(visitedNodes map[*TypeRWWrapper]bool) { if trw.vectorLike || trw.dynamicSize { return diff --git a/internal/tlcodegen/type_rw_union_cpp.go b/internal/tlcodegen/type_rw_union_cpp.go index b02a93aa..da71aef0 100644 --- a/internal/tlcodegen/type_rw_union_cpp.go +++ b/internal/tlcodegen/type_rw_union_cpp.go @@ -12,6 +12,10 @@ import ( "strings" ) +func (trw *TypeRWUnion) CPPTypeJSONEmptyCondition(bytesVersion bool, val string, ref bool, deps []string) string { + return "" +} + func (trw *TypeRWUnion) CPPFillRecursiveChildren(visitedNodes map[*TypeRWWrapper]bool) { for _, f := range trw.Fields { if !f.recursive { @@ -196,12 +200,7 @@ void %[7]s::%[1]sReset(%[2]s& item) { } bool %[7]s::%[1]sWriteJSON(std::ostream & s, const %[2]s& item%[3]s) { - s << "{"; - s << "\"type\":"; - s << %[1]s_tbl_tl_tag[item.value.index()]; - switch (item.value.index()) { -%[8]s } - s << "}"; +%[8]s return true; } bool %[7]s::%[1]sReadBoxed(::basictl::tl_istream & s, %[2]s& item%[3]s) { @@ -467,16 +466,28 @@ func (trw *TypeRWUnion) CPPWriteFields(bytesVersion bool) string { func (trw *TypeRWUnion) CPPWriteJSONFields(bytesVersion bool) string { var s strings.Builder - for fieldIndex, field := range trw.Fields { - if !field.t.IsTrueType() { - s.WriteString(fmt.Sprintf("\tcase %d:\n", fieldIndex)) - s.WriteString(` s << ",\"value\":"; + if trw.IsEnum { + s.WriteString(fmt.Sprintf(` s << "\"" << %s_tbl_tl_name[item.value.index()] << "\"";`, trw.wr.goGlobalName)) + } else { + s.WriteString(fmt.Sprintf(` s << "{"; + s << "\"type\":"; + s << "\"" << %s_tbl_tl_name[item.value.index()] << "\""; + switch (item.value.index()) { +`, trw.wr.goGlobalName)) + + for fieldIndex, field := range trw.Fields { + if !field.t.IsTrueType() { + s.WriteString(fmt.Sprintf("\tcase %d:\n", fieldIndex)) + s.WriteString(` s << ",\"value\":"; `) - s.WriteString("\t" + - field.t.trw.CPPTypeWritingJsonCode(bytesVersion, addAsterisk(field.recursive, fmt.Sprintf("std::get<%d>(item.value)", fieldIndex)), - true, formatNatArgsCPP(trw.Fields, field.natArgs), false) + "\n") - s.WriteString("\t\tbreak;\n") + s.WriteString("\t" + + field.t.trw.CPPTypeWritingJsonCode(bytesVersion, addAsterisk(field.recursive, fmt.Sprintf("std::get<%d>(item.value)", fieldIndex)), + true, formatNatArgsCPP(trw.Fields, field.natArgs), false) + "\n") + s.WriteString("\t\tbreak;\n") + } } + s.WriteString(` } + s << "}";`) } return s.String() }