File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,13 +35,16 @@ bool CollectionIterator::decode_value() {
3535 data_type = collection_->primary_data_type ();
3636 }
3737
38- return decoder_.decode_value (data_type, value_, true );
38+ value_ = decoder_.decode_value (data_type);
39+ return value_.is_valid ();
3940}
4041
4142bool TupleIterator::next () {
4243 if (next_ == end_) {
4344 return false ;
4445 }
4546 current_ = next_++;
46- return decoder_.decode_value (*current_, value_);
47+
48+ value_ = decoder_.decode_value (*current_);
49+ return value_.is_valid ();
4750}
Original file line number Diff line number Diff line change @@ -138,33 +138,22 @@ bool Decoder::decode_warnings(WarningVec& output) {
138138 return true ;
139139}
140140
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) {
144142 int32_t size = 0 ;
145-
146- if (!decode_int32 (size)) {
147- return false ;
148- }
143+ if (!decode_int32 (size)) return Value ();
149144
150145 if (size >= 0 ) {
151- buffer = input_;
146+ Decoder decoder ( input_, size, protocol_version_) ;
152147 input_ += size;
153148 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 ();
162153 }
163- } else { // null value
164- output = Value (data_type);
154+ return Value (data_type, count, decoder);
165155 }
166-
167- return true ;
156+ return Value (data_type);
168157}
169158
170159void 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 {
558558 bool decode_write_type (CassWriteType& output);
559559 bool decode_warnings (WarningVec& output);
560560
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);
563562
564563protected:
565564 // Testing only
Original file line number Diff line number Diff line change 1919using namespace datastax ::internal::core;
2020
2121bool 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 ;
2428}
2529
2630bool MapIterator::next () {
Original file line number Diff line number Diff line change @@ -51,14 +51,19 @@ namespace datastax { namespace internal { namespace core {
5151
5252bool decode_row (Decoder& decoder, const ResultResponse* result, OutputValueVec& output) {
5353 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+ }
6066 }
61-
6267 return true ;
6368}
6469
Original file line number Diff line number Diff line change @@ -25,5 +25,6 @@ bool UserTypeFieldIterator::next() {
2525 return false ;
2626 }
2727 current_ = next_++;
28- return decoder_.decode_value (current_->type , value_);
28+ value_ = decoder_.decode_value (current_->type );
29+ return value_.is_valid ();
2930}
Original file line number Diff line number Diff line change @@ -51,6 +51,8 @@ class Value {
5151 ProtocolVersion protocol_version () const { return decoder_.protocol_version (); }
5252 int64_t size () const { return (is_null_ ? -1 : decoder_.remaining ()); }
5353
54+ bool is_valid () const { return !!data_type_; }
55+
5456 CassValueType value_type () const {
5557 if (!data_type_) {
5658 return CASS_VALUE_TYPE_UNKNOWN;
You can’t perform that action at this time.
0 commit comments