decode method

Future<Object?> decode(
  1. EncodedValue value,
  2. CodecContext context
)

Implementation

Future<Object?> decode(EncodedValue value, CodecContext context) async {
  final typeOid = value.typeOid;
  if (typeOid == null) {
    throw ArgumentError('`EncodedValue.typeOid` was not provided.');
  }

  // check for codec
  final codec = _codecs[typeOid];
  if (codec != null) {
    final r = await codec.decode(value, context);
    if (r != value && r is! UndecodedBytes) {
      return r;
    }
  }

  // fallback decoding
  final bytes = value.bytes;
  if (bytes == null) {
    return null;
  }
  return UndecodedBytes(
    typeOid: typeOid,
    bytes: bytes,
    isBinary: value.isBinary,
    encoding: context.encoding,
  );
}