Swiftpack.co -  spacenation/swift-binary-decoder as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
:rocket: Binary Decoder
.package(url: "https://github.com/spacenation/swift-binary-decoder.git", from: "2.0.0-beta.17")



SPM package to decode and encode types from binary data.

Binary Decoder

try? BinaryDecoder.decode(Message<DeliveryFlags>.self, from: [0b0000_1111, 0b1111_1111, 0b0000_0011])

Binary Encoder

try? BinaryEncoder.encode(Message(source: 15, data: Data([0b1111_1111]), flags: DeliveryFlags(isDelivered: true, isRead: true)))


private struct Message<Flags: Equatable & BinaryCodable>: Equatable, BinaryCodable {
    let source: UInt8
    let data: Data
    let flags: Flags
    init(source: UInt8, data: Data, flags: Flags) {
        self.source = source
        self.data = data
        self.flags = flags
    init(from decoder: BinaryDecoder) throws {
        source = try decoder.decode()
        data = try decoder.decode(size: .byte)
        try decoder.skip(size: 6)
        flags = try decoder.decode()
    func encode(to encoder: BinaryEncoder) throws {
        encoder.encode(data, size: .byte)
        encoder.encodeEmpty(size: 6)
        try encoder.encode(flags)

Code Contributions

Feel free to contribute via fork/pull request to master branch. If you want to request a feature or report a bug please start a new issue.

Coffee Contributions

If you find this project useful please consider becoming my GitHub sponsor.


Stars: 1
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Int decoders
1 week ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API