decode method

  1. @override
DecodingResult<List<T>> decode(
  1. ByteBuffer buffer,
  2. int offset
)
override

Implementation

@override
DecodingResult<List<T>> decode(ByteBuffer buffer, int offset) {
  final decoded = <T>[];
  var headersLength = 0;
  var dynamicLength = 0;

  if (encodingLength.isDynamic) {
    for (var i = 0; i < length; i++) {
      final positionResult =
          const UintType().decode(buffer, offset + headersLength);
      headersLength += positionResult.bytesRead;

      final position = positionResult.data.toInt();

      final dataResult = type.decode(buffer, offset + position);
      dynamicLength += dataResult.bytesRead;
      decoded.add(dataResult.data);
    }
  } else {
    for (var i = 0; i < length; i++) {
      final result = type.decode(buffer, offset + headersLength);
      headersLength += result.bytesRead;

      decoded.add(result.data);
    }
  }

  return DecodingResult(decoded, headersLength + dynamicLength);
}