Skip to content

Commit

Permalink
specify types | add Consumer typedef
Browse files Browse the repository at this point in the history
  • Loading branch information
erf authored and ra1u committed Jul 14, 2021
1 parent cb680f9 commit c622322
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class RedisConnection {
}

// ignore: unused_element
Future _sendraw(List data) {
_socket!.add(data as List<int>);
Future _sendraw(List<int> data) {
_socket!.add(data);
return _senddummy();
}

Expand Down
2 changes: 2 additions & 0 deletions lib/redis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import 'dart:async';
import 'dart:convert';
import 'dart:collection';

import 'dart:typed_data';

part './redisserialise.dart';
part './connection.dart';
part './lazystream.dart';
Expand Down
12 changes: 6 additions & 6 deletions lib/redisserialise.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class RedisBulk {
RedisBulk(this.iterable) {}
}

typedef Consumer = void Function(Iterable<int> s);

class RedisSerialise {
static final ASCII = const AsciiCodec();
static final UTF8 = const Utf8Codec();
Expand All @@ -28,15 +30,13 @@ class RedisSerialise {
static final _linesep = ASCII.encode("\r\n");
static final _dollarminus1 = ASCII.encode("\$-1");

static List<int> Serialise(object) {
var s = <int>[];
SerialiseConsumable(object, (v) {
s.addAll(v as Iterable<int>);
});
static List<int> Serialise(Object? object) {
final s = <int>[];
SerialiseConsumable(object, (v) => s.addAll(v));
return s;
}

static void SerialiseConsumable(object, void consumer(Iterable s)) {
static void SerialiseConsumable(Object? object, Consumer consumer) {
if (object is String) {
var data = UTF8.encode(object);
consumer(_dollar);
Expand Down

0 comments on commit c622322

Please sign in to comment.