@@ -583,9 +583,11 @@ class PostgresBinaryEncoder {
583583 case TypeOid .jsonbArray:
584584 {
585585 if (input is List ) {
586- final objectsArray = input
587- .map (_jsonFusedEncoding (encoding).encode)
588- .toList ();
586+ final encoder = _jsonFusedEncoding (encoding);
587+ final objectsArray = input.map ((item) {
588+ if (item is TypedValue && item.isSqlNull) return null ;
589+ return encoder.encode (item);
590+ }).toList ();
589591 return _writeListBytes <List <int >>(
590592 objectsArray,
591593 3802 ,
@@ -914,15 +916,15 @@ class PostgresBinaryDecoder {
914916 return readListBytes <Uint8List >(
915917 input,
916918 (reader, length) => reader.read (length),
917- );
919+ ).items ;
918920
919921 case TypeOid .uuid:
920922 return _decodeUuid (input);
921923 case TypeOid .uuidArray:
922924 return readListBytes <String >(
923925 input,
924926 (reader, _) => _decodeUuid (reader.read (16 )),
925- );
927+ ).items ;
926928
927929 case TypeOid .regtype:
928930 final data = input.buffer.asByteData (input.offsetInBytes, input.length);
@@ -984,53 +986,66 @@ class PostgresBinaryDecoder {
984986 return readListBytes <bool >(
985987 input,
986988 (reader, _) => reader.readUint8 () != 0 ,
987- );
989+ ).items ;
988990
989991 case TypeOid .smallIntegerArray:
990- return readListBytes <int >(input, (reader, _) => reader.readInt16 ());
992+ return readListBytes <int >(
993+ input,
994+ (reader, _) => reader.readInt16 (),
995+ ).items;
991996 case TypeOid .integerArray:
992- return readListBytes <int >(input, (reader, _) => reader.readInt32 ());
997+ return readListBytes <int >(
998+ input,
999+ (reader, _) => reader.readInt32 (),
1000+ ).items;
9931001 case TypeOid .bigIntegerArray:
994- return readListBytes <int >(input, (reader, _) => reader.readInt64 ());
1002+ return readListBytes <int >(
1003+ input,
1004+ (reader, _) => reader.readInt64 (),
1005+ ).items;
9951006
9961007 case TypeOid .dateArray:
9971008 return readListBytes <DateTime >(
9981009 input,
9991010 (reader, _) =>
10001011 DateTime .utc (2000 ).add (Duration (days: reader.readInt32 ())),
1001- );
1012+ ).items ;
10021013 case TypeOid .timeArray:
10031014 return readListBytes <Time >(
10041015 input,
10051016 (reader, _) => Time .fromMicroseconds (reader.readInt64 ()),
1006- );
1017+ ).items ;
10071018 case TypeOid .timestampArray:
10081019 case TypeOid .timestampTzArray:
10091020 return readListBytes <DateTime >(
10101021 input,
10111022 (reader, _) => DateTime .utc (
10121023 2000 ,
10131024 ).add (Duration (microseconds: reader.readInt64 ())),
1014- );
1025+ ).items ;
10151026
10161027 case TypeOid .varCharArray:
10171028 case TypeOid .textArray:
10181029 return readListBytes <String >(input, (reader, length) {
10191030 return context.encoding.decode (length > 0 ? reader.read (length) : []);
1020- });
1031+ }).items ;
10211032
10221033 case TypeOid .doubleArray:
10231034 return readListBytes <double >(
10241035 input,
10251036 (reader, _) => reader.readFloat64 (),
1026- );
1037+ ).items ;
10271038
10281039 case TypeOid .jsonbArray:
1029- return readListBytes <dynamic >(input, (reader, length) {
1040+ final (: items, : sqlNulls) = readListBytes <dynamic >(input, (
1041+ reader,
1042+ length,
1043+ ) {
10301044 reader.read (1 );
10311045 final bytes = reader.read (length - 1 );
10321046 return _jsonFusedEncoding (context.encoding).decode (bytes);
10331047 });
1048+ return JsonbListView (items, sqlNulls);
10341049
10351050 case TypeOid .integerRange:
10361051 final range = _decodeRange (context, buffer, input, TypeOid .integer);
@@ -1076,12 +1091,12 @@ class PostgresBinaryDecoder {
10761091 );
10771092 }
10781093
1079- static List <V ?> readListBytes <V >(
1094+ static ({ List <V ?> items, List < bool > sqlNulls}) readListBytes <V >(
10801095 Uint8List data,
10811096 V Function (ByteDataReader reader, int length) valueDecoder,
10821097 ) {
10831098 if (data.length < 16 ) {
1084- return [] ;
1099+ return (items : [], sqlNulls : []) ;
10851100 }
10861101
10871102 final reader = ByteDataReader ()..add (data);
@@ -1092,20 +1107,23 @@ class PostgresBinaryDecoder {
10921107
10931108 reader.read (4 ); // index
10941109
1110+ final sqlNulls = < bool > [];
10951111 bool hasNull = false ;
10961112 for (var i = 0 ; i < size; i++ ) {
10971113 final len = reader.readInt32 ();
10981114 if (len == - 1 ) {
10991115 decoded.add (null );
1116+ sqlNulls.add (true );
11001117 hasNull = true ;
11011118 } else {
11021119 final v = valueDecoder (reader, len);
11031120 decoded.add (v);
1121+ sqlNulls.add (false );
11041122 hasNull = hasNull || (v == null );
11051123 }
11061124 }
11071125
1108- return hasNull ? decoded : decoded.cast <V >();
1126+ return (items : hasNull ? decoded : decoded.cast <V >(), sqlNulls : sqlNulls );
11091127 }
11101128
11111129 /// Decode numeric / decimal to String without loosing precision.
0 commit comments