From 98eed1e536452d5fc922bf13ac5ca9e7cbbfa8fe Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Thu, 16 Feb 2017 16:15:14 -0500 Subject: [PATCH] 0.6 compat & rename at-struct -> at-io Also disable travis testing on OS X --- .travis.yml | 1 - README.md | 25 +++++++++++++++++++++---- REQUIRE | 3 ++- src/StructIO.jl | 7 ++++--- test/runtests.jl | 9 +++++---- 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index f725a9b..bee1f51 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ language: julia os: - linux - - osx julia: - 0.5 - nightly diff --git a/README.md b/README.md index 47697ba..4358773 100644 --- a/README.md +++ b/README.md @@ -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) + +``` diff --git a/REQUIRE b/REQUIRE index 70e314a..8a3f6b8 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1 +1,2 @@ -julia 0.5- +julia 0.5 +Compat 0.18.0 diff --git a/src/StructIO.jl b/src/StructIO.jl index 0b37d2f..ae9c744 100644 --- a/src/StructIO.jl +++ b/src/StructIO.jl @@ -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 @@ -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] diff --git a/test/runtests.jl b/test/runtests.jl index cf7e898..6d25de2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,7 +1,8 @@ using StructIO +using Compat using Base.Test -@struct immutable TwoUInts +@io immutable TwoUInts x::UInt y::UInt end @@ -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