Defines how a value of type V is serialized to and from Uint8List.
Required by DiskCache and SecureCache, which need a binary
representation of values to write to disk or encrypt in memory.
Implement this for your own model types:
class UserCodec implements CacheCodec<User> {
const UserCodec();
@override
Uint8List encode(User value) {
final json = jsonEncode(value.toJson());
return Uint8List.fromList(utf8.encode(json));
}
@override
User decode(Uint8List bytes) {
final json = utf8.decode(bytes);
return User.fromJson(jsonDecode(json) as Map<String, dynamic>);
}
}
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
decode(
Uint8List bytes) → V -
Decodes
bytesback into a value of typeV. -
encode(
V value) → Uint8List -
Encodes
valueinto bytes. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited