Git Product home page Git Product logo

buffer's Introduction

Buffer - Dart library for byte buffers and streams.

Pub

Utility functions and classes to work with byte buffers and streams efficiently, to read and write binary data formats.

Examples

Here are some examples of how you can use the buffer package:

Writing to a ByteDataWriter and reading from a ByteDataReader

This example demonstrates how to write unsigned integers of different sizes to a ByteDataWriter and then read them back using a ByteDataReader.

final writer = ByteDataWriter();
writer.writeUint8(255);
writer.writeUint16(65535);
writer.writeUint32(4294967295);

final reader = ByteDataReader();
reader.add(writer.toBytes());
print(reader.readUint8()); // Output: 255
print(reader.readUint16()); // Output: 65535
print(reader.readUint32()); // Output: 4294967295

buffer's People

Contributors

adrianboyko avatar albemala avatar isoos avatar jonasfj avatar timwhiting avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

buffer's Issues

Reading zero bytes from end of buffer crashes.

I encountered this minor problem in a project that reads a p-string (length prefixed) string at the end of a datagram. In one case, the length of the string was 0 and the subsequent read(0) crashed.

Here's a test case that simulates the situation I ran into. Think of [0,0,0,0] as a datagram that contains just one empty p-string.

    test('Zero byte read at end of buffer', () {
      final buffer = [0,0,0,0]; 
      final reader = ByteDataReader();
      reader.add(buffer);
      final strLen = reader.readUint32();
      expect(strLen, equals(0));
      var noBytes = reader.read(strLen);
      expect(noBytes.length, equals(0));
    });

The work-around is to only call read(n) when n>0, but it would be better if read(0) just returned an empty Uint8List.

P.S. Thanks for publishing this library!

Null Safety Migration

Null safety is now in beta. I would like to update my package to use null-safety, but I depend on this package.

Any ideas when you will upgrade? I'd be willing to submit a pull request. A quick check with dart migrate seems to provide a decent migration, but I understand if you would like to spend a bit more time and not have as many null asserts.

Add support for `peek`.

There are cases when you need to peek ahead for given data, e.g. check for magics and act accordingly.

ByteDataReader Offset - setter

I am working on a project where I would need to update the offset position. Something similar to MemoryStream class in C#, Where Stream position can be updated.

I see there is a getter for OffsetInBytes. I think enabling this feature adds more value to this solution.

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.