Skip to content

Commit

Permalink
Add overloads for Base.elsize and Base.strides to Message (#214)
Browse files Browse the repository at this point in the history
This is handy if deserializing a Message with MsgPack, which requires these
methods to be defined.
  • Loading branch information
JamesWrigley authored Mar 21, 2022
1 parent 00f5d8d commit 044d957
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/message.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ end
# Convert message to string (copies data)
Base.unsafe_string(zmsg::Message) = @preserve zmsg unsafe_string(pointer(zmsg), length(zmsg))

Base.elsize(::Message) = 1
Base.strides(::Message) = (1,)

# Build an IOStream from a message
# Copies the data
function Base.convert(::Type{IOStream}, zmsg::Message)
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ end
ZMQ.connect(s2, "tcp://localhost:5555")

msg = Message("test request")

# Smoke tests
@test Base.elsize(msg) == 1
@test Base.strides(msg) == (1,)

# Test similar() and copy() fixes in https://github.com/JuliaInterop/ZMQ.jl/pull/165
# Note that we have to send this message to work around
# https://github.com/JuliaInterop/ZMQ.jl/issues/166
Expand Down

0 comments on commit 044d957

Please sign in to comment.