Skip to content

Commit

Permalink
Merge pull request #16 from kmsquire/kms/compat_updates
Browse files Browse the repository at this point in the history
Remove residual uses of Compat
  • Loading branch information
kmsquire committed Dec 23, 2016
2 parents 6b5f4ec + e95f40f commit 4f0934e
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 83 deletions.
14 changes: 12 additions & 2 deletions .travis.yml
@@ -1,9 +1,19 @@
# Documentation: http://docs.travis-ci.com/user/languages/julia/
language: julia
os:
- osx
- linux
- osx
julia:
- release
- nightly
- 0.5
notifications:
email: false
# uncomment the following lines to override the default test script
#script:
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
# - julia -e 'Pkg.clone(pwd()); Pkg.build("MsgPack"); Pkg.test("MsgPack"; coverage=true)'
after_success:
# push coverage results to Coveralls
- julia -e 'cd(Pkg.dir("MsgPack")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
# push coverage results to Codecov
- julia -e 'cd(Pkg.dir("MsgPack")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
8 changes: 7 additions & 1 deletion README.md
Expand Up @@ -2,6 +2,12 @@

[![Build Status](https://travis-ci.org/kmsquire/MsgPack.jl.svg?branch=master)](https://travis-ci.org/kmsquire/MsgPack.jl)

[![Build Status](https://ci.appveyor.com/api/projects/status/93qbkbnqh0fn9qr4?svg=true)](https://ci.appveyor.com/project/kmsquire/msgpack-jl)

[![Coverage Status](https://coveralls.io/repos/kmsquire/MsgPack.jl/badge.svg?branch=master&service=github)](https://coveralls.io/github/kmsquire/MsgPack.jl?branch=master)

[![codecov.io](http://codecov.io/github/kmsquire/MsgPack.jl/coverage.svg?branch=master)](http://codecov.io/github/kmsquire/MsgPack.jl?branch=master)

Provides basic support for the [msgpack](http://msgpack.org) format.

```
Expand Down Expand Up @@ -93,7 +99,7 @@ MsgPack reserves typecodes in the range `[-128, -1]` for future types specified
```julia
julia> Ext(-43, Uint8[1, 5, 3, 9])
ERROR: MsgPack Ext typecode -128 through -1 reserved by implementation
in call at /Users/sean/.julia/v0.4/MsgPack/src/MsgPack.jl:48
in call at /Users/sean/.julia/v0.4/MsgPack/src/MsgPack.jl:48

julia> Ext(-43, Uint8[1, 5, 3, 9], impltype=true)
MsgPack.Ext(-43,UInt8[0x01,0x05,0x03,0x09])
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
@@ -1,2 +1,2 @@
julia 0.5
Compat
Compat 0.9.5
34 changes: 34 additions & 0 deletions appveyor.yml
@@ -0,0 +1,34 @@
environment:
matrix:
- JULIAVERSION: "julialang/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe"

branches:
only:
- master
- /release-.*/

notifications:
- provider: Email
on_build_success: false
on_build_failure: false
on_build_status_changed: false

install:
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$("http://s3.amazonaws.com/"+$env:JULIAVERSION),
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia

build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"MsgPack\"); Pkg.build(\"MsgPack\")"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"MsgPack\")"
140 changes: 70 additions & 70 deletions src/MsgPack.jl
@@ -1,6 +1,6 @@
module MsgPack

using Compat
import Compat: take!, xor

export pack, unpack, Ext
import Base: ==
Expand Down Expand Up @@ -70,54 +70,54 @@ extdeserialize(e::Ext) = (e.typecode, deserialize(IOBuffer(e.data)))


readn(s, t) = ntoh(read(s, t))
readi(s, t) = @compat Int64(readn(s, t))
readi(s, t) = Int64(readn(s, t))

readu64(s, t) = begin
v = @compat UInt64(readn(s, t))
v = UInt64(readn(s, t))
if v > 2^63-1
v
else
@compat Int64(v)
Int64(v)
end
end

const DISPATCH =
@compat Dict( NIL => s -> nothing
,UNUSED => s -> error("unused")
,FALSE => s -> false
,TRUE => s -> true
,BIN_8 => s -> unpack_bin(s, readn(s, UInt8))
,BIN_16 => s -> unpack_bin(s, readn(s, UInt16))
,BIN_32 => s -> unpack_bin(s, readn(s, UInt32))
,EXT_8 => s -> unpack_ext(s, readn(s, UInt8))
,EXT_16 => s -> unpack_ext(s, readn(s, UInt16))
,EXT_32 => s -> unpack_ext(s, readn(s, UInt32))
,FLOAT_32 => s -> readn(s, Float32)
,FLOAT_64 => s -> readn(s, Float64)
,UINT_8 => s -> readi(s, UInt8)
,UINT_16 => s -> readi(s, UInt16)
,UINT_32 => s -> readi(s, UInt32)
,UINT_64 => s -> readu64(s, UInt64)
,INT_8 => s -> readi(s, Int8)
,INT_16 => s -> readi(s, Int16)
,INT_32 => s -> readi(s, Int32)
,INT_64 => s -> readi(s, Int64)
,STR_8 => s -> unpack_str(s, readn(s, UInt8))
,STR_16 => s -> unpack_str(s, readn(s, UInt16))
,STR_32 => s -> unpack_str(s, readn(s, UInt32))
,ARR_16 => s -> unpack_arr(s, readn(s, UInt16))
,ARR_32 => s -> unpack_arr(s, readn(s, UInt32))
,MAP_16 => s -> unpack_map(s, readn(s, UInt16))
,MAP_32 => s -> unpack_map(s, readn(s, UInt32))
)
Dict(NIL => s -> nothing,
UNUSED => s -> error("unused"),
FALSE => s -> false,
TRUE => s -> true,
BIN_8 => s -> unpack_bin(s, readn(s, UInt8)),
BIN_16 => s -> unpack_bin(s, readn(s, UInt16)),
BIN_32 => s -> unpack_bin(s, readn(s, UInt32)),
EXT_8 => s -> unpack_ext(s, readn(s, UInt8)),
EXT_16 => s -> unpack_ext(s, readn(s, UInt16)),
EXT_32 => s -> unpack_ext(s, readn(s, UInt32)),
FLOAT_32 => s -> readn(s, Float32),
FLOAT_64 => s -> readn(s, Float64),
UINT_8 => s -> readi(s, UInt8),
UINT_16 => s -> readi(s, UInt16),
UINT_32 => s -> readi(s, UInt32),
UINT_64 => s -> readu64(s, UInt64),
INT_8 => s -> readi(s, Int8),
INT_16 => s -> readi(s, Int16),
INT_32 => s -> readi(s, Int32),
INT_64 => s -> readi(s, Int64),
STR_8 => s -> unpack_str(s, readn(s, UInt8)),
STR_16 => s -> unpack_str(s, readn(s, UInt16)),
STR_32 => s -> unpack_str(s, readn(s, UInt32)),
ARR_16 => s -> unpack_arr(s, readn(s, UInt16)),
ARR_32 => s -> unpack_arr(s, readn(s, UInt32)),
MAP_16 => s -> unpack_map(s, readn(s, UInt16)),
MAP_32 => s -> unpack_map(s, readn(s, UInt32))
)

unpack(s) = unpack(IOBuffer(s))
unpack(s::IO) = begin
b = read(s, UInt8)

if b <= 0x7f
# positive fixint
@compat Int64(b)
Int64(b)

elseif b <= 0x8f
# fixmap
Expand All @@ -140,7 +140,7 @@ unpack(s::IO) = begin

else
# negative fixint
@compat Int64(reinterpret(Int8, b))
Int64(reinterpret(Int8, b))
end
end

Expand Down Expand Up @@ -178,35 +178,35 @@ pack(v) = begin
end


@compat pack(s, ::Void) = write(s, NIL)
pack(s, ::Void) = write(s, NIL)
pack(s, v::Bool) = if v write(s, TRUE) else write(s, FALSE) end

pack(s, v::Integer) = begin
if v < 0
if v >= -32
write(s, @compat Int8(v))
write(s, Int8(v))
elseif v >= -2^7
wh(s, INT_8, @compat Int8(v))
wh(s, INT_8, Int8(v))
elseif v >= -2^15
wh(s, INT_16, @compat Int16(v))
wh(s, INT_16, Int16(v))
elseif v >= -2^31
wh(s, INT_32, @compat Int32(v))
elseif v >= -2^63
wh(s, INT_64, @compat Int64(v))
wh(s, INT_32, Int32(v))
elseif v >= -Int64(2)^63
wh(s, INT_64, Int64(v))
else
error("MsgPack signed int overflow")
end
else
if v <= 127
write(s, @compat UInt8(v))
write(s, UInt8(v))
elseif v <= 2^8-1
wh(s, UINT_8, @compat UInt8(v))
wh(s, UINT_8, UInt8(v))
elseif v <= 2^16-1
wh(s, UINT_16, @compat UInt16(v))
elseif v <= 2^32-1
wh(s, UINT_32, @compat UInt32(v))
elseif v <= @compat UInt64(2)^64-1
wh(s, UINT_64, @compat UInt64(v))
wh(s, UINT_16, UInt16(v))
elseif v <= UInt64(2)^32-1
wh(s, UINT_32, UInt32(v))
elseif v <= UInt64(2)^64-1
wh(s, UINT_64, UInt64(v))
else
error("MsgPack unsigned int overflow")
end
Expand All @@ -220,18 +220,18 @@ pack(s, v::Float64) = wh(s, 0xcb, v)
pack(s, v::AbstractString) = begin
n = sizeof(v)
if n < 2^5
write(s, STR_F | @compat UInt8(n))
write(s, STR_F | UInt8(n))
## Note: with this section commented out, we do not have
## the most compact format for a string. However,
## the string is still in spec, and some other
## msgpack libaries (*ahem* Python) can't decode
## strings created with this rule.
#elseif n < 2^8
# wh(s, 0xd9, @compat UInt8(n))
# wh(s, 0xd9, UInt8(n))
elseif n < 2^16
wh(s, 0xda, @compat UInt16(n))
elseif n < 2^32
wh(s, 0xdb, @compat UInt32(n))
wh(s, 0xda, UInt16(n))
elseif n < UInt64(2)^32
wh(s, 0xdb, UInt32(n))
else
error("MsgPack str overflow: ", n)
end
Expand All @@ -252,11 +252,11 @@ pack(s, v::Ext) = begin
elseif n == 16
write(s, 0xd8)
elseif n < 2^8
wh(s, 0xc7, @compat UInt8(n))
wh(s, 0xc7, UInt8(n))
elseif n < 2^16
wh(s, 0xc8, @compat UInt16(n))
elseif n < 2^32
wh(s, 0xc9, @compat UInt32(n))
wh(s, 0xc8, UInt16(n))
elseif n < UInt64(2)^32
wh(s, 0xc9, UInt32(n))
else
error("MsgPack ext overflow: ", n)
end
Expand All @@ -268,26 +268,26 @@ end
pack(s, v::Vector{UInt8}) = begin
n = length(v)
if n < 2^8
wh(s, 0xc4, @compat UInt8(n))
wh(s, 0xc4, UInt8(n))
elseif n < 2^16
wh(s, 0xc5, @compat UInt16(n))
elseif n < 2^32
wh(s, 0xc6, @compat UInt32(n))
wh(s, 0xc5, UInt16(n))
elseif n < UInt64(2)^32
wh(s, 0xc6, UInt32(n))
else
error("MsgPack bin overflow: ", n)
end
write(s, v)
end

# Simple arrays
pack(s, @compat v::Union{Vector, Tuple}) = begin
pack(s, v::Union{Vector, Tuple}) = begin
n = length(v)
if n < 2^4
write(s, ARR_F | @compat UInt8(n))
write(s, ARR_F | UInt8(n))
elseif n < 2^16
wh(s, 0xdc, @compat UInt16(n))
elseif n < 2^32
wh(s, 0xdd, @compat UInt32(n))
wh(s, 0xdc, UInt16(n))
elseif n < UInt64(2)^32
wh(s, 0xdd, UInt32(n))
else
error("MsgPack array overflow: ", n)
end
Expand All @@ -301,11 +301,11 @@ end
pack(s, v::Dict) = begin
n = length(v)
if n < 2^4
write(s, MAP_F | @compat UInt8(n))
write(s, MAP_F | UInt8(n))
elseif n < 2^16
wh(s, 0xde, @compat UInt16(n))
elseif n < 2^32
wh(s, 0xdf, @compat UInt32(n))
wh(s, 0xde, UInt16(n))
elseif n < UInt64(2)^32
wh(s, 0xdf, UInt32(n))
else
error("MsgPack map overflow: ", n)
end
Expand Down
17 changes: 8 additions & 9 deletions test/runtests.jl
@@ -1,6 +1,5 @@
using MsgPack
using Base.Test
using Compat

ck_pack(a, b) = pack(a) == b && unpack(b) == a

Expand All @@ -20,8 +19,8 @@ ck_pack(a, b) = pack(a) == b && unpack(b) == a
# UInt32
@test ck_pack(2^16, [0xce,0x00,0x01,0x00,0x00])
# UInt64
@test ck_pack(2^32, [0xcf,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00])
@test ck_pack((@compat UInt64(2)^64-1), [0xcf,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff])
@test ck_pack(UInt64(2)^32, [0xcf,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00])
@test ck_pack(UInt64(2)^64-1, [0xcf,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff])

# negative fixint
@test ck_pack(-5, [0xfb])
Expand All @@ -36,11 +35,11 @@ ck_pack(a, b) = pack(a) == b && unpack(b) == a
@test ck_pack(-2^16, [0xd2,0xff,0xff,0x00,0x00])
@test ck_pack(-2^31, [0xd2,0x80,0x00,0x00,0x00])
# Int64
@test ck_pack(-2^32, [0xd3,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00])
@test ck_pack(-2^63, [0xd3,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00])
@test ck_pack(-Int64(2)^32, [0xd3,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00])
@test ck_pack(-Int64(2)^63, [0xd3,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00])

# Float32
@test ck_pack((@compat Float32(5.876)), [0xca, 0x40, 0xbc, 0x08, 0x31])
@test ck_pack((Float32(5.876)), [0xca, 0x40, 0xbc, 0x08, 0x31])
# Float64
@test ck_pack(0.654789321, [0xcb, 0x3f, 0xe4, 0xf4, 0x08, 0xbb, 0xee, 0xe1, 0xa8])

Expand Down Expand Up @@ -72,7 +71,7 @@ b = rand(UInt8, 2^20)
b = []

# fixarray
@test ck_pack(Any[1, (@compat Float32(2)), UInt8[0x22, 0x54]],
@test ck_pack(Any[1, (Float32(2)), UInt8[0x22, 0x54]],
[0x93, 0x01, 0xca, 0x40, 0x00, 0x00, 0x00, 0xc4, 0x02, 0x22, 0x54])
@test ck_pack(Any[nothing, "heya", true, false],
[0x94, 0xc0, 0xa4, 0x68, 0x65, 0x79, 0x61, 0xc3, 0xc2])
Expand All @@ -82,11 +81,11 @@ b = []
# tuple
@test pack(Any[(1, [true, false], UInt8[0xff, 0xde])]) ==
[0x91, 0x93, 0x01, 0x92, 0xc3, 0xc2, 0xc4, 0x02, 0xff, 0xde]
@test pack(("hi", ((@compat Float32(2)), 0xff))) ==
@test pack(("hi", ((Float32(2)), 0xff))) ==
[0x92, 0xa2, 0x68, 0x69, 0x92, 0xca, 0x40, 0x00, 0x00, 0x00, 0xcc, 0xff]

# fixmap
@test ck_pack((@compat Dict(1=>2, "hi"=>"mom")),
@test ck_pack((Dict(1=>2, "hi"=>"mom")),
[0x82,0xa2,0x68,0x69,0xa3,0x6d,0x6f,0x6d,0x01,0x02])

# fixext 1
Expand Down

0 comments on commit 4f0934e

Please sign in to comment.