Skip to content

Commit

Permalink
Merge pull request #13 from kmsquire/kms/0.4_deprecations
Browse files Browse the repository at this point in the history
Fix 0.4 deprecations (closes #11, #12)
  • Loading branch information
kmsquire committed Jan 7, 2016
2 parents 15fcfac + 6a4ac29 commit 1fbe1ed
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 110 deletions.
23 changes: 8 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
language: cpp
compiler:
- clang
language: julia
os:
- osx
- linux
julia:
- nightly
- 0.4
- 0.3
notifications:
email: false
env:
matrix:
- JULIAVERSION="juliareleases"
- JULIAVERSION="julianightlies"
before_install:
- sudo add-apt-repository ppa:staticfloat/julia-deps -y
- sudo add-apt-repository ppa:staticfloat/${JULIAVERSION} -y
- sudo apt-get update -qq -y
- sudo apt-get install libpcre3-dev julia -y
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
script:
- julia -e 'Pkg.init(); Pkg.clone(pwd()); Pkg.test("MsgPack")'
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
julia 0.3
Compat
141 changes: 72 additions & 69 deletions src/MsgPack.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
module MsgPack

using Compat

export pack, unpack, Ext
import Base: ==

const INT_FP = 0x00 # - 0xf7
const MAP_F = 0x80 # - 0x8f
Expand Down Expand Up @@ -40,9 +43,9 @@ const INT_FN = 0xe0 # - 0xff

immutable Ext
typecode::Int8
data::Vector{Uint8}
data::Vector{UInt8}

function Ext(t::Integer, d::Vector{Uint8}; impltype=false)
function Ext(t::Integer, d::Vector{UInt8}; impltype=false)
# -128 to -1 reserved for implementation
if -128 <= t <= -1
impltype || error("MsgPack Ext typecode -128 through -1 reserved by implementation")
Expand All @@ -67,54 +70,54 @@ extdeserialize(e::Ext) = (e.typecode, deserialize(IOBuffer(e.data)))


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

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

const DISPATCH =
[ 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))
]
@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))
)

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

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

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

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

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


pack(s, ::Nothing) = write(s, NIL)
@compat 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, int8(v))
write(s, @compat Int8(v))
elseif v >= -2^7
wh(s, INT_8, int8(v))
wh(s, INT_8, @compat Int8(v))
elseif v >= -2^15
wh(s, INT_16, int16(v))
wh(s, INT_16, @compat Int16(v))
elseif v >= -2^31
wh(s, INT_32, int32(v))
wh(s, INT_32, @compat Int32(v))
elseif v >= -2^63
wh(s, INT_64, int64(v))
wh(s, INT_64, @compat Int64(v))
else
error("MsgPack signed int overflow")
end
else
if v <= 127
write(s, uint8(v))
write(s, @compat UInt8(v))
elseif v <= 2^8-1
wh(s, UINT_8, uint8(v))
wh(s, UINT_8, @compat UInt8(v))
elseif v <= 2^16-1
wh(s, UINT_16, uint16(v))
wh(s, UINT_16, @compat UInt16(v))
elseif v <= 2^32-1
wh(s, UINT_32, uint32(v))
elseif v <= uint64(2)^64-1
wh(s, UINT_64, uint64(v))
wh(s, UINT_32, @compat UInt32(v))
elseif v <= @compat UInt64(2)^64-1
wh(s, UINT_64, @compat UInt64(v))
else
error("MsgPack unsigned int overflow")
end
Expand All @@ -214,21 +217,21 @@ pack(s, v::Float32) = wh(s, 0xca, v)
pack(s, v::Float64) = wh(s, 0xcb, v)

# str format
pack(s, v::String) = begin
pack(s, v::AbstractString) = begin
n = sizeof(v)
if n < 2^5
write(s, STR_F | uint8(n))
## Note: with this section commented out, we do not have
## the most compact format for a string. However,
write(s, STR_F | @compat 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, uint8(n))
# wh(s, 0xd9, @compat UInt8(n))
elseif n < 2^16
wh(s, 0xda, uint16(n))
wh(s, 0xda, @compat UInt16(n))
elseif n < 2^32
wh(s, 0xdb, uint32(n))
wh(s, 0xdb, @compat UInt32(n))
else
error("MsgPack str overflow: ", n)
end
Expand All @@ -249,11 +252,11 @@ pack(s, v::Ext) = begin
elseif n == 16
write(s, 0xd8)
elseif n < 2^8
wh(s, 0xc7, uint8(n))
wh(s, 0xc7, @compat UInt8(n))
elseif n < 2^16
wh(s, 0xc8, uint16(n))
wh(s, 0xc8, @compat UInt16(n))
elseif n < 2^32
wh(s, 0xc9, uint32(n))
wh(s, 0xc9, @compat UInt32(n))
else
error("MsgPack ext overflow: ", n)
end
Expand All @@ -262,29 +265,29 @@ pack(s, v::Ext) = begin
end

# bin format
pack(s, v::Vector{Uint8}) = begin
pack(s, v::Vector{UInt8}) = begin
n = length(v)
if n < 2^8
wh(s, 0xc4, uint8(n))
wh(s, 0xc4, @compat UInt8(n))
elseif n < 2^16
wh(s, 0xc5, uint16(n))
wh(s, 0xc5, @compat UInt16(n))
elseif n < 2^32
wh(s, 0xc6, uint32(n))
wh(s, 0xc6, @compat UInt32(n))
else
error("MsgPack bin overflow: ", n)
end
write(s, v)
end

# Simple arrays
pack(s, v::Union(Vector, Tuple)) = begin
pack(s, @compat v::Union{Vector, Tuple}) = begin
n = length(v)
if n < 2^4
write(s, ARR_F | uint8(n))
write(s, ARR_F | @compat UInt8(n))
elseif n < 2^16
wh(s, 0xdc, uint16(n))
wh(s, 0xdc, @compat UInt16(n))
elseif n < 2^32
wh(s, 0xdd, uint32(n))
wh(s, 0xdd, @compat UInt32(n))
else
error("MsgPack array overflow: ", n)
end
Expand All @@ -298,11 +301,11 @@ end
pack(s, v::Dict) = begin
n = length(v)
if n < 2^4
write(s, MAP_F | uint8(n))
write(s, MAP_F | @compat UInt8(n))
elseif n < 2^16
wh(s, 0xde, uint16(n))
wh(s, 0xde, @compat UInt16(n))
elseif n < 2^32
wh(s, 0xdf, uint32(n))
wh(s, 0xdf, @compat UInt32(n))
else
error("MsgPack map overflow: ", n)
end
Expand Down
Loading

0 comments on commit 1fbe1ed

Please sign in to comment.