From 044d957ff4e4040e5f19049d1be1fea3f3565e9e Mon Sep 17 00:00:00 2001 From: James Wrigley Date: Mon, 21 Mar 2022 21:32:17 +0100 Subject: [PATCH] Add overloads for Base.elsize and Base.strides to Message (#214) This is handy if deserializing a Message with MsgPack, which requires these methods to be defined. --- src/message.jl | 3 +++ test/runtests.jl | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/message.jl b/src/message.jl index cdeb292..71e231a 100644 --- a/src/message.jl +++ b/src/message.jl @@ -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) diff --git a/test/runtests.jl b/test/runtests.jl index c6b91d5..f07d174 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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