@@ -23,9 +23,31 @@ function gc_free_fn(data::Ptr{Cvoid}, hint::Ptr{Cvoid})
23
23
end
24
24
25
25
"""
26
- High-level Message object for sending/receiving ZMQ messages in shared buffers.
26
+ mutable struct Message <: AbstractArray{UInt8, 1}
27
+
28
+ High-level `Message` object for sending/receiving ZMQ messages in shared
29
+ buffers. As an `AbstractArray`, it supports common (non-resizeable) array
30
+ behaviour.
31
+
32
+ # Examples
33
+ ```jldoctest
34
+ julia> using ZMQ
35
+
36
+ julia> m = Message("foo");
37
+
38
+ julia> Char(m[1]) # Array indexing
39
+ 'f': ASCII/Unicode U+0066 (category Ll: Letter, lowercase)
40
+
41
+ julia> m[end] = Int('g'); # Array assignment
42
+
43
+ julia> unsafe_string(m) # Conversion to string (only do this if you know the message is a string)
44
+ "fog"
45
+
46
+ julia> IOBuffer(m) # Create a zero-copy IOBuffer
47
+ IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=3, maxsize=Inf, ptr=1, mark=-1)
48
+ ```
27
49
"""
28
- mutable struct Message <: AbstractArray{UInt8,1}
50
+ mutable struct Message <: AbstractArray{UInt8, 1}
29
51
# Matching the declaration in the header: char _[64];
30
52
w_padding:: _Message
31
53
handle:: Ptr{Cvoid} # index into gc_protect, if any
@@ -164,6 +186,7 @@ Base.strides(::Message) = (1,)
164
186
# Build an IOStream from a message
165
187
# Copies the data
166
188
function Base. convert (:: Type{IOStream} , zmsg:: Message )
189
+ Base. depwarn (" convert(IOStream, ::Message) is deprecated, use `IOBuffer(zmsg)` instead to make a zero-copy IOBuffer from a Message." , :convert )
167
190
s = IOBuffer ()
168
191
write (s, zmsg)
169
192
return s
0 commit comments