Dart Documentationredis_protocol_transformerMultiBulkReply

MultiBulkReply class

This class differs a bit from the oder RedisReplies in that it actually holds a list of mulitple RedisReplys.

class MultiBulkReply extends RedisReply {

 final _OneLineDataConsumer _initialLineDataConsumer = new _OneLineDataConsumer();

 /// The number of replies this multi bulk reply returns.
 int _numberOfReplies;

 /// Returns true if all replies have successfully been returned.
 bool get done {
   // Not even the inital first line has been received.
   if (_numberOfReplies == null) return false;

   if (_numberOfReplies == 0) return true;

   // Not all replies have been received.
   if (_replies.length != _numberOfReplies) return false;

   // If the last reply is done, the [MultiBulkReply] is done.
   return _replies.last.done;
 }


 /// Holds the list of [RedisReply]s.
 List<RedisReply> _replies = <RedisReply>[ ];

 List<RedisReply> get replies {
   return _replies;
 }

 RedisReply get _lastReply => _replies.length > 0 ? _replies.last : null;

 /**
  * Consumes the first line with an [_OneLineDataConsumer], retrieves the
  * number of replies from it.
  */
 @override
 List<int> _consumeData(List<int> data) {

   if (!_initialLineDataConsumer.done) {
     _initialLineDataConsumer.consumeData(data);

     // Can be null
     data = _initialLineDataConsumer.unconsumedData;

     if (_initialLineDataConsumer.done) {
       _numberOfReplies = int.parse(new String.fromCharCodes(_initialLineDataConsumer.data));
     }

     if (data == null || done) {
       // Stop here.
       return data;
     }
   }

   // The initialLineConsumer has done it's job the last time or this time.
   // Now all replies have to be received.

   var lastReply = _lastReply;

   if (lastReply == null || lastReply.done) {
     // Need to create a new reply
     lastReply = new RedisReply.fromType(data.first);
     _replies.add(lastReply);
   }

   var unconsumedData = lastReply._consumeData(data);

   if (lastReply.done) {
     if (_replies.length == _numberOfReplies) {
       // All replies have been received.
       return unconsumedData;
     }
     else {
       _consumeData(unconsumedData);
     }
   }

   // Since the last reply is not done, there can't be any unconsumed data.
   return null;
 }

}

Extends

RedisReply > MultiBulkReply

Properties

final bool done #

Returns true if all replies have successfully been returned.

bool get done {
 // Not even the inital first line has been received.
 if (_numberOfReplies == null) return false;

 if (_numberOfReplies == 0) return true;

 // Not all replies have been received.
 if (_replies.length != _numberOfReplies) return false;

 // If the last reply is done, the [MultiBulkReply] is done.
 return _replies.last.done;
}

final List<RedisReply> replies #

List<RedisReply> get replies {
 return _replies;
}