Skip to content

Commit

Permalink
add write-json
Browse files Browse the repository at this point in the history
  • Loading branch information
Brat-vseznamus committed Jul 31, 2024
1 parent f799adf commit a685b72
Show file tree
Hide file tree
Showing 451 changed files with 7,121 additions and 4 deletions.
1 change: 1 addition & 0 deletions internal/tlcodegen/helpers_cpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package tlcodegen
const basicCPPTLCodeHeader = `%s
#pragma once
#include <ostream>
#include <stddef.h>
#include <cstring>
#include <stdexcept>
Expand Down
4 changes: 4 additions & 0 deletions internal/tlcodegen/test/codegen_test/cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ run-all-tests:
make run-objects-test
make run-functions-test

clean-build:
rm -rf build
mkdir build

run-objects-test: build-objects-bytes
./build/test_objects_bytes

Expand Down
131 changes: 131 additions & 0 deletions internal/tlcodegen/test/gen/cases_cpp/__common_namespace/details.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ void tl2::details::BuiltinVectorDictionaryFieldAnyDoubleIntReset(std::vector<::t
item.resize(0); // TODO - unwrap
}

bool tl2::details::BuiltinVectorDictionaryFieldAnyDoubleIntWriteJSON(std::ostream & s, const std::vector<::tl2::DictionaryFieldAny<double, int32_t>>& item) {
s << "[";
size_t index = 0;
for(const auto & el : item) {
if (!::tl2::details::DictionaryFieldAnyDoubleIntWriteJSON(s, el)) { return false; }
if (index != item.size() - 1) {
s << ",";
}
index++;
}
s << "]";
return true;
}

bool tl2::details::BuiltinVectorDictionaryFieldAnyDoubleIntRead(::basictl::tl_istream & s, std::vector<::tl2::DictionaryFieldAny<double, int32_t>>& item) {
uint32_t len = 0;
if (!s.nat_read(len)) { return false; }
Expand All @@ -38,6 +52,20 @@ void tl2::details::BuiltinVectorDictionaryFieldAnyIntIntReset(std::vector<::tl2:
item.resize(0); // TODO - unwrap
}

bool tl2::details::BuiltinVectorDictionaryFieldAnyIntIntWriteJSON(std::ostream & s, const std::vector<::tl2::DictionaryFieldAny<int32_t, int32_t>>& item) {
s << "[";
size_t index = 0;
for(const auto & el : item) {
if (!::tl2::details::DictionaryFieldAnyIntIntWriteJSON(s, el)) { return false; }
if (index != item.size() - 1) {
s << ",";
}
index++;
}
s << "]";
return true;
}

bool tl2::details::BuiltinVectorDictionaryFieldAnyIntIntRead(::basictl::tl_istream & s, std::vector<::tl2::DictionaryFieldAny<int32_t, int32_t>>& item) {
uint32_t len = 0;
if (!s.nat_read(len)) { return false; }
Expand All @@ -61,6 +89,20 @@ void tl2::details::BuiltinVectorDictionaryFieldIntReset(std::vector<::tl2::Dicti
item.resize(0); // TODO - unwrap
}

bool tl2::details::BuiltinVectorDictionaryFieldIntWriteJSON(std::ostream & s, const std::vector<::tl2::DictionaryField<int32_t>>& item) {
s << "[";
size_t index = 0;
for(const auto & el : item) {
if (!::tl2::details::DictionaryFieldIntWriteJSON(s, el)) { return false; }
if (index != item.size() - 1) {
s << ",";
}
index++;
}
s << "]";
return true;
}

bool tl2::details::BuiltinVectorDictionaryFieldIntRead(::basictl::tl_istream & s, std::vector<::tl2::DictionaryField<int32_t>>& item) {
uint32_t len = 0;
if (!s.nat_read(len)) { return false; }
Expand All @@ -84,6 +126,11 @@ void tl2::details::DictionaryAnyDoubleIntReset(::tl2::DictionaryAny<double, int3
item.clear();
}

bool tl2::details::DictionaryAnyDoubleIntWriteJSON(std::ostream& s, const ::tl2::DictionaryAny<double, int32_t>& item) {
if (!::tl2::details::BuiltinVectorDictionaryFieldAnyDoubleIntWriteJSON(s, item)) { return false; }
return true;
}

bool tl2::details::DictionaryAnyDoubleIntRead(::basictl::tl_istream & s, ::tl2::DictionaryAny<double, int32_t>& item) {
if (!::tl2::details::BuiltinVectorDictionaryFieldAnyDoubleIntRead(s, item)) { return false; }
return true;
Expand All @@ -108,6 +155,11 @@ void tl2::details::DictionaryAnyIntIntReset(std::vector<::tl2::DictionaryFieldAn
item.clear();
}

bool tl2::details::DictionaryAnyIntIntWriteJSON(std::ostream& s, const std::vector<::tl2::DictionaryFieldAny<int32_t, int32_t>>& item) {
if (!::tl2::details::BuiltinVectorDictionaryFieldAnyIntIntWriteJSON(s, item)) { return false; }
return true;
}

bool tl2::details::DictionaryAnyIntIntRead(::basictl::tl_istream & s, std::vector<::tl2::DictionaryFieldAny<int32_t, int32_t>>& item) {
if (!::tl2::details::BuiltinVectorDictionaryFieldAnyIntIntRead(s, item)) { return false; }
return true;
Expand All @@ -133,6 +185,17 @@ void tl2::details::DictionaryFieldAnyDoubleIntReset(::tl2::DictionaryFieldAny<do
item.value = 0;
}

bool tl2::details::DictionaryFieldAnyDoubleIntWriteJSON(std::ostream& s, const ::tl2::DictionaryFieldAny<double, int32_t>& item) {
s << "{";
s << "\"key\":";
s << item.key;
s << ",";
s << "\"value\":";
s << item.value;
s << "}";
return true;
}

bool tl2::details::DictionaryFieldAnyDoubleIntRead(::basictl::tl_istream & s, ::tl2::DictionaryFieldAny<double, int32_t>& item) {
if (!s.double_read(item.key)) { return false; }
if (!s.int_read(item.value)) { return false; }
Expand Down Expand Up @@ -160,6 +223,17 @@ void tl2::details::DictionaryFieldAnyIntIntReset(::tl2::DictionaryFieldAny<int32
item.value = 0;
}

bool tl2::details::DictionaryFieldAnyIntIntWriteJSON(std::ostream& s, const ::tl2::DictionaryFieldAny<int32_t, int32_t>& item) {
s << "{";
s << "\"key\":";
s << item.key;
s << ",";
s << "\"value\":";
s << item.value;
s << "}";
return true;
}

bool tl2::details::DictionaryFieldAnyIntIntRead(::basictl::tl_istream & s, ::tl2::DictionaryFieldAny<int32_t, int32_t>& item) {
if (!s.int_read(item.key)) { return false; }
if (!s.int_read(item.value)) { return false; }
Expand Down Expand Up @@ -187,6 +261,17 @@ void tl2::details::DictionaryFieldIntReset(::tl2::DictionaryField<int32_t>& item
item.value = 0;
}

bool tl2::details::DictionaryFieldIntWriteJSON(std::ostream& s, const ::tl2::DictionaryField<int32_t>& item) {
s << "{";
s << "\"key\":";
s << "\"" << item.key << "\"";
s << ",";
s << "\"value\":";
s << item.value;
s << "}";
return true;
}

bool tl2::details::DictionaryFieldIntRead(::basictl::tl_istream & s, ::tl2::DictionaryField<int32_t>& item) {
if (!s.string_read(item.key)) { return false; }
if (!s.int_read(item.value)) { return false; }
Expand All @@ -213,6 +298,11 @@ void tl2::details::DictionaryIntReset(::tl2::Dictionary<int32_t>& item) {
item.clear();
}

bool tl2::details::DictionaryIntWriteJSON(std::ostream& s, const ::tl2::Dictionary<int32_t>& item) {
if (!::tl2::details::BuiltinVectorDictionaryFieldIntWriteJSON(s, item)) { return false; }
return true;
}

bool tl2::details::DictionaryIntRead(::basictl::tl_istream & s, ::tl2::Dictionary<int32_t>& item) {
if (!::tl2::details::BuiltinVectorDictionaryFieldIntRead(s, item)) { return false; }
return true;
Expand All @@ -237,6 +327,11 @@ void tl2::details::IntReset(int32_t& item) {
item = 0;
}

bool tl2::details::IntWriteJSON(std::ostream& s, const int32_t& item) {
s << item;
return true;
}

bool tl2::details::IntRead(::basictl::tl_istream & s, int32_t& item) {
if (!s.int_read(item)) { return false; }
return true;
Expand All @@ -261,6 +356,11 @@ void tl2::details::Int32Reset(::tl2::Int32& item) {
item = 0;
}

bool tl2::details::Int32WriteJSON(std::ostream& s, const ::tl2::Int32& item) {
s << item;
return true;
}

bool tl2::details::Int32Read(::basictl::tl_istream & s, ::tl2::Int32& item) {
if (!s.int_read(item)) { return false; }
return true;
Expand All @@ -285,6 +385,11 @@ void tl2::details::Int64Reset(::tl2::Int64& item) {
item = 0;
}

bool tl2::details::Int64WriteJSON(std::ostream& s, const ::tl2::Int64& item) {
s << item;
return true;
}

bool tl2::details::Int64Read(::basictl::tl_istream & s, ::tl2::Int64& item) {
if (!s.long_read(item)) { return false; }
return true;
Expand All @@ -309,6 +414,11 @@ void tl2::details::LongReset(int64_t& item) {
item = 0;
}

bool tl2::details::LongWriteJSON(std::ostream& s, const int64_t& item) {
s << item;
return true;
}

bool tl2::details::LongRead(::basictl::tl_istream & s, int64_t& item) {
if (!s.long_read(item)) { return false; }
return true;
Expand All @@ -333,6 +443,11 @@ void tl2::details::StringReset(std::string& item) {
item.clear();
}

bool tl2::details::StringWriteJSON(std::ostream& s, const std::string& item) {
s << "\"" << item << "\"";
return true;
}

bool tl2::details::StringRead(::basictl::tl_istream & s, std::string& item) {
if (!s.string_read(item)) { return false; }
return true;
Expand All @@ -353,6 +468,11 @@ bool tl2::details::StringWriteBoxed(::basictl::tl_ostream & s, const std::string
return tl2::details::StringWrite(s, item);
}

bool tl2::True::write_json(std::ostream& s)const {
if (!::tl2::details::TrueWriteJSON(s, *this)) { return false; }
return true;
}

bool tl2::True::read(::basictl::tl_istream & s) {
if (!::tl2::details::TrueRead(s, *this)) { return false; }
return true;
Expand All @@ -376,6 +496,12 @@ bool tl2::True::write_boxed(::basictl::tl_ostream & s)const {
void tl2::details::TrueReset(::tl2::True& item) {
}

bool tl2::details::TrueWriteJSON(std::ostream& s, const ::tl2::True& item) {
s << "{";
s << "}";
return true;
}

bool tl2::details::TrueRead(::basictl::tl_istream & s, ::tl2::True& item) {
return true;
}
Expand All @@ -398,6 +524,11 @@ void tl2::details::VectorDictionaryFieldIntReset(std::vector<::tl2::DictionaryFi
item.clear();
}

bool tl2::details::VectorDictionaryFieldIntWriteJSON(std::ostream& s, const std::vector<::tl2::DictionaryField<int32_t>>& item) {
if (!::tl2::details::BuiltinVectorDictionaryFieldIntWriteJSON(s, item)) { return false; }
return true;
}

bool tl2::details::VectorDictionaryFieldIntRead(::basictl::tl_istream & s, std::vector<::tl2::DictionaryField<int32_t>>& item) {
if (!::tl2::details::BuiltinVectorDictionaryFieldIntRead(s, item)) { return false; }
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace tl2 { namespace details {

void DictionaryIntReset(::tl2::Dictionary<int32_t>& item);

bool DictionaryIntWriteJSON(std::ostream& s, const ::tl2::Dictionary<int32_t>& item);
bool DictionaryIntRead(::basictl::tl_istream & s, ::tl2::Dictionary<int32_t>& item);
bool DictionaryIntWrite(::basictl::tl_ostream & s, const ::tl2::Dictionary<int32_t>& item);
bool DictionaryIntReadBoxed(::basictl::tl_istream & s, ::tl2::Dictionary<int32_t>& item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
namespace tl2 { namespace details {

void DictionaryAnyDoubleIntReset(::tl2::DictionaryAny<double, int32_t>& item);

bool DictionaryAnyDoubleIntWriteJSON(std::ostream& s, const ::tl2::DictionaryAny<double, int32_t>& item);
bool DictionaryAnyDoubleIntRead(::basictl::tl_istream & s, ::tl2::DictionaryAny<double, int32_t>& item);
bool DictionaryAnyDoubleIntWrite(::basictl::tl_ostream & s, const ::tl2::DictionaryAny<double, int32_t>& item);
bool DictionaryAnyDoubleIntReadBoxed(::basictl::tl_istream & s, ::tl2::DictionaryAny<double, int32_t>& item);
Expand All @@ -17,6 +19,8 @@ bool DictionaryAnyDoubleIntWriteBoxed(::basictl::tl_ostream & s, const ::tl2::Di
namespace tl2 { namespace details {

void DictionaryAnyIntIntReset(std::vector<::tl2::DictionaryFieldAny<int32_t, int32_t>>& item);

bool DictionaryAnyIntIntWriteJSON(std::ostream& s, const std::vector<::tl2::DictionaryFieldAny<int32_t, int32_t>>& item);
bool DictionaryAnyIntIntRead(::basictl::tl_istream & s, std::vector<::tl2::DictionaryFieldAny<int32_t, int32_t>>& item);
bool DictionaryAnyIntIntWrite(::basictl::tl_ostream & s, const std::vector<::tl2::DictionaryFieldAny<int32_t, int32_t>>& item);
bool DictionaryAnyIntIntReadBoxed(::basictl::tl_istream & s, std::vector<::tl2::DictionaryFieldAny<int32_t, int32_t>>& item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace tl2 { namespace details {

void BuiltinVectorDictionaryFieldIntReset(std::vector<::tl2::DictionaryField<int32_t>>& item);

bool BuiltinVectorDictionaryFieldIntWriteJSON(std::ostream & s, const std::vector<::tl2::DictionaryField<int32_t>>& item);
bool BuiltinVectorDictionaryFieldIntRead(::basictl::tl_istream & s, std::vector<::tl2::DictionaryField<int32_t>>& item);
bool BuiltinVectorDictionaryFieldIntWrite(::basictl::tl_ostream & s, const std::vector<::tl2::DictionaryField<int32_t>>& item);

Expand All @@ -14,6 +16,8 @@ bool BuiltinVectorDictionaryFieldIntWrite(::basictl::tl_ostream & s, const std::
namespace tl2 { namespace details {

void DictionaryFieldIntReset(::tl2::DictionaryField<int32_t>& item);

bool DictionaryFieldIntWriteJSON(std::ostream& s, const ::tl2::DictionaryField<int32_t>& item);
bool DictionaryFieldIntRead(::basictl::tl_istream & s, ::tl2::DictionaryField<int32_t>& item);
bool DictionaryFieldIntWrite(::basictl::tl_ostream & s, const ::tl2::DictionaryField<int32_t>& item);
bool DictionaryFieldIntReadBoxed(::basictl::tl_istream & s, ::tl2::DictionaryField<int32_t>& item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace tl2 { namespace details {

void BuiltinVectorDictionaryFieldAnyDoubleIntReset(std::vector<::tl2::DictionaryFieldAny<double, int32_t>>& item);

bool BuiltinVectorDictionaryFieldAnyDoubleIntWriteJSON(std::ostream & s, const std::vector<::tl2::DictionaryFieldAny<double, int32_t>>& item);
bool BuiltinVectorDictionaryFieldAnyDoubleIntRead(::basictl::tl_istream & s, std::vector<::tl2::DictionaryFieldAny<double, int32_t>>& item);
bool BuiltinVectorDictionaryFieldAnyDoubleIntWrite(::basictl::tl_ostream & s, const std::vector<::tl2::DictionaryFieldAny<double, int32_t>>& item);

Expand All @@ -14,6 +16,8 @@ bool BuiltinVectorDictionaryFieldAnyDoubleIntWrite(::basictl::tl_ostream & s, co
namespace tl2 { namespace details {

void BuiltinVectorDictionaryFieldAnyIntIntReset(std::vector<::tl2::DictionaryFieldAny<int32_t, int32_t>>& item);

bool BuiltinVectorDictionaryFieldAnyIntIntWriteJSON(std::ostream & s, const std::vector<::tl2::DictionaryFieldAny<int32_t, int32_t>>& item);
bool BuiltinVectorDictionaryFieldAnyIntIntRead(::basictl::tl_istream & s, std::vector<::tl2::DictionaryFieldAny<int32_t, int32_t>>& item);
bool BuiltinVectorDictionaryFieldAnyIntIntWrite(::basictl::tl_ostream & s, const std::vector<::tl2::DictionaryFieldAny<int32_t, int32_t>>& item);

Expand All @@ -22,6 +26,8 @@ bool BuiltinVectorDictionaryFieldAnyIntIntWrite(::basictl::tl_ostream & s, const
namespace tl2 { namespace details {

void DictionaryFieldAnyDoubleIntReset(::tl2::DictionaryFieldAny<double, int32_t>& item);

bool DictionaryFieldAnyDoubleIntWriteJSON(std::ostream& s, const ::tl2::DictionaryFieldAny<double, int32_t>& item);
bool DictionaryFieldAnyDoubleIntRead(::basictl::tl_istream & s, ::tl2::DictionaryFieldAny<double, int32_t>& item);
bool DictionaryFieldAnyDoubleIntWrite(::basictl::tl_ostream & s, const ::tl2::DictionaryFieldAny<double, int32_t>& item);
bool DictionaryFieldAnyDoubleIntReadBoxed(::basictl::tl_istream & s, ::tl2::DictionaryFieldAny<double, int32_t>& item);
Expand All @@ -32,6 +38,8 @@ bool DictionaryFieldAnyDoubleIntWriteBoxed(::basictl::tl_ostream & s, const ::tl
namespace tl2 { namespace details {

void DictionaryFieldAnyIntIntReset(::tl2::DictionaryFieldAny<int32_t, int32_t>& item);

bool DictionaryFieldAnyIntIntWriteJSON(std::ostream& s, const ::tl2::DictionaryFieldAny<int32_t, int32_t>& item);
bool DictionaryFieldAnyIntIntRead(::basictl::tl_istream & s, ::tl2::DictionaryFieldAny<int32_t, int32_t>& item);
bool DictionaryFieldAnyIntIntWrite(::basictl::tl_ostream & s, const ::tl2::DictionaryFieldAny<int32_t, int32_t>& item);
bool DictionaryFieldAnyIntIntReadBoxed(::basictl::tl_istream & s, ::tl2::DictionaryFieldAny<int32_t, int32_t>& item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace tl2 { namespace details {

void IntReset(int32_t& item);

bool IntWriteJSON(std::ostream& s, const int32_t& item);
bool IntRead(::basictl::tl_istream & s, int32_t& item);
bool IntWrite(::basictl::tl_ostream & s, const int32_t& item);
bool IntReadBoxed(::basictl::tl_istream & s, int32_t& item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace tl2 { namespace details {

void Int32Reset(::tl2::Int32& item);

bool Int32WriteJSON(std::ostream& s, const ::tl2::Int32& item);
bool Int32Read(::basictl::tl_istream & s, ::tl2::Int32& item);
bool Int32Write(::basictl::tl_ostream & s, const ::tl2::Int32& item);
bool Int32ReadBoxed(::basictl::tl_istream & s, ::tl2::Int32& item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace tl2 { namespace details {

void Int64Reset(::tl2::Int64& item);

bool Int64WriteJSON(std::ostream& s, const ::tl2::Int64& item);
bool Int64Read(::basictl::tl_istream & s, ::tl2::Int64& item);
bool Int64Write(::basictl::tl_ostream & s, const ::tl2::Int64& item);
bool Int64ReadBoxed(::basictl::tl_istream & s, ::tl2::Int64& item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace tl2 { namespace details {

void LongReset(int64_t& item);

bool LongWriteJSON(std::ostream& s, const int64_t& item);
bool LongRead(::basictl::tl_istream & s, int64_t& item);
bool LongWrite(::basictl::tl_ostream & s, const int64_t& item);
bool LongReadBoxed(::basictl::tl_istream & s, int64_t& item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace tl2 { namespace details {

void StringReset(std::string& item);

bool StringWriteJSON(std::ostream& s, const std::string& item);
bool StringRead(::basictl::tl_istream & s, std::string& item);
bool StringWrite(::basictl::tl_ostream & s, const std::string& item);
bool StringReadBoxed(::basictl::tl_istream & s, std::string& item);
Expand Down
Loading

0 comments on commit a685b72

Please sign in to comment.