diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d7c982..820d62e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 2.8) set(PROTOGEN_MAJOR 2) set(PROTOGEN_MINOR 0) -set(PROTOGEN_PATCH 0) +set(PROTOGEN_PATCH 1) add_definitions(-DPROTOGEN_MAJOR=${PROTOGEN_MAJOR}) add_definitions(-DPROTOGEN_MINOR=${PROTOGEN_MINOR}) diff --git a/README.md b/README.md index edbbe5d..4d7b11c 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ PG_JSON(MyData, name, age, pets) Now it's possible to serialize and deserialize the type using the functions ``serialize`` and ``deserialize``. ```c++ -using protogen_2_0_0; +using protogen_2_0_1; MyData obj; obj.name = "Margot"; @@ -113,7 +113,7 @@ Types generated by protogen compiler contain helper functions like ``serialize`` These options can be set in the proto3 file: * **obfuscate_strings** (top-level) – Enable string obfuscation. If enabled, all strings in the C++ generated file will be obfuscated with a very simple (and insecure) algorithm. The default value is `false`. This option can be used to make a little difficult for curious people to find out your JSON field names by inspecting binary files. -* **number_names** (top-level) – Use field numbers as JSON field names. The default value is `false`. If enabled, every JSON field name will be the number of the corresponding field in the `.proto` file. This can reduce significantly the size of the JSON output. +* **number_names** (top-level) – Use field numbers as JSON field names. The default value is `false`. If enabled, every JSON field name will be the number of the corresponding field in the `.proto` file. This can significantly reduce the size of the JSON output. * **transient** (field-level) – Make the field transient (`true`) or not (`false`). Transient fields are not serialized/deserialized. The default value is `false`. * **cpp_use_lists** (top-level) – Use `std::list` (`true`) instead of `std::vector` (`false`) in repeated fields. This gives best performance if your program constantly changes repeated fields (add and/or remove items). This option does not affect `bytes` fields which always use `std::vector`. The default value is `false`. diff --git a/compiler/cpp/code.txt b/compiler/cpp/code.txt index ed8a40b..5ac74c5 100644 --- a/compiler/cpp/code.txt +++ b/compiler/cpp/code.txt @@ -51,7 +51,7 @@ --- CODE_JSON_MODEL -namespace protogen_2_0_0 { +namespace protogen_2_0_1 { template<> struct json<$1$> { static int read( json_context &ctx, $1$ &value ) { return read_object(ctx, value); } @@ -118,9 +118,9 @@ $8$ return false; ------ --- CODE_ENTITY -PG_ENTITY($1$,$2$,protogen_2_0_0::json<$2$>) +PG_ENTITY($1$,$2$,protogen_2_0_1::json<$2$>) ------ --- CODE_ENTITY_JSON -PG_ENTITY_SERIALIZER($1$,$2$,protogen_2_0_0::json<$2$>) +PG_ENTITY_SERIALIZER($1$,$2$,protogen_2_0_1::json<$2$>) ------ diff --git a/protogen.hh b/protogen.hh index f596b79..3388f3a 100644 --- a/protogen.hh +++ b/protogen.hh @@ -1,5 +1,5 @@ -#ifndef PROTOGEN_2_0_0 -#define PROTOGEN_2_0_0 +#ifndef PROTOGEN_2_0_1 +#define PROTOGEN_2_0_1 #include #include @@ -11,7 +11,7 @@ #define PG_MKSTR(...) #__VA_ARGS__ -namespace protogen_2_0_0 { +namespace protogen_2_0_1 { enum error_code { @@ -466,7 +466,7 @@ class mem_iterator } // namespace internal -using namespace protogen_2_0_0::internal; +using namespace protogen_2_0_1::internal; template struct is_container : std::false_type {}; @@ -969,7 +969,7 @@ static int read_object( json_context &ctx, T &object ) #define PG_DIF_EX(field_id, field_name, field_label) \ if (name == field_label) { \ - int result = protogen_2_0_0::json::read(ctx, value.field_name); \ + int result = protogen_2_0_1::json::read(ctx, value.field_name); \ if (result == PGR_OK) ctx.mask |= (1 << field_id); \ return result; \ } else @@ -978,34 +978,34 @@ static int read_object( json_context &ctx, T &object ) PG_DIF_EX(field_id, field_name, PG_MKSTR(field_name) ) #define PG_SIF_EX(field_name, field_label) \ - if (!protogen_2_0_0::json::empty(value.field_name)) \ + if (!protogen_2_0_1::json::empty(value.field_name)) \ { \ if (!first) (*ctx.os) << ','; \ first = false; \ (*ctx.os) << '\"' << field_label << "\":"; \ - protogen_2_0_0::json::write(ctx, value.field_name); \ + protogen_2_0_1::json::write(ctx, value.field_name); \ } #define PG_SIF(field_name,user_data,field_id) \ PG_SIF_EX(field_name, PG_MKSTR(field_name) ) #define PG_EIF(field_name,user_data,field_id) \ - if (!protogen_2_0_0::json::empty(value.field_name)) return false; + if (!protogen_2_0_1::json::empty(value.field_name)) return false; #define PG_CLL(field_name,user_data,field_id) \ - protogen_2_0_0::json::clear(value.field_name); + protogen_2_0_1::json::clear(value.field_name); #define PG_QIF(field_name,user_data,field_id) \ - if (!protogen_2_0_0::json::equal(a.field_name, b.field_name)) return false; + if (!protogen_2_0_1::json::equal(a.field_name, b.field_name)) return false; #define PG_SLL(field_name,user_data,field_id) \ - protogen_2_0_0::json::swap(a.field_name, b.field_name); + protogen_2_0_1::json::swap(a.field_name, b.field_name); #define PG_MIF(field_name,user_data,field_id) \ if (!(ctx.mask & (1 << field_id))) { name = PG_MKSTR(field_name); } else #define PG_JSON(type, ...) \ - namespace protogen_2_0_0 { \ + namespace protogen_2_0_1 { \ template<> \ struct json \ { \ @@ -1053,7 +1053,7 @@ static int read_object( json_context &ctx, T &object ) };} template -bool deserialize( T &value, protogen_2_0_0::tokenizer& tok, bool required = false, ErrorInfo *err = nullptr ) +bool deserialize( T &value, protogen_2_0_1::tokenizer& tok, bool required = false, ErrorInfo *err = nullptr ) { json_context ctx; ctx.tok = &tok; @@ -1141,10 +1141,10 @@ void serialize( const T &value, std::ostream &out ) serialize(value, os); } -template> +template> void clear( T &value ) { json::clear(value); } -template> +template> bool empty( const T &value ) { return json::empty(value); } // parent class for messages @@ -1218,31 +1218,31 @@ struct message }; #define PG_ENTITY(N,O,S) \ - struct N : public O, public protogen_2_0_0::message< O, S > \ + struct N : public O, public protogen_2_0_1::message< O, S > \ { \ typedef O value_type; \ typedef S serializer_type; \ - typedef protogen_2_0_0::ErrorInfo ErrorInfo; \ + typedef protogen_2_0_1::ErrorInfo ErrorInfo; \ N() = default; \ N( const N& ) = default; \ N( N &&that ) { S::swap(*this, that); } \ N &operator=( const N & ) = default; \ - using protogen_2_0_0::message::serialize; \ - using protogen_2_0_0::message::deserialize; \ - bool deserialize( protogen_2_0_0::tokenizer& tok, bool required = false, \ - protogen_2_0_0::ErrorInfo *err = nullptr ) override \ + using protogen_2_0_1::message::serialize; \ + using protogen_2_0_1::message::deserialize; \ + bool deserialize( protogen_2_0_1::tokenizer& tok, bool required = false, \ + protogen_2_0_1::ErrorInfo *err = nullptr ) override \ { \ - protogen_2_0_0::json_context ctx; \ + protogen_2_0_1::json_context ctx; \ ctx.tok = &tok; \ ctx.required = required; \ int result = S::read(ctx, *this); \ - if (result == protogen_2_0_0::PGR_OK) return true; \ + if (result == protogen_2_0_1::PGR_OK) return true; \ if (err != nullptr) *err = tok.error(); \ return false; \ } \ - void serialize( protogen_2_0_0::ostream &out ) const override \ + void serialize( protogen_2_0_1::ostream &out ) const override \ { \ - protogen_2_0_0::json_context ctx; \ + protogen_2_0_1::json_context ctx; \ ctx.os = &out; \ S::write(ctx, *this); \ } \ @@ -1253,7 +1253,7 @@ struct message }; #define PG_ENTITY_SERIALIZER(N,O,S) \ - namespace protogen_2_0_0 { \ + namespace protogen_2_0_1 { \ template<> \ struct json \ { \ @@ -1267,7 +1267,7 @@ struct message static bool is_missing( json_context &ctx ) { return S::is_missing(ctx); } \ };} -} // namespace protogen_2_0_0 +} // namespace protogen_2_0_1 -#endif // PROTOGEN_2_0_0 +#endif // PROTOGEN_2_0_1 diff --git a/tests/tests.cc b/tests/tests.cc index bafbca6..95de9a4 100644 --- a/tests/tests.cc +++ b/tests/tests.cc @@ -26,7 +26,7 @@ struct Person PG_JSON(compact::Person, name, age, gender, email, friends) -using namespace protogen_2_0_0; +using namespace protogen_2_0_1; bool RUN_TEST1( int argc, char **argv) {