'Verify the byte length of the data

I'm writing and reading data from the bluetooth device. One of the messages that I have to send follows the scheme: |01|startingEntry|endingEntry|. Together the message contains 8 bytes. startingInt should have 3 bytes and endingInt should have 3 bytes too. How I can ensure this in my code?

List<int> _request = [];
    List<List<int>> _response = [];

    try {
      _request = HEX.decode("02");
      String _logLength = HEX.encode(await sendReqReadRespLogging(_request)).substring(4,12);
      print('Number of messages: ' + _logLength);

      // max number of message per one response is 7
      final _logLengthInt = int.parse(_logLength);
      int numberOfPackages = _logLengthInt ~/ 7;
      int remainder = _logLengthInt % 7;

      List<String> _logMessages = [];

      //covering full messages
      for(int i = 0; i < numberOfPackages; i++){

        final startingEntry = i*7;
        final endingEntry = (i+1)*7-1;

        _request = HEX.decode("01$startingEntry$endingEntry");
        String _logMessage = HEX.encode(await sendReqReadRespLogging(_request)).substring(8,130);
        _logMessages.add(_logMessage);
      }
      //covering leftover messages
      if(remainder != 0){

        final startingEntry = numberOfPackages*7;
        final endingEntry = numberOfPackages*7+remainder;

        _request = HEX.decode("01$startingEntry$endingEntry");
        String _logMessage = HEX.encode(await sendReqReadRespLogging(_request)).substring(8,130);
        _logMessages.add(_logMessage);
      }

      print('logs: ' + _logMessages.toString());

    } catch (e) {
      throw 'GET_LOGS_ERROR:' + e.toString();
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source