Example for using a PipeBuffer() ?

146 views
Skip to first unread message

Uwe Fechner

unread,
Mar 8, 2014, 8:34:42 AM3/8/14
to julia...@googlegroups.com
Hello,

I would like to convert the content of a pipebuffer int an array of Uint8.

My code so far:

    iob = PipeBuffer();
    write(iob, char(14))
    writeproto(iob, pub.state)


Now I want to print the content of iob as hex string for debugging.

I can use bytes2hex to convert an array of Uint8 to a hex string,
like in this example:

s="Hello world!"
bytes2hex(convert(Array{Uint8, 1}, s))


but I could not find a way to access the content of a PipeBuffer.

Any idea?

Regards:

Uwe

Ivar Nesje

unread,
Mar 8, 2014, 9:33:27 AM3/8/14
to julia...@googlegroups.com
Judging from base/iobuffer.jl, you can access iob.data to see the actual Uint8 array that backs a PipeBuffer.

Just note that type fields is not considered part of the exported and (somewhat) stable interface.

Ivar

Uwe Fechner

unread,
Mar 8, 2014, 9:41:47 AM3/8/14
to julia...@googlegroups.com
Thanks, iob.data works.

Is there a way in Julia to find out what are the field names of a Type, like the dir function in Python?

Best regards:

Uwe

Mike Innes

unread,
Mar 8, 2014, 10:20:20 AM3/8/14
to julia...@googlegroups.com
names(Type) may be what you are looking for, e.g. names(Complex) => [:re, :im]

Uwe Fechner

unread,
Mar 8, 2014, 11:41:39 AM3/8/14
to julia...@googlegroups.com
Thanks, this is working for me:

julia> iob = PipeBuffer()
IOBuffer([],true,true,false,true,0,9223372036854775807,1)

julia> names(iob)
8-element Array{Any,1}:
 :data   
 :readable
 :writable
 :seekable
 :append 
 :size   
 :maxsize
 :ptr    

julia>

Uwe

Ivar Nesje

unread,
Mar 8, 2014, 11:49:22 AM3/8/14
to julia...@googlegroups.com
Or you can search in the /base directory in the source. https://github.com/JuliaLang/julia/search?q=PipeBuffer&ref=cmdform&type=Code

Jameson Nash

unread,
Mar 8, 2014, 12:51:17 PM3/8/14
to julia...@googlegroups.com
None of the names in IOBuffer are part of the API since they mean something slightly different from what you expect in almost all cases (especially .data and .ptr)
Use real(im) instead of im.re
Use takebuf_array(iob) instead of iob.data or use readbytes(iob)

Uwe Fechner

unread,
Mar 8, 2014, 12:58:17 PM3/8/14
to julia...@googlegroups.com
All of this is really missing in the documentation.

Is there a Julia documentation project?

It would be nice to have a wiki where people could add examples how to use the functions, provided
by Julia.

Regards:

Uwe

Patrick O'Leary

unread,
Mar 8, 2014, 4:34:19 PM3/8/14
to julia...@googlegroups.com
The documentation is in a series of ReStructured Text files in the main repository, under the `doc` directory: https://github.com/JuliaLang/julia/tree/master/doc

Pull requests to improve the documentation are very welcomed, and usually quickly accepted.
Reply all
Reply to author
Forward
0 new messages