GithubHelp home page GithubHelp logo

Comments (2)

postmasters avatar postmasters commented on July 28, 2024

That is the purpose of the split method.

https://github.com/google/crclib.dart/blob/main/lib/src/primitive.dart#L105

After calling that, you can finalize the returned sink.

from crclib.dart.

dlewis2017 avatar dlewis2017 commented on July 28, 2024

Thanks! @postmasters I think that should work. It would be helpful if FinalSink could be exposed and just the type for ParametricCrcSink<dynamic> but in theory, based on what you said, the below should work. I do manage to get it to work when the bytes being sent over BLE are small enough that there's only 1 chunk from C to Dart. But I have not been able to get it working for multiple chunks and going from Dart to C. The C side isn't able to compute a proper CRC based on the value I calculate on the Dart side. I'm pretty sure the polynomials and all variables match even though the other code is C, and I've tried multiple types from the catalog.dart file but still no luck. I'll assume it's some weird mismatch and this issue can be closed.

Another interesting note is that the code here works both Dart to C and C to Dart: https://github.com/kaisellgren/CRC32/blob/master/lib/crc32.dart


  Crc32IsoHdlc crc32 = Crc32IsoHdlc();
  CrcValueCollector outputSink = CrcValueCollector();
  
      if (currentChunk == 0) {
        final crcSink = crc32.startChunkedConversion(outputSink);
        crcSink.add(totalSegments);
        crcSink.close();
      } else {
        final updatedSink = crcSink.split(outputSink);
        updatedSink.add(totalSegments);
        updatedSink.close();
      }
      
...


class CrcValueCollector implements Sink<CrcValue> {
  CrcValue? crcValue;

  int get crcValueInt {
    final bigIntVal = crcValue!.toBigInt();
    return bigIntVal.toInt();
  }

  @override
  void add(CrcValue data) {
    crcValue = data;
  }

  @override
  void close() {
    print('CRC Calculation Completed: ${crcValue.toString()}');
  }
}

from crclib.dart.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.