decode method

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

Decode.

Implementation

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

  for (final type in types) {
    if (type.encodingLength.isDynamic) {
      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 {
      final result = type.decode(buffer, offset + headersLength);
      headersLength += result.bytesRead;
      decoded.add(result.data);
    }
  }

  return DecodingResult(decoded, headersLength + dynamicLength);
}