Skip to content

Commit

Permalink
0.6 compat & rename at-struct -> at-io
Browse files Browse the repository at this point in the history
Also disable travis testing on OS X
  • Loading branch information
Keno committed Feb 16, 2017
1 parent 5fdc718 commit 98eed1e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
language: julia
os:
- linux
- osx
julia:
- 0.5
- nightly
Expand Down
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
# StructIO

StructIO is inspired by StrPack. It is intended to be able to experiment with a
few new ideas without interrupting existing users of StrPack until it's ready,
but I do expect it to be merged in eventually.

[![StructIO](http://pkg.julialang.org/badges/StructIO_0.5.svg)](http://pkg.julialang.org/?pkg=StructIO)
[![Build Status](https://travis-ci.org/Keno/StructIO.jl.svg?branch=master)](https://travis-ci.org/Keno/StructIO.jl)

Generates IO methods (`sizeof`, `pack`, `unpack`) from structure definitions.

# Example usage
```julia
julia> using StructIO

julia> @io struct TwoUInt64s
x::UInt64
y::UInt64
end

julia> buf = IOBuffer(collect(UInt8(1):UInt8(16)));

julia> seekstart(buf); unpack(buf, TwoUInt64s) # Default endianness depends on machine
TwoUInt64s(0x0807060504030201, 0x100f0e0d0c0b0a09)

julia> seekstart(buf); unpack(buf, TwoUInt64s, :BigEndian)
TwoUInt64s(0x0102030405060708, 0x090a0b0c0d0e0f10)

```
3 changes: 2 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
julia 0.5-
julia 0.5
Compat 0.18.0
7 changes: 4 additions & 3 deletions src/StructIO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ module StructIO

using Base: @pure
using Base.Meta
export @struct, unpack, pack, fix_endian
using Compat
export @io, unpack, pack, fix_endian

needs_bswap(endianness) = (ENDIAN_BOM == 0x01020304) ?
endianness == :LittleEndian : endianness == :BigEndian
fix_endian(x, endianness) = needs_bswap(x) ? bswap(x) : x

# Alignment traits
abstract PackingStrategy
@compat abstract type PackingStrategy end
immutable Packed <: PackingStrategy; end
immutable Default <: PackingStrategy; end
function strategy
Expand All @@ -31,7 +32,7 @@ module StructIO
sizeof(T::DataType) = sizeof(T, nfields(T) == 0 ? Default : strategy(T))

# Generates methods for unpack!, pack!, and sizeof
macro struct(typ, annotations...)
macro io(typ, annotations...)
alignment = :align_default
if length(annotations) == 1
ann = annotations[1]
Expand Down
9 changes: 5 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using StructIO
using Compat
using Base.Test

@struct immutable TwoUInts
@io immutable TwoUInts
x::UInt
y::UInt
end
Expand All @@ -12,15 +13,15 @@ write(buf, UInt(2))
seekstart(buf)
@test unpack(buf, TwoUInts) == TwoUInts(1,2)

abstract SomeAbstractType
@struct immutable SomeConcreteType <: SomeAbstractType
@compat abstract type SomeAbstractType end
@io immutable SomeConcreteType <: SomeAbstractType
A::UInt32
B::UInt16
C::UInt32
D::UInt8
end align_packed

@struct immutable ParametricType{S,T}
@io immutable ParametricType{S,T}
A::S
B::T
C::T
Expand Down

0 comments on commit 98eed1e

Please sign in to comment.