Skip to content

Commit

Permalink
Revert asynchronous encode/decode method signatures (for now).
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos committed Sep 3, 2024
1 parent d524d00 commit db49d6f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
7 changes: 3 additions & 4 deletions lib/src/types/type_codec.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dart:async';
import 'dart:collection';
import 'dart:convert';
import 'dart:typed_data';
Expand All @@ -11,7 +10,7 @@ import 'type_registry.dart';
/// Encodes the [input] value and returns an [EncodedValue] object.
///
/// May return `null` if the codec is not able to encode the [input].
typedef TypeEncoderFn = FutureOr<EncodedValue?> Function(
typedef TypeEncoderFn = EncodedValue? Function(
TypeCodecContext context, Object? input);

/// Encoder and decoder for a given type (OID).
Expand Down Expand Up @@ -42,12 +41,12 @@ abstract class TypeCodec {
/// Encodes the [input] value and returns an [EncodedValue] object.
///
/// May return `null` if the codec is not able to encode the [input].
FutureOr<EncodedValue?> encode(TypeCodecContext context, Object? input);
EncodedValue? encode(TypeCodecContext context, Object? input);

/// Decodes the [input] value and returns a Dart value object.
///
/// May return [UndecodedBytes] if the codec is not able to decode the [input].
FutureOr<Object?> decode(TypeCodecContext context, EncodedValue input);
Object? decode(TypeCodecContext context, EncodedValue input);
}

/// The read-only, passive view of the Postgresql's runtime/session parameters.
Expand Down
15 changes: 7 additions & 8 deletions lib/src/types/type_registry.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dart:async';
import 'dart:typed_data';

import 'package:buffer/buffer.dart';
Expand Down Expand Up @@ -280,10 +279,10 @@ extension TypeRegistryExt on TypeRegistry {

Type? resolveSubstitution(String name) => _bySubstitutionName[name];

FutureOr<EncodedValue?> encodeValue({
EncodedValue? encodeValue({
required TypeCodecContext context,
required TypedValue typedValue,
}) async {
}) {
final type = typedValue.type;
final value = typedValue.value;
final oid = type.oid;
Expand All @@ -292,10 +291,10 @@ extension TypeRegistryExt on TypeRegistry {
if (!codec.encodesNull && value == null) {
return null;
}
return await codec.encode(context, value);
return codec.encode(context, value);
} else {
for (final encoder in _genericTypeEncoders) {
final encoded = await encoder(context, value);
final encoded = encoder(context, value);
if (encoded != null) {
return encoded;
}
Expand All @@ -304,19 +303,19 @@ extension TypeRegistryExt on TypeRegistry {
throw PgException("Could not infer type of value '$value'.");
}

FutureOr<Object?> decodeBytes(
Object? decodeBytes(
Uint8List? bytes, {
required TypeCodecContext context,
required int typeOid,
required bool isBinary,
}) async {
}) {
final codec = _codecs[typeOid];
if (codec != null) {
if (!codec.decodesNull && bytes == null) {
return null;
}
final value = EncodedValue(bytes: bytes, isBinary: isBinary);
return await codec.decode(context, value);
return codec.decode(context, value);
} else {
if (bytes == null) {
return null;
Expand Down

0 comments on commit db49d6f

Please sign in to comment.