Skip to content

Commit

Permalink
Merge pull request #25 from JuliaComputing/tan/misc
Browse files Browse the repository at this point in the history
use constructors where possible instead of `convert` methods, updates logging, add Project.toml
  • Loading branch information
tanmaykm authored Nov 25, 2019
2 parents cb80f84 + d69782e commit beb6f34
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 108 deletions.
8 changes: 0 additions & 8 deletions .juliarun_ci.sh

This file was deleted.

37 changes: 26 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
# Documentation: http://docs.travis-ci.com/user/languages/julia/
language: julia
sudo: required

os:
- linux

# this lets us have more RAM that we need to run multiple parallel julia processes
sudo: required
dist: xenial

julia:
- 1.0
- 1.1
- 1.2
- 1.3
- nightly
services:
- rabbitmq

addons:
apt:
packages:
- rabbitmq-server

matrix:
allow_failures:
- julia: nightly

notifications:
email: false

# uncomment the following lines to override the default test script
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia --inline=no -e 'using Pkg; Pkg.clone(pwd()); Pkg.build("AMQPClient"); Pkg.test("AMQPClient"; coverage=true)'
#script:
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
# - julia --inline=no -e 'using Pkg; Pkg.clone(pwd()); Pkg.build("AMQPClient"); Pkg.test("AMQPClient"; coverage=true)'

after_success:
# push coverage results to Coveralls
- julia -e 'cd(using Pkg; Pkg.dir("AMQPClient")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
# push coverage results to Codecov
- julia -e 'cd(using Pkg; Pkg.dir("AMQPClient")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())';
# - julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())';
20 changes: 20 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name = "AMQPClient"
uuid = "79c8b4cd-a41a-55fa-907c-fab5288e1383"
keywords = ["amqpclient", "rabbitmq", "amqp", "amqp-client", "message-queue"]
license = "MIT"
desc = "A Julia AMQP (Advanced Message Queuing Protocol) / RabbitMQ Client."
version = "0.3.0"

[deps]
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"

[compat]
julia = "1"

[extras]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Random"]
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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

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

Expand Down
1 change: 0 additions & 1 deletion REQUIRE

This file was deleted.

8 changes: 0 additions & 8 deletions src/AMQPClient.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ import Base: write, read, read!, close, convert, show, isopen

using Sockets

const DEBUG = false

# 0.7: use builtin logging by enabling following statement
# using Logging; Logging.global_logger(Logging.ConsoleLogger(stderr, Logging.Debug))
macro debug(s)
esc(:(DEBUG && Base.@debug($s)))
end

# Client property info that gets sent to the server on connection startup
const CLIENT_IDENTIFICATION = Dict{String,Any}(
"product" => "Julia AMQPClient",
Expand Down
4 changes: 2 additions & 2 deletions src/auth.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
function auth_resp_amqplain(auth_params::Dict{String,Any})
params = Dict{String,Any}("LOGIN" => auth_params["LOGIN"], "PASSWORD" => auth_params["PASSWORD"])
iob = IOBuffer()
write(iob, convert(TAMQPFieldTable, params))
write(iob, TAMQPFieldTable(params))
bytes = take!(iob)
skipbytes = sizeof(fieldtype(TAMQPFieldTable, :len))
bytes = bytes[(skipbytes+1):end]
convert(TAMQPLongStr, bytes)
TAMQPLongStr(bytes)
end

const AUTH_PROVIDERS = Dict{String,Function}("AMQPLAIN" => auth_resp_amqplain)
35 changes: 7 additions & 28 deletions src/convert.jl
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
convert(::Type{Any}, s::T) where {T<:Union{TAMQPShortStr,TAMQPLongStr,TAMQPByteArray}} = convert(String, s)
convert(::Type{String}, s::T) where {T<:Union{TAMQPShortStr,TAMQPLongStr,TAMQPByteArray}} = String(copy(convert(Vector{UInt8}, s.data)))
convert(::Type{T}, s::AbstractString) where {T<:Union{TAMQPShortStr,TAMQPLongStr,TAMQPByteArray}} = T(length(s), Vector{UInt8}(codeunits(String(s))))
convert(::Type{TAMQPLongStr}, d::Vector{UInt8}) = TAMQPLongStr(length(d), d)
convert(::Type{TAMQPByteArray}, d::Vector{UInt8}) = TAMQPByteArray(length(d), d)

convert(::Type{TAMQPFieldValue{T}}, v::T) where {T} = TAMQPFieldValue{T}(FieldIndicatorMap[T], v)

as_fval(v::T) where {T} = convert(TAMQPFieldValue{T}, v)
as_fval(v::Dict{String,Any}) = convert(TAMQPFieldValue{TAMQPFieldTable}, convert(TAMQPFieldTable, v))
as_fval(v::String) = convert(TAMQPFieldValue{TAMQPLongStr}, convert(TAMQPLongStr, v))

convert(::Type{Any}, t::TAMQPFieldTable) = convert(Dict{Any,Any}, t)
convert(::Type{Dict{K,V}}, t::TAMQPFieldTable) where {K, V} = Dict{K,V}(f.name => f.val for f in t.data)
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)
function convert(::Type{TAMQPFieldTable}, d::Dict{String,Any})
data = TAMQPFieldValuePair[]
for (n,v) in d
push!(data, TAMQPFieldValuePair(convert(TAMQPShortStr,n), as_fval(v)))
end
TAMQPFieldTable(length(data), data)
end

convert(::Type{Any}, t::TAMQPFieldArray) = convert(Vector, t)
convert(::Type{Vector{T}}, t::TAMQPFieldArray) where {T} = convert(Vector{T}, t.data)

convert(::Type{String}, s::T) where {T<:Union{TAMQPShortStr,TAMQPLongStr,TAMQPByteArray}} = String(copy(s.data))
convert(::Type{Bool}, b::TAMQPBit) = Bool(b.val & 0x1)
convert(::Type{TAMQPBit}, b::Bool) = TAMQPBit(convert(UInt8, b))
convert(::Type{TAMQPBit}, b::T) where {T<:Integer} = convert(TAMQPBit, Bool(b))

simplify(val::T) where {T <: Union{TAMQPShortStr,TAMQPLongStr,TAMQPByteArray}} = String(copy(val.data))
simplify(val::TAMQPFieldArray) = [simplify(elem) for elem in val.data]
simplify(table::TAMQPFieldTable) = Dict{String,Any}(simplify(f.name)=>simplify(f.val) for f in table.data)
simplify(val::TAMQPFieldValue) = simplify(val.fld)
simplify(x) = x
3 changes: 2 additions & 1 deletion src/message.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function set_properties(msg::Message; kwargs...)
if v === nothing
delete!(msg.properties, k)
else
msg.properties[k] = convert(PROPERTIES[k].typ, v)
# all possible property types have constructors that can be used to create them
msg.properties[k] = (PROPERTIES[k].typ)(v)
end
end
nothing
Expand Down
Loading

2 comments on commit beb6f34

@tanmaykm
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/5862

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.0 -m "<description of version>" beb6f34be968f17c7395d7e8127adb31001159bd
git push origin v0.3.0

Please sign in to comment.