https://github.com/serenity4/binaryparsingtools.jl
A collection of tools to parse binary data
https://github.com/serenity4/binaryparsingtools.jl
Last synced: 3 months ago
JSON representation
A collection of tools to parse binary data
- Host: GitHub
- URL: https://github.com/serenity4/binaryparsingtools.jl
- Owner: serenity4
- License: mit
- Created: 2024-06-05T18:53:08.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-19T09:06:54.000Z (8 months ago)
- Last Synced: 2025-02-12T13:23:31.849Z (5 months ago)
- Language: Julia
- Homepage:
- Size: 290 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BinaryParsingTools
[](https://serenity4.github.io/BinaryParsingTools.jl/stable/)
[](https://serenity4.github.io/BinaryParsingTools.jl/dev/)
[](https://github.com/serenity4/BinaryParsingTools.jl/actions/workflows/CI.yml?query=branch%3Amain)
[](https://codecov.io/gh/serenity4/BinaryParsingTools.jl)Provides a set of tools for working with binary data formats.
This library uses a `BinaryIO`, to be extended for any `Base.read` operations on
your types. Under the hood, this is an alias to `SwapStreams.SwapStream` which will
make sure you read in the correct endianness. To determine whether endianness should be changed, see `BinaryParsingTools.swap_endianness`.Then, read any binary data using `read_binary` which will create the create the appropriate `BinaryIO` and dispatch to `Base.read(::BinaryIO, ::Type{MyType})`.
```julia
using BinaryParsingToolsBinaryParsingTools.swap_endianness(io::IO, ::Type{MyType}) = false
function Base.read(::BinaryIO, ::Type{MyType})
# ...
endopen(io -> read_binary(io, MyType), "data.bin")
```A `@serializable` macro is furthermore provided to automate the parsing of structs, as so:
```julia
@serializable struct MyType
x::UInt32
name::String << String([read(io, UInt8) for _ in 1:32])
end
```which will automatically define `read(io::IO, ::Type{MyType})` (see the reference documentation for more details on how it works).