@@ -35,17 +35,17 @@ class Writer {
3535 ~Writer () = default ;
3636
3737 OutputArrayType array_as_root (const size_t _size) const {
38- *ar_ << static_cast <std:: uint64_t > (_size);
38+ write_size (_size);
3939 return OutputArrayType{};
4040 }
4141
4242 OutputMapType map_as_root (const size_t _size) const {
43- *ar_ << static_cast <std:: uint64_t > (_size);
43+ write_size (_size);
4444 return OutputMapType{};
4545 }
4646
4747 OutputObjectType object_as_root (const size_t _size) const {
48- *ar_ << static_cast <std:: uint64_t > (_size);
48+ write_size (_size);
4949 return OutputObjectType{};
5050 }
5151
@@ -61,85 +61,85 @@ class Writer {
6161
6262 OutputArrayType add_array_to_array (const size_t _size,
6363 OutputArrayType* /* _parent*/ ) const {
64- *ar_ << static_cast <std:: uint64_t > (_size);
64+ write_size (_size);
6565 return OutputArrayType{};
6666 }
6767
6868 OutputArrayType add_array_to_map (const std::string_view& _name,
6969 const size_t _size,
7070 OutputMapType* /* _parent*/ ) const {
71- *ar_ << std::string (_name);
72- *ar_ << static_cast <std:: uint64_t > (_size);
71+ write_key (_name);
72+ write_size (_size);
7373 return OutputArrayType{};
7474 }
7575
7676 OutputArrayType add_array_to_object (const std::string_view& /* _name*/ ,
7777 const size_t _size,
7878 OutputObjectType* /* _parent*/ ) const {
79- *ar_ << static_cast <std:: uint64_t > (_size);
79+ write_size (_size);
8080 return OutputArrayType{};
8181 }
8282
8383 OutputArrayType add_array_to_union (const size_t _index, const size_t _size,
8484 OutputUnionType* /* _parent*/ ) const {
85- *ar_ << static_cast <std:: uint64_t > (_index);
86- *ar_ << static_cast <std:: uint64_t > (_size);
85+ write_index (_index);
86+ write_size (_size);
8787 return OutputArrayType{};
8888 }
8989
9090 OutputMapType add_map_to_array (const size_t _size,
9191 OutputArrayType* /* _parent*/ ) const {
92- *ar_ << static_cast <std:: uint64_t > (_size);
92+ write_size (_size);
9393 return OutputMapType{};
9494 }
9595
9696 OutputMapType add_map_to_map (const std::string_view& _name,
9797 const size_t _size,
9898 OutputMapType* /* _parent*/ ) const {
99- *ar_ << std::string (_name);
100- *ar_ << static_cast <std:: uint64_t > (_size);
99+ write_key (_name);
100+ write_size (_size);
101101 return OutputMapType{};
102102 }
103103
104104 OutputMapType add_map_to_object (const std::string_view& /* _name*/ ,
105105 const size_t _size,
106106 OutputObjectType* /* _parent*/ ) const {
107- *ar_ << static_cast <std:: uint64_t > (_size);
107+ write_size (_size);
108108 return OutputMapType{};
109109 }
110110
111111 OutputMapType add_map_to_union (const size_t _index, const size_t _size,
112112 OutputUnionType* /* _parent*/ ) const {
113- *ar_ << static_cast <std:: uint64_t > (_index);
114- *ar_ << static_cast <std:: uint64_t > (_size);
113+ write_index (_index);
114+ write_size (_size);
115115 return OutputMapType{};
116116 }
117117
118118 OutputObjectType add_object_to_array (const size_t _size,
119119 OutputArrayType* /* _parent*/ ) const {
120- *ar_ << static_cast <std:: uint64_t > (_size);
120+ write_size (_size);
121121 return OutputObjectType{};
122122 }
123123
124124 OutputObjectType add_object_to_map (const std::string_view& _name,
125125 const size_t _size,
126126 OutputMapType* /* _parent*/ ) const {
127- *ar_ << std::string (_name);
128- *ar_ << static_cast <std:: uint64_t > (_size);
127+ write_key (_name);
128+ write_size (_size);
129129 return OutputObjectType{};
130130 }
131131
132132 OutputObjectType add_object_to_object (const std::string_view& /* _name*/ ,
133133 const size_t _size,
134134 OutputObjectType* /* _parent*/ ) const {
135- *ar_ << static_cast <std:: uint64_t > (_size);
135+ write_size (_size);
136136 return OutputObjectType{};
137137 }
138138
139139 OutputObjectType add_object_to_union (const size_t _index, const size_t _size,
140140 OutputUnionType* /* _parent*/ ) const {
141- *ar_ << static_cast <std:: uint64_t > (_index);
142- *ar_ << static_cast <std:: uint64_t > (_size);
141+ write_index (_index);
142+ write_size (_size);
143143 return OutputObjectType{};
144144 }
145145
@@ -149,7 +149,7 @@ class Writer {
149149
150150 OutputUnionType add_union_to_map (const std::string_view& _name,
151151 OutputMapType* /* _parent*/ ) const {
152- *ar_ << std::string (_name);
152+ write_key (_name);
153153 return OutputUnionType{};
154154 }
155155
@@ -160,7 +160,7 @@ class Writer {
160160
161161 OutputUnionType add_union_to_union (const size_t _index,
162162 OutputUnionType* /* _parent*/ ) const {
163- *ar_ << static_cast <std:: uint64_t > (_index);
163+ write_index (_index);
164164 return OutputUnionType{};
165165 }
166166
@@ -174,7 +174,7 @@ class Writer {
174174 template <class T >
175175 OutputVarType add_value_to_map (const std::string_view& _name, const T& _var,
176176 OutputMapType* /* _parent*/ ) const {
177- *ar_ << std::string (_name);
177+ write_key (_name);
178178 new_value (_var);
179179 return OutputVarType{};
180180 }
@@ -190,7 +190,7 @@ class Writer {
190190 template <class T >
191191 OutputVarType add_value_to_union (const size_t _index, const T& _var,
192192 OutputUnionType* /* _parent*/ ) const {
193- *ar_ << static_cast <std:: uint64_t > (_index);
193+ write_index (_index);
194194 new_value (_var);
195195 return OutputVarType{};
196196 }
@@ -201,7 +201,7 @@ class Writer {
201201
202202 OutputVarType add_null_to_map (const std::string_view& _name,
203203 OutputMapType* /* _parent*/ ) const {
204- *ar_ << std::string (_name);
204+ write_key (_name);
205205 return OutputVarType{};
206206 }
207207
@@ -212,7 +212,7 @@ class Writer {
212212
213213 OutputVarType add_null_to_union (const size_t _index,
214214 OutputUnionType* /* _parent*/ ) const {
215- *ar_ << static_cast <std:: uint64_t > (_index);
215+ write_index (_index);
216216 return OutputVarType{};
217217 }
218218
@@ -223,6 +223,18 @@ class Writer {
223223 void end_object (OutputObjectType* /* _obj*/ ) const {}
224224
225225 private:
226+ void write_size (const size_t _size) const {
227+ *ar_ << static_cast <std::uint64_t >(_size);
228+ }
229+
230+ void write_index (const size_t _index) const {
231+ *ar_ << static_cast <std::uint64_t >(_index);
232+ }
233+
234+ void write_key (const std::string_view& _name) const {
235+ *ar_ << std::string (_name);
236+ }
237+
226238 template <class T >
227239 void new_value (const T& _var) const {
228240 using Type = std::remove_cvref_t <T>;
0 commit comments