<commit_before>library hetimatorrent.message.cancel;

import 'dart:core';
import 'dart:async';
import 'package:hetimacore/hetimacore.dart';
import 'torrentmessage.dart';

class TMessageCancel extends TorrentMessage {
  static final List<int> RESERVED = new List.from([0, 0, 0, 0, 0, 0, 0, 0], growable: false);


  static const int CANCEL_LENGTH = 1+4*3;
  int _mIndex = 0;
  int _mBegin = 0;
  int _mLength = 0;

  int get index => _mIndex; 
  int get begin => _mBegin;
  int get length => _mLength;

  TMessageCancel._empty() : super(TorrentMessage.SIGN_CANCEL) {
  }

  TMessageCancel(int index, int begin, int length) : super(TorrentMessage.SIGN_CANCEL) {
    this._mIndex = index;
    this._mBegin = begin;
    this._mLength= length;
  }

  static Future<TMessageCancel> decode(EasyParser parser) {
    Completer c = new Completer();
    TMessageCancel message = new TMessageCancel._empty();
    parser.push();
    parser.readInt(ByteOrder.BYTEORDER_BIG_ENDIAN).then((int size) {
      if(size != CANCEL_LENGTH) {
        throw {};
      }
      return parser.readByte();
    }).then((int v) {
      if(v != TorrentMessage.SIGN_CANCEL) {
        throw {};
      }
      return parser.readInt(ByteOrder.BYTEORDER_BIG_ENDIAN);
    }).then((int index) {
      message._mIndex = index;
      return parser.readInt(ByteOrder.BYTEORDER_BIG_ENDIAN);
    }).then((int begin) {
      message._mBegin = begin;
      return parser.readInt(ByteOrder.BYTEORDER_BIG_ENDIAN);
    }).then((int length) {
      message._mLength = length;
      parser.pop();
      c.complete(message);
    }).catchError((e) {
      parser.back();
      parser.pop();
      c.completeError(e);
    });
    return c.future;
  }

  Future<List<int>> encode() {
    return new Future(() {
      ArrayBuilder builder = new ArrayBuilder();
      builder.appendIntList(ByteOrder.parseIntByte(CANCEL_LENGTH, ByteOrder.BYTEORDER_BIG_ENDIAN));
      builder.appendByte(id);
      builder.appendIntList(ByteOrder.parseIntByte(_mIndex, ByteOrder.BYTEORDER_BIG_ENDIAN));
      builder.appendIntList(ByteOrder.parseIntByte(_mBegin, ByteOrder.BYTEORDER_BIG_ENDIAN));
      builder.appendIntList(ByteOrder.parseIntByte(_mLength, ByteOrder.BYTEORDER_BIG_ENDIAN));
      return builder.toList();
    });
  }
  
  String toString() {
    return "${TorrentMessage.toText(id)}:${_mIndex} ${_mBegin} ${_mLength}";
  }
}<commit_msg>mod async base about messagecancel<commit_after>library hetimatorrent.message.cancel;

import 'dart:core';
import 'dart:async';
import 'package:hetimacore/hetimacore.dart';
import 'torrentmessage.dart';

class TMessageCancel extends TorrentMessage {
  static final List<int> RESERVED = new List.from([0, 0, 0, 0, 0, 0, 0, 0], growable: false);

  static const int CANCEL_LENGTH = 1 + 4 * 3;
  int _mIndex = 0;
  int _mBegin = 0;
  int _mLength = 0;

  int get index => _mIndex;
  int get begin => _mBegin;
  int get length => _mLength;

  TMessageCancel._empty() : super(TorrentMessage.SIGN_CANCEL) {}

  TMessageCancel(int index, int begin, int length) : super(TorrentMessage.SIGN_CANCEL) {
    this._mIndex = index;
    this._mBegin = begin;
    this._mLength = length;
  }

  static Future<TMessageCancel> decode(EasyParser parser) async {
    parser.push();
    try {
      int size = await parser.readInt(ByteOrder.BYTEORDER_BIG_ENDIAN);
      if (size != CANCEL_LENGTH) {
        throw {};
      }
      int v = await parser.readByte();
      if (v != TorrentMessage.SIGN_CANCEL) {
        throw {};
      }
      TMessageCancel message = new TMessageCancel._empty();
      message._mIndex = await parser.readInt(ByteOrder.BYTEORDER_BIG_ENDIAN);
      message._mBegin = await parser.readInt(ByteOrder.BYTEORDER_BIG_ENDIAN);
      message._mLength = await parser.readInt(ByteOrder.BYTEORDER_BIG_ENDIAN);
      parser.pop();
      return message;
    } catch (e) {
      parser.back();
      parser.pop();
    }
  }

  Future<List<int>> encode() async {
    ArrayBuilder builder = new ArrayBuilder();
    builder.appendIntList(ByteOrder.parseIntByte(CANCEL_LENGTH, ByteOrder.BYTEORDER_BIG_ENDIAN));
    builder.appendByte(id);
    builder.appendIntList(ByteOrder.parseIntByte(_mIndex, ByteOrder.BYTEORDER_BIG_ENDIAN));
    builder.appendIntList(ByteOrder.parseIntByte(_mBegin, ByteOrder.BYTEORDER_BIG_ENDIAN));
    builder.appendIntList(ByteOrder.parseIntByte(_mLength, ByteOrder.BYTEORDER_BIG_ENDIAN));
    return builder.toList();
  }

  String toString() {
    return "${TorrentMessage.toText(id)}:${_mIndex} ${_mBegin} ${_mLength}";
  }
}
{'fraction_non_alphanumeric': 0.12527618205921343, 'fraction_numerical': 0.0061864781263809105, 'mean_word_length': 3.7452830188679247, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1079228', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1508, 'n_words': 290}