GithubHelp home page GithubHelp logo

dekkonot / bitbuffer Goto Github PK

View Code? Open in Web Editor NEW
42.0 42.0 11.0 896 KB

A binary stream module for packing binary data in pure Lua

Home Page: https://dekkonot.github.io/bitbuffer/

License: MIT License

Lua 99.88% Shell 0.07% Batchfile 0.05%
binary-data lua roblox roblox-lua stream

bitbuffer's People

Contributors

brinkokevin avatar dekkonot avatar jeparlefrancais avatar

Stargazers

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

Watchers

 avatar  avatar

bitbuffer's Issues

Remove adler32

After rethinking it, I believe adler32 is too niche to keep in the BitBuffer -- it's easy to implement on its own and is only useful for zlib.

Assertion messages are inconsisent

In some cases (such as writeFloat) the assertion messages use the format bitBuffer.X and in others (such as readBit) they use X (n both cases, X is the name of the function)

Ideally, the format would be bitBuffer.X since it makes debugging easier.

Switch to using hex for all constants

The source of the module looks like it's filled with magic numbers, and hex will make it look less like that since numbers like 0x7f and 0xff are obvious to people who know what they're doing

Read base64 string buffer

This request comes from the fact that I can't seem to assign the value I get from buffer.dumpString() into a StringValue object Value property. I tried using a ModuleScript's Source property to store the string but didn't have any luck with that neither.

My solution for this is to store the dumpBase64() string, but it would be nicer to have a way to make BitBuffer read it back ๐Ÿ™‚

It could be done by changing the API to something like this:

BitBuffer(stream: str, options?: { format = "byte" | "base64" | "binary" | "hex" })

Let me know what you think about that!

Add several common datatypes to module as shorthands

Should include things like Int32 and UInt32. Should also shorthand some like writeByte -> writeUInt8.

Unclear how to handle assertions and testing. Seems like it may add a lot of overhead to run assertions twice in cases like writeFloat32.

  • UInt8
  • Int8
  • UInt16
  • Int16
  • UInt32
  • Int32
  • UInt64
  • Int64
  • Float16
  • Float32
  • Float64

Switch to faster table.concat use

Creating several medium sized strings and then using table.concat on an array of them is faster than using table.concat on a bunch of small strings.

Add documentation for the module

Documentation is a must, and a dedicated github pages site (made either by hand or with mkdocs) is a good idea, especially when #4 and #2 are dealt with.

Remove bit-level packing

The module currently has several functions that operate on a bit level that utterly thrash the performance of the module, to the point that there's a recommendation to not use them and functions that avoid them entirely. We should remove these entirely in the future.

This is rather far reaching because it involves removing some rather fundamental parts of the module, but it's a small price to pay for performance and futureproofing.

Add functions for exporting in chunks

It would be beneficial to have the ability to output an X length chunk from the current pointer, as very large streams may cause problems if exported all at once.

Ideally in the form of dumpString(length: number?)

dumpBase64 using incorrect table.create amount

In dumpBase64 for the roblox version, to create the table of output bytes the script will do table.create(math.ceil(byteCount * 0.333)). This is incorrect, as Base64 does not make the file size 1/3. it should be * 1.333.

Reimplement writeUnsigned to finish off current byte when buffer isn't aligned

At the moment, writeUnsigned calls writeByte several times followed by writeBits. It should instead call writeBits with however many bits is needed to make the buffer aligned, call writeByte with whatever is left, then call writeBits after that.

Benchmarks forthcoming, but I assume this will be substantially faster than the current implementation.

Create roblox specific version of module

The Roblox specific version of the module should:

  • Run in Roblox
  • Use table.create where possible
  • Have type annotations
  • Have Roblox specific datatypes

And long-term should have support for the Roblox CLI when it comes out.

Make sure all the write functions actually return `nil`

Early in development the plan was to have the buffer return false instead of throwing when something went wrong. Artifacts of that exist throughout the base functions but the documentation says they all return nil. Should be corrected at some point.

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.