Skip to content

Commit beb6f34

Browse files
authored
Merge pull request #25 from JuliaComputing/tan/misc
use constructors where possible instead of `convert` methods, updates logging, add Project.toml
2 parents cb80f84 + d69782e commit beb6f34

14 files changed

+130
-108
lines changed

.juliarun_ci.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

.travis.yml

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
1-
# Documentation: http://docs.travis-ci.com/user/languages/julia/
21
language: julia
3-
sudo: required
2+
43
os:
54
- linux
5+
6+
# this lets us have more RAM that we need to run multiple parallel julia processes
7+
sudo: required
8+
dist: xenial
9+
610
julia:
711
- 1.0
12+
- 1.1
13+
- 1.2
14+
- 1.3
815
- nightly
9-
services:
10-
- rabbitmq
16+
17+
addons:
18+
apt:
19+
packages:
20+
- rabbitmq-server
21+
22+
matrix:
23+
allow_failures:
24+
- julia: nightly
25+
1126
notifications:
1227
email: false
28+
1329
# uncomment the following lines to override the default test script
14-
script:
15-
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
16-
- julia --inline=no -e 'using Pkg; Pkg.clone(pwd()); Pkg.build("AMQPClient"); Pkg.test("AMQPClient"; coverage=true)'
30+
#script:
31+
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
32+
# - julia --inline=no -e 'using Pkg; Pkg.clone(pwd()); Pkg.build("AMQPClient"); Pkg.test("AMQPClient"; coverage=true)'
33+
1734
after_success:
18-
# push coverage results to Coveralls
19-
- julia -e 'cd(using Pkg; Pkg.dir("AMQPClient")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
20-
# push coverage results to Codecov
21-
- julia -e 'cd(using Pkg; Pkg.dir("AMQPClient")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
35+
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())';
36+
# - julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())';

Project.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name = "AMQPClient"
2+
uuid = "79c8b4cd-a41a-55fa-907c-fab5288e1383"
3+
keywords = ["amqpclient", "rabbitmq", "amqp", "amqp-client", "message-queue"]
4+
license = "MIT"
5+
desc = "A Julia AMQP (Advanced Message Queuing Protocol) / RabbitMQ Client."
6+
version = "0.3.0"
7+
8+
[deps]
9+
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
10+
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
11+
12+
[compat]
13+
julia = "1"
14+
15+
[extras]
16+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
17+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
18+
19+
[targets]
20+
test = ["Test", "Random"]

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
[![Build Status](https://travis-ci.org/JuliaComputing/AMQPClient.jl.svg?branch=master)](https://travis-ci.org/JuliaComputing/AMQPClient.jl)
44
[![Coverage Status](https://coveralls.io/repos/JuliaComputing/AMQPClient.jl/badge.svg?branch=master&service=github)](https://coveralls.io/github/JuliaComputing/AMQPClient.jl?branch=master)
5-
[![codecov.io](http://codecov.io/github/JuliaComputing/AMQPClient.jl/coverage.svg?branch=master)](http://codecov.io/github/JuliaComputing/AMQPClient.jl?branch=master)
65

76
A Julia [AMQP (Advanced Message Queuing Protocol)](http://www.amqp.org/) Client.
87

REQUIRE

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/AMQPClient.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ import Base: write, read, read!, close, convert, show, isopen
44

55
using Sockets
66

7-
const DEBUG = false
8-
9-
# 0.7: use builtin logging by enabling following statement
10-
# using Logging; Logging.global_logger(Logging.ConsoleLogger(stderr, Logging.Debug))
11-
macro debug(s)
12-
esc(:(DEBUG && Base.@debug($s)))
13-
end
14-
157
# Client property info that gets sent to the server on connection startup
168
const CLIENT_IDENTIFICATION = Dict{String,Any}(
179
"product" => "Julia AMQPClient",

src/auth.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
function auth_resp_amqplain(auth_params::Dict{String,Any})
22
params = Dict{String,Any}("LOGIN" => auth_params["LOGIN"], "PASSWORD" => auth_params["PASSWORD"])
33
iob = IOBuffer()
4-
write(iob, convert(TAMQPFieldTable, params))
4+
write(iob, TAMQPFieldTable(params))
55
bytes = take!(iob)
66
skipbytes = sizeof(fieldtype(TAMQPFieldTable, :len))
77
bytes = bytes[(skipbytes+1):end]
8-
convert(TAMQPLongStr, bytes)
8+
TAMQPLongStr(bytes)
99
end
1010

1111
const AUTH_PROVIDERS = Dict{String,Function}("AMQPLAIN" => auth_resp_amqplain)

src/convert.jl

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,8 @@
1-
convert(::Type{Any}, s::T) where {T<:Union{TAMQPShortStr,TAMQPLongStr,TAMQPByteArray}} = convert(String, s)
2-
convert(::Type{String}, s::T) where {T<:Union{TAMQPShortStr,TAMQPLongStr,TAMQPByteArray}} = String(copy(convert(Vector{UInt8}, s.data)))
3-
convert(::Type{T}, s::AbstractString) where {T<:Union{TAMQPShortStr,TAMQPLongStr,TAMQPByteArray}} = T(length(s), Vector{UInt8}(codeunits(String(s))))
4-
convert(::Type{TAMQPLongStr}, d::Vector{UInt8}) = TAMQPLongStr(length(d), d)
5-
convert(::Type{TAMQPByteArray}, d::Vector{UInt8}) = TAMQPByteArray(length(d), d)
6-
7-
convert(::Type{TAMQPFieldValue{T}}, v::T) where {T} = TAMQPFieldValue{T}(FieldIndicatorMap[T], v)
8-
9-
as_fval(v::T) where {T} = convert(TAMQPFieldValue{T}, v)
10-
as_fval(v::Dict{String,Any}) = convert(TAMQPFieldValue{TAMQPFieldTable}, convert(TAMQPFieldTable, v))
11-
as_fval(v::String) = convert(TAMQPFieldValue{TAMQPLongStr}, convert(TAMQPLongStr, v))
12-
13-
convert(::Type{Any}, t::TAMQPFieldTable) = convert(Dict{Any,Any}, t)
14-
convert(::Type{Dict{K,V}}, t::TAMQPFieldTable) where {K, V} = Dict{K,V}(f.name => f.val for f in t.data)
15-
convert(::Type{Dict{String, String}}, t::TAMQPFieldTable) = Dict{String, String}(String(copy(f.name.data)) => String(copy(f.val.fld.data)) for f in t.data)
16-
function convert(::Type{TAMQPFieldTable}, d::Dict{String,Any})
17-
data = TAMQPFieldValuePair[]
18-
for (n,v) in d
19-
push!(data, TAMQPFieldValuePair(convert(TAMQPShortStr,n), as_fval(v)))
20-
end
21-
TAMQPFieldTable(length(data), data)
22-
end
23-
24-
convert(::Type{Any}, t::TAMQPFieldArray) = convert(Vector, t)
25-
convert(::Type{Vector{T}}, t::TAMQPFieldArray) where {T} = convert(Vector{T}, t.data)
26-
1+
convert(::Type{String}, s::T) where {T<:Union{TAMQPShortStr,TAMQPLongStr,TAMQPByteArray}} = String(copy(s.data))
272
convert(::Type{Bool}, b::TAMQPBit) = Bool(b.val & 0x1)
28-
convert(::Type{TAMQPBit}, b::Bool) = TAMQPBit(convert(UInt8, b))
29-
convert(::Type{TAMQPBit}, b::T) where {T<:Integer} = convert(TAMQPBit, Bool(b))
3+
4+
simplify(val::T) where {T <: Union{TAMQPShortStr,TAMQPLongStr,TAMQPByteArray}} = String(copy(val.data))
5+
simplify(val::TAMQPFieldArray) = [simplify(elem) for elem in val.data]
6+
simplify(table::TAMQPFieldTable) = Dict{String,Any}(simplify(f.name)=>simplify(f.val) for f in table.data)
7+
simplify(val::TAMQPFieldValue) = simplify(val.fld)
8+
simplify(x) = x

src/message.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ function set_properties(msg::Message; kwargs...)
5252
if v === nothing
5353
delete!(msg.properties, k)
5454
else
55-
msg.properties[k] = convert(PROPERTIES[k].typ, v)
55+
# all possible property types have constructors that can be used to create them
56+
msg.properties[k] = (PROPERTIES[k].typ)(v)
5657
end
5758
end
5859
nothing

0 commit comments

Comments
 (0)