BulkReply class
Used for bulk replies
class BulkReply extends RedisReply {
final _OneLineDataConsumer _initialLineDataConsumer = new _OneLineDataConsumer();
_BytesDataConsumer _dataConsumer;
/// The length of this bulk reply
int byteLength;
/**
* Specifies if this reply has been fully received.
*/
bool get done {
if (byteLength == -1) return true;
if (_dataConsumer == null) return false;
else return _dataConsumer.done;
}
/**
* Consumes the first line with an [_OneLineDataConsumer], retrieves the
* byteLength from it, and consumes the rest of the data with a
* [_BytesDataConsumer].
*/
@override
List<int> _consumeData(List<int> data) {
if (!_initialLineDataConsumer.done) {
_initialLineDataConsumer.consumeData(data);
// Can be null
data = _initialLineDataConsumer.unconsumedData;
if (_initialLineDataConsumer.done) {
byteLength = int.parse(new String.fromCharCodes(_initialLineDataConsumer.data));
if (byteLength == -1) {
// Null response
return data;
}
}
if (data == null) {
// Stop here.
return null;
}
}
// The initialLineConsumer has done it's job the last time or this time.
// Either way, now it's time for the _dataConsumer to do it's job.
if (_dataConsumer == null) {
// Need to create the data consumer
_dataConsumer = new _BytesDataConsumer(byteLength);
}
_dataConsumer.consumeData(data);
if (_dataConsumer.done && _dataConsumer.unconsumedData != null) {
return _dataConsumer.unconsumedData;
}
else {
return null;
}
}
/// Returns the raw bytes of this reply. Can be null.
List<int> get bytes {
if (byteLength == -1) return null;
assert(_dataConsumer != null);
// [_DataConsumer.data] checks if this reply is [done] and fails if not.
return _dataConsumer.data;
}
String _dataAsString;
/// Returns the reply as String. Can be null.
String get string {
if (byteLength == -1) return null;
if (_dataAsString == null) {
_dataAsString = decodeUtf8(bytes);
}
return _dataAsString;
}
}
Extends
RedisReply > BulkReply
Properties
int byteLength #
The length of this bulk reply
int byteLength
final List<int> bytes #
Returns the raw bytes of this reply. Can be null.
List<int> get bytes {
if (byteLength == -1) return null;
assert(_dataConsumer != null);
// [_DataConsumer.data] checks if this reply is [done] and fails if not.
return _dataConsumer.data;
}
final bool done #
Specifies if this reply has been fully received.
bool get done {
if (byteLength == -1) return true;
if (_dataConsumer == null) return false;
else return _dataConsumer.done;
}
final String string #
Returns the reply as String. Can be null.
String get string {
if (byteLength == -1) return null;
if (_dataAsString == null) {
_dataAsString = decodeUtf8(bytes);
}
return _dataAsString;
}