File tree Expand file tree Collapse file tree 7 files changed +37
-34
lines changed Expand file tree Collapse file tree 7 files changed +37
-34
lines changed Original file line number Diff line number Diff line change @@ -35,13 +35,16 @@ bool CollectionIterator::decode_value() {
35
35
data_type = collection_->primary_data_type ();
36
36
}
37
37
38
- return decoder_.decode_value (data_type, value_, true );
38
+ value_ = decoder_.decode_value (data_type);
39
+ return value_.is_valid ();
39
40
}
40
41
41
42
bool TupleIterator::next () {
42
43
if (next_ == end_) {
43
44
return false ;
44
45
}
45
46
current_ = next_++;
46
- return decoder_.decode_value (*current_, value_);
47
+
48
+ value_ = decoder_.decode_value (*current_);
49
+ return value_.is_valid ();
47
50
}
Original file line number Diff line number Diff line change @@ -138,33 +138,22 @@ bool Decoder::decode_warnings(WarningVec& output) {
138
138
return true ;
139
139
}
140
140
141
- bool Decoder::decode_value (const DataType::ConstPtr& data_type, Value& output,
142
- bool is_inside_collection /* = false*/ ) {
143
- const char * buffer = NULL ;
141
+ Value Decoder::decode_value (const DataType::ConstPtr& data_type) {
144
142
int32_t size = 0 ;
145
-
146
- if (!decode_int32 (size)) {
147
- return false ;
148
- }
143
+ if (!decode_int32 (size)) return Value ();
149
144
150
145
if (size >= 0 ) {
151
- buffer = input_;
146
+ Decoder decoder ( input_, size, protocol_version_) ;
152
147
input_ += size;
153
148
remaining_ -= size;
154
- Decoder decoder (buffer, size, protocol_version_);
155
-
156
- if (data_type->is_collection ()) {
157
- int32_t count;
158
- if (!decoder.decode_int32 (count)) return false ;
159
- output = Value (data_type, count, decoder);
160
- } else {
161
- output = Value (data_type, decoder);
149
+
150
+ int32_t count = 0 ;
151
+ if (data_type->is_collection () && !decoder.decode_int32 (count)) {
152
+ return Value ();
162
153
}
163
- } else { // null value
164
- output = Value (data_type);
154
+ return Value (data_type, count, decoder);
165
155
}
166
-
167
- return true ;
156
+ return Value (data_type);
168
157
}
169
158
170
159
void Decoder::notify_error (const char * detail, size_t bytes) const {
Original file line number Diff line number Diff line change @@ -558,8 +558,7 @@ class Decoder {
558
558
bool decode_write_type (CassWriteType& output);
559
559
bool decode_warnings (WarningVec& output);
560
560
561
- bool decode_value (const DataType::ConstPtr& data_type, Value& output,
562
- bool is_inside_collection = false );
561
+ Value decode_value (const DataType::ConstPtr& data_type);
563
562
564
563
protected:
565
564
// Testing only
Original file line number Diff line number Diff line change 19
19
using namespace datastax ::internal::core;
20
20
21
21
bool MapIterator::decode_pair () {
22
- if (!decoder_.decode_value (map_->primary_data_type (), key_, true )) return false ;
23
- return decoder_.decode_value (map_->secondary_data_type (), value_, true );
22
+ key_ = decoder_.decode_value (map_->primary_data_type ());
23
+ if (key_.data_type ()) {
24
+ value_ = decoder_.decode_value (map_->secondary_data_type ());
25
+ return value_.is_valid ();
26
+ }
27
+ return false ;
24
28
}
25
29
26
30
bool MapIterator::next () {
Original file line number Diff line number Diff line change @@ -51,14 +51,19 @@ namespace datastax { namespace internal { namespace core {
51
51
52
52
bool decode_row (Decoder& decoder, const ResultResponse* result, OutputValueVec& output) {
53
53
output.clear ();
54
- output.reserve (result->column_count ());
55
- for (int i = 0 ; i < result->column_count (); ++i) {
56
- Value value;
57
- const ColumnDefinition& def = result->metadata ()->get_column_definition (i);
58
- CHECK_RESULT (decoder.decode_value (def.data_type , value));
59
- output.push_back (value);
54
+ const int column_count = result->column_count ();
55
+ if (column_count > 0 ) {
56
+ output.reserve (column_count);
57
+ const SharedRefPtr<ResultMetadata>& metadata = result->metadata ();
58
+ for (int i = 0 ; i < column_count; ++i) {
59
+ const ColumnDefinition& def = metadata->get_column_definition (i);
60
+ Value value = decoder.decode_value (def.data_type );
61
+ if (value.is_valid ()) {
62
+ output.push_back (value);
63
+ } else
64
+ return false ;
65
+ }
60
66
}
61
-
62
67
return true ;
63
68
}
64
69
Original file line number Diff line number Diff line change @@ -25,5 +25,6 @@ bool UserTypeFieldIterator::next() {
25
25
return false ;
26
26
}
27
27
current_ = next_++;
28
- return decoder_.decode_value (current_->type , value_);
28
+ value_ = decoder_.decode_value (current_->type );
29
+ return value_.is_valid ();
29
30
}
Original file line number Diff line number Diff line change @@ -51,6 +51,8 @@ class Value {
51
51
ProtocolVersion protocol_version () const { return decoder_.protocol_version (); }
52
52
int64_t size () const { return (is_null_ ? -1 : decoder_.remaining ()); }
53
53
54
+ bool is_valid () const { return !!data_type_; }
55
+
54
56
CassValueType value_type () const {
55
57
if (!data_type_) {
56
58
return CASS_VALUE_TYPE_UNKNOWN;
You can’t perform that action at this time.
0 commit comments