All Projects → tsolomko → BitByteData

tsolomko / BitByteData

Licence: MIT license
Read and write bits and bytes in Swift.

Programming Languages

swift
15916 projects
python
139335 projects - #7 most used programming language
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to BitByteData

xbytes
Parse bytes to human readable sizes (4747) → ('4.75 KB') and vice versa.
Stars: ✭ 17 (-19.05%)
Mutual labels:  bytes, bits
Simulink-Arduino-Serial
How to connect Arduino and Simulink
Stars: ✭ 54 (+157.14%)
Mutual labels:  bytes
Codec Beam
Generate Erlang VM byte code from Haskell
Stars: ✭ 152 (+623.81%)
Mutual labels:  bytes
bytes
Work with bytes and implement network protocols
Stars: ✭ 77 (+266.67%)
Mutual labels:  bytes
Flake Idgen
Flake ID generator yields k-ordered, conflict-free ids in a distributed environment in Node.js
Stars: ✭ 196 (+833.33%)
Mutual labels:  bytes
biguint-format
Node.js module to format big uint numbers from a byte array or a Buffer
Stars: ✭ 16 (-23.81%)
Mutual labels:  bytes
Deku
Declarative binary reading and writing: bit-level, symmetric, serialization/deserialization
Stars: ✭ 136 (+547.62%)
Mutual labels:  bytes
impartus-downloader
Download Impartus lectures, convert to mkv for offline viewing.
Stars: ✭ 19 (-9.52%)
Mutual labels:  bits
Pbbl
A thread-safe ByteBuffer pool that allows for the automatic reuse of ByteBuffers, which can be over 30x faster than having to allocate a new ByteBuffer when needed.
Stars: ✭ 32 (+52.38%)
Mutual labels:  bytes
bytekit
Java 字节操作的工具库(不是字节码的工具库)
Stars: ✭ 40 (+90.48%)
Mutual labels:  bytes
Bytes
Swift Library for working with sequences of Bytes (aka [UInt8])
Stars: ✭ 35 (+66.67%)
Mutual labels:  bytes
Hex
🔮 Futuristic take on hexdump, made in Rust.
Stars: ✭ 242 (+1052.38%)
Mutual labels:  bytes
GoogleDriveBrowser
Goole Drive Download Library for iOS
Stars: ✭ 13 (-38.1%)
Mutual labels:  bytes
Simplenet
An easy-to-use, event-driven, asynchronous network application framework compiled with Java 11.
Stars: ✭ 164 (+680.95%)
Mutual labels:  bytes
SerialTransfer
Arduino library to transfer dynamic, packetized data fast and reliably via Serial, I2C, or SPI
Stars: ✭ 273 (+1200%)
Mutual labels:  bytes
Hltool
Go 开发常用工具库, Google2步验证客户端,AES加密解密,RSA加密解密,钉钉机器人,邮件发送,JWT生成解析,Log,BoltDB操作,图片操作,json操作,struct序列化
Stars: ✭ 151 (+619.05%)
Mutual labels:  bytes
memchr
Optimized string search routines for Rust.
Stars: ✭ 474 (+2157.14%)
Mutual labels:  bytes
ByteSizeLibPascal
TByteSize is a utility record that makes byte size representation in code easier by removing ambiguity of the value being represented.
Stars: ✭ 24 (+14.29%)
Mutual labels:  bytes
rulid.rs
Rust Universally Unique Lexicographically Sortable Identifier
Stars: ✭ 40 (+90.48%)
Mutual labels:  bytes
bytes-java
Bytes is a utility library that makes it easy to create, parse, transform, validate and convert byte arrays in Java. It supports endianness as well as immutability and mutability, so the caller may decide to favor performance.
Stars: ✭ 120 (+471.43%)
Mutual labels:  bytes

BitByteData

Swift 5.1+ GitHub license Build Status

A Swift framework with classes for reading and writing bits and bytes. Supported platforms include Apple platforms, Linux, and Windows.

Installation

BitByteData can be integrated into your project using either Swift Package Manager, CocoaPods, or Carthage.

Swift Package Manager

To install using SPM, add BitByteData to you package dependencies and specify it as a dependency for your target, e.g.:

import PackageDescription

let package = Package(
    name: "PackageName",
    dependencies: [
        .package(url: "https://github.com/tsolomko/BitByteData.git",
                 from: "2.0.0")
    ],
    targets: [
        .target(
            name: "TargetName",
            dependencies: ["BitByteData"]
        )
    ]
)

More details you can find in Swift Package Manager's Documentation.

CocoaPods

Add pod 'BitByteData', '~> 2.0' and use_frameworks! lines to your Podfile.

To complete installation, run pod install.

Carthage

Add to your Cartfile github "tsolomko/BitByteData" ~> 2.0.

Then:

  1. If you use Xcode 12 or later you should run carthage update --use-xcframeworks. After that drag and drop the BitByteData.xcframework file from the Carthage/Build/ directory into the "Frameworks, Libraries, and Embedded Content" section of your target's "General" tab in Xcode.

  2. If you use Xcode 11 or earlier you should run carthage update. After that drag and drop the BitByteData.framework file from from the Carthage/Build/<platform>/ directory into the "Embedded Binaries" section of your target's "General" tab in Xcode.

Migration to 2.0

There is a number of breaking changes in the 2.0 update. In this section you can find a list of modifications you need to perform to your code to make it compile with BitByteData 2.0. For more information, please refer to either 2.0 Release Notes or API Reference Documentation.

  1. ByteReader class has been renamed to LittleEndianByteReader.

    Solution: Change all occurrences in your code of ByteReader to LittleEndianByteReader.

  2. BitReader protocol has two new method requirements: signedInt(fromBits:representation:) and advance(by:).

    Solution: If you have your own type that conforms to the BitReader protocol you need to implement these two methods.

  3. BitWriter protocol has two new method requirements: write(unsignedNumber:bitsCount:) and write(signedNumber:bitsCount:representation:).

    Solution: If you have your own type that conforms to the BitWriter protocol you need to implement the write(unsignedNumber:bitsCount:) function (the second function has a default implementation).

  4. The setter of the offset property of the LsbBitReader and MsbBitReader classes will now crash if the reader is not aligned.

    Solution: If you set this property directly, make sure that the reader is aligned, for example, by checking the isAligned property.

  5. The default implementation of the BitWriter.write(number:bitsCount:) function and the write(unsignedNumber:bitsCount:) function of the LsbBitWriter and MsbBitWriter classes now crash if the bitsCount argument exceeds the bit width of the integer type on the current platform.

    Solution: If you use these functions directly, make sure that the bitsCount argument has a valid value.

In addition, BitByteData 2.0 provides new functionality for working with signed integers more correctly. If you were working with signed integers before, consider using the new BitReader.signedInt(fromBits:representation:) and BitWriter.write(signedNumber:bitsCount:representation:) functions instead of int(fromBits:) and write(number:bitsCount:), respectively.

Usage

To read bytes use either LittleEndianByteReader or BigEndianByteReader class, which implement the ByteReader protocol.

For reading bits there are also two classes: LsbBitReader and MsbBitReader, which implement the BitReader protocol for two bit-numbering schemes ("LSB 0" and "MSB 0" correspondingly), though they only support Little Endian byte order. Since the BitReader protocol inherits from ByteReader, you can also use the LsbBitReader and MsbBitReader classes to read bytes (but they must be aligned when doing so, see documentation for more details).

Writing bits is implemented for two bit-numbering schemes as well: the LsbBitWriter and MsbBitWriter classes. Both of them conform to the BitWriter protocol.

Note: All readers and writers aren't structs, but classes intentionally to make it easier to pass them as references to functions. This allows to eliminate potential copying and avoid writing extra inouts and ampersands all over the code.

Documentation

Every function or type of BitByteData's public API is documented. This documentation can be found at its own website or via a slightly shorter link: bitbytedata.tsolomko.me

Contributing

Whether you find a bug, have a suggestion, idea, feedback or something else, please create an issue on GitHub. If you have any questions, you can ask them on the Discussions page.

If you'd like to contribute, please create a pull request on GitHub.

Note: If you are considering working on BitByteData, please note that the Xcode project (BitByteData.xcodeproj) was created manually and you shouldn't use the swift package generate-xcodeproj command.

Performance and benchmarks

One of the most important goals of BitByteData's development is high speed performance. To help achieve this goal there are benchmarks for every function in the project as well as a handy command-line tool, benchmarks.py, which helps to run, show, and compare benchmarks and their results.

If you are considering contributing to the project please make sure that:

  1. Every new function has also a new benchmark added.
  2. Other changes to existing functionality do not introduce performance regressions, or, at the very least, these regressions are small and such performance tradeoff is necessary and justifiable.

Finally, please note that any meaningful comparison can be made only between benchmarks run on the same hardware and software.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].