Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fwcd/swift-binary-coder
Flat, untagged binary serializer for Codable Swift types
https://github.com/fwcd/swift-binary-coder
binary codable swift
Last synced: 25 days ago
JSON representation
Flat, untagged binary serializer for Codable Swift types
- Host: GitHub
- URL: https://github.com/fwcd/swift-binary-coder
- Owner: fwcd
- License: mit
- Created: 2022-09-07T21:08:55.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-04-20T14:33:27.000Z (over 1 year ago)
- Last Synced: 2024-11-29T11:48:50.544Z (about 1 month ago)
- Topics: binary, codable, swift
- Language: Swift
- Homepage: https://fwcd.github.io/swift-binary-coder/documentation/binarycoder
- Size: 59.6 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Binary Coder for Swift
[![Build](https://github.com/fwcd/swift-binary-coder/actions/workflows/build.yml/badge.svg)](https://github.com/fwcd/swift-binary-coder/actions/workflows/build.yml)
[![Docs](https://github.com/fwcd/swift-binary-coder/actions/workflows/docs.yml/badge.svg)](https://fwcd.github.io/swift-binary-coder/documentation/binarycoder)A simple `Encoder` and `Decoder` that serializes `Codable` Swift types to a flat, untagged binary representation. Note that this usually requires the structures to have a fixed size.
## Example
```swift
struct Point: Codable {
let x: UInt16
let y: UInt16
}let encoder = BinaryEncoder()
try encoder.encode(Point(x: 2, y: 3))
// -> Data([0, 2, 0, 3])let decoder = BinaryDecoder()
try decoder.decode(Point.self, from: Data([0, 2, 0, 3]))
// -> Point(x: 2, y: 3)
```