Skip to content

Commit bec2330

Browse files
Add dedicated function for string vieww
1 parent 4648aab commit bec2330

2 files changed

Lines changed: 27 additions & 32 deletions

File tree

include/rfl/yas/Writer.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,8 @@ struct Writer {
129129
return OutputObjectType{_parent->ar};
130130
}
131131

132-
OutputObjectType add_object_to_union(
133-
const size_t _index, const size_t _size,
134-
OutputUnionType* _parent) const noexcept;
132+
OutputObjectType add_object_to_union(const size_t _index, const size_t _size,
133+
OutputUnionType* _parent) const noexcept;
135134

136135
OutputUnionType add_union_to_array(OutputArrayType* _parent) const noexcept {
137136
return OutputUnionType{_parent->ar};
@@ -202,7 +201,8 @@ struct Writer {
202201
void end_object(OutputObjectType* /*_obj*/) const noexcept {}
203202

204203
void add_string_view(const std::string_view& _str) const {
205-
(*ar_) & std::string(_str);
204+
ar_->write_seq_size(_str.length());
205+
ar_->write(_str.data(), _str.length());
206206
}
207207

208208
template <class T>

src/rfl/yas/Writer.cpp

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,59 +28,55 @@ SOFTWARE.
2828

2929
namespace rfl::yas {
3030

31-
Writer::OutputArrayType Writer::add_array_to_map(const std::string_view& _name,
32-
const size_t _size,
33-
OutputMapType* _parent) const
34-
noexcept {
35-
(*_parent->ar) & std::string(_name);
31+
Writer::OutputArrayType Writer::add_array_to_map(
32+
const std::string_view& _name, const size_t _size,
33+
OutputMapType* _parent) const noexcept {
34+
add_string_view(_name);
3635
(*_parent->ar) & _size;
3736
return OutputArrayType{_parent->ar};
3837
}
3938

4039
Writer::OutputArrayType Writer::add_array_to_union(
41-
const size_t _index, const size_t _size, OutputUnionType* _parent) const
42-
noexcept {
40+
const size_t _index, const size_t _size,
41+
OutputUnionType* _parent) const noexcept {
4342
(*_parent->ar) & _index;
4443
(*_parent->ar) & _size;
4544
return OutputArrayType{_parent->ar};
4645
}
4746

48-
Writer::OutputMapType Writer::add_map_to_map(const std::string_view& _name,
49-
const size_t _size,
50-
OutputMapType* _parent) const
51-
noexcept {
52-
(*_parent->ar) & std::string(_name);
47+
Writer::OutputMapType Writer::add_map_to_map(
48+
const std::string_view& _name, const size_t _size,
49+
OutputMapType* _parent) const noexcept {
50+
add_string_view(_name);
5351
(*_parent->ar) & _size;
5452
return OutputMapType{_parent->ar};
5553
}
5654

57-
Writer::OutputMapType Writer::add_map_to_union(const size_t _index,
58-
const size_t _size,
59-
OutputUnionType* _parent) const
60-
noexcept {
55+
Writer::OutputMapType Writer::add_map_to_union(
56+
const size_t _index, const size_t _size,
57+
OutputUnionType* _parent) const noexcept {
6158
(*_parent->ar) & _index;
6259
(*_parent->ar) & _size;
6360
return OutputMapType{_parent->ar};
6461
}
6562

6663
Writer::OutputObjectType Writer::add_object_to_map(
67-
const std::string_view& _name, const size_t, OutputMapType* _parent) const
68-
noexcept {
69-
(*_parent->ar) & std::string(_name);
64+
const std::string_view& _name, const size_t,
65+
OutputMapType* _parent) const noexcept {
66+
add_string_view(_name);
7067
return OutputObjectType{_parent->ar};
7168
}
7269

7370
Writer::OutputObjectType Writer::add_object_to_union(
74-
const size_t _index, const size_t, OutputUnionType* _parent) const
75-
noexcept {
71+
const size_t _index, const size_t,
72+
OutputUnionType* _parent) const noexcept {
7673
(*_parent->ar) & _index;
7774
return OutputObjectType{_parent->ar};
7875
}
7976

80-
Writer::OutputUnionType Writer::add_union_to_map(const std::string_view& _name,
81-
OutputMapType* _parent) const
82-
noexcept {
83-
(*_parent->ar) & std::string(_name);
77+
Writer::OutputUnionType Writer::add_union_to_map(
78+
const std::string_view& _name, OutputMapType* _parent) const noexcept {
79+
add_string_view(_name);
8480
return OutputUnionType{_parent->ar};
8581
}
8682

@@ -90,9 +86,8 @@ Writer::OutputUnionType Writer::add_union_to_union(
9086
return OutputUnionType{_parent->ar};
9187
}
9288

93-
Writer::OutputVarType Writer::add_null_to_union(const size_t _index,
94-
OutputUnionType* _parent) const
95-
noexcept {
89+
Writer::OutputVarType Writer::add_null_to_union(
90+
const size_t _index, OutputUnionType* _parent) const noexcept {
9691
(*_parent->ar) & _index;
9792
return OutputVarType{};
9893
}

0 commit comments

Comments
 (0)