• Stars
    star
    110
  • Rank 316,770 (Top 7 %)
  • Language
    Swift
  • License
    MIT License
  • Created almost 9 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

💾🔍🧮 BinaryKit helps you to break down binary data into bits and bytes, easily access specific parts and write data to binary.

BinaryKit

BinaryKit helps you to break down binary data into bits and bytes, easily access specific parts and write data to binary.

Access Bytes

By using any read* method (readByte(), readBytes(quantity:), readBit(), …), BinaryKit will increment an internal cursor (or reading offset) to the end of the requested bit or byte, so the next read* method can continue from there.

Any get* method (getByte(index:), getBytes(range:), getBit(index:), …) will give access to binary data at any given location — without incrementing the internal cursor.

Here are the methods you can call:

var binary = Binary(bytes: [0xDE, 0xAD, 0xBE, 0xEF, ])

// Reads exactly 1 byte and
// increments the cursor by 1 byte 
try binary.readByte()

// Reads the next 4 bytes and
// increments the cursor by 4 bytes
try binary.readBytes(4)

// Reads the next 1 bit and
// increments the cursor by 1 bit
try binary.readBit()

// Reads the next 4 bits and
// increments the cursor by 4 bits
try binary.readBits(4)

Example

var binary = Binary(bytes: [0b1_1_0_1_1_1_0_0])
//                            | | | | | | | | 
//                            | | | | | | | try binary.readBit()  // 0
//                            | | | | | | try binary.readBit()    // 0
//                            | | | | | try binary.readBit()      // 1
//                            | | | | try binary.readBit()        // 1
//                            | | | try binary.readBit()          // 1
//                            | | try binary.readBit()            // 0
//                            | try binary.readBit()              // 1
//                            try binary.readBit()                // 1

This shows how easy it is, to break down an IPv4 header.

var binary = Binary(bytes: [0x1B, 0x44, ])
let version                         = try binary.readBits(4)
let internetHeaderLength            = try binary.readBits(4)
let differentiatedServicesCodePoint = try binary.readBits(6)
let explicitCongestionNotification  = try binary.readBits(2)
let totalLength                     = try binary.readBytes(2)
let identification                  = try binary.readBytes(2)
let flags                           = try binary.readBits(4)
let fragmentOffset                  = try binary.readBits(12)
let timeToLive                      = try binary.readByte()
let protocolNumber                  = try binary.readByte()
let headerChecksum                  = try binary.readBytes(2)
let sourceIpAddress                 = try binary.readBytes(4)
let destinationIpAddress            = try binary.readBytes(4)
...

Store Bytes

Use the write* methods to store different types to binary.

var binary = Binary()
binary.writeInt32(1_350_849_546)
binary.writeString("Hello World!")
binary.writeBytes([0xFF, 0xCC, 0x00, 0x01])
binary.writeBool(true)

Contact

Other Projects

  • Clippy — Clippy from Microsoft Office is back and runs on macOS! Written in Swift.
  • GrammaticalNumber — Turns singular words to the plural and vice-versa in Swift.
  • HackMan — Stop writing boilerplate code yourself. Let hackman do it for you via the command line.
  • ISO8859 — Convert ISO8859 1-16 Encoded Text to String in Swift. Supports iOS, tvOS, watchOS and macOS.
  • SpriteMap — SpriteMap helps you to extract sprites out of a sprite map. Written in Swift.
  • StringCase — Converts String to lowerCamelCase, UpperCamelCase and snake_case. Tested and written in Swift.
  • TinyConsole — TinyConsole is a micro-console that can help you log and display information inside an iOS application, where having a connection to a development computer is not possible.

License

BinaryKit is released under the MIT License.

More Repositories

1

TinyConsole

📱💬🚦 TinyConsole is a micro-console that can help you log and display information inside an iOS application, where having a connection to a development computer is not possible.
Swift
1,955
star
2

OpenSwiftUI

WIP — OpenSwiftUI is an OpenSource implementation of Apple's SwiftUI DSL.
Swift
1,382
star
3

Clippy

📎💬🎉 Clippy from Microsoft Office is back and runs on macOS! Written in Swift.
Swift
741
star
4

HackMan

🤖🔜🤯 Stop writing boilerplate code yourself. Let hackman do it for you via the command line.
Swift
292
star
5

SwiftUIEmbedded

WIP — SwiftUIEmbedded is an implementation of SwiftUI (based on OpenSwiftUI) for embedded and Linux devices.
Swift
111
star
6

awesome-embedded-swift

⚡️🛠🧰 A curated list for Embedded and Low-Level development in the Swift programming language.
Swift
69
star
7

GrammaticalNumber

1️⃣🔜🔢 Turns singular words to the plural and vice-versa in Swift.
Swift
35
star
8

SwiftUIEmbedded-Demo

WIP — SwiftUIEmbedded — Demo for Linux
Swift
31
star
9

ISO8859

🌍⏩📄 Convert ISO8859 1-16 Encoded Text to String in Swift. Supports iOS, tvOS, watchOS and macOS.
Swift
18
star
10

Nodes

🌲🌿🌳 Nodes is a class protocol for tree data structures with multiple children. Written in Swift.
Swift
17
star
11

StringCase

👇👆🐍 Converts String to lowerCamelCase, UpperCamelCase and snake_case. Tested and written in Swift.
Swift
16
star
12

ShotPlan

A command line tool that calls your Xcode Test Plan and creates screenshots of your app automatically.
Swift
11
star
13

TransportStream

🎬📺🎞 MPEG-TS (Transport Stream) Tools: Demultiplexer, CRC32, Program Specific Information (PMT PAT, NIT, CAT). Written in Swift.
Swift
10
star
14

bashtv

Hackathon Project — Watch public television in your terminal. No browser needed.
Swift
8
star
15

awesome-swift-platforms

A curated list of Swift on different platforms.
Swift
4
star
16

Pixels

WIP — Pixels is a low level graphics library written in Swift.
Swift
4
star
17

News-Sightseeing

Sophisticated-location-aware-news.
C#
3
star
18

bashtv-service

C#
2
star
19

PSVR_api

C#
2
star
20

ToThePoint

Hackathon Project — Jump right to the interesting parts of a video. Project at mediahackday.
JavaScript
2
star
21

JSKit

A quick and dirty attempt to recreate UIKit in JavaScript
JavaScript
2
star
22

Isometric

JavaScript
1
star
23

SpriteMap

SpriteMap helps you to extract sprites out of a sprite map. Written in Swift.
Swift
1
star
24

spotify-places

Spotify places enables social playlists for bars based on the users favorite songs.
C#
1
star
25

FeedCollectionViewLayout

[WIP] 📱📐 Customizable UICollectionLayout for single and multi-column feeds.
Swift
1
star
26

Note

This is for debugging and reference only. Document Based + ReferenceFileDocument + UndoManager + Commands Example
Swift
1
star