Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIFOBuffer does not follow read(::Any, ::Type{UInt8}) standard #41

Closed
omus opened this issue Apr 18, 2017 · 3 comments
Closed

FIFOBuffer does not follow read(::Any, ::Type{UInt8}) standard #41

omus opened this issue Apr 18, 2017 · 3 comments

Comments

@omus
Copy link
Contributor

omus commented Apr 18, 2017

I'm trying to use readbytes! with FIFOBuffer but I'm encountering errors since read(::FIFOBuffer, ::Type{UInt8}) returns a Tuple{UInt8,Bool} rather than the typical UInt8.

julia> using HTTP

julia> f = HTTP.FIFOBuffer(5);

julia> b = Array{UInt8}(3);

julia> write(f, [0x01, 0x02, 0x03, 0x04, 0x05])
5

julia> readbytes!(f, b)
ERROR: MethodError: Cannot `convert` an object of type Tuple{UInt8,Bool} to an object of type UInt8
This may have arisen from a call to the constructor UInt8(...),
since type constructors fall back to convert methods.
 in readbytes!(::HTTP.FIFOBuffer, ::Array{UInt8,1}, ::Int64) at ./io.jl:351
 in readbytes!(::HTTP.FIFOBuffer, ::Array{UInt8,1}) at ./io.jl:342

julia> io = IOBuffer([0x01, 0x02, 0x03, 0x04, 0x05])
IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=5, maxsize=Inf, ptr=1, mark=-1)

julia> readbytes!(io, b)
3

Could you use a different function name for this behaviour if it is required?

@quinnj
Copy link
Member

quinnj commented Apr 18, 2017

Yeah, it'd probably be better to call it something different. It started out returning like normal, but then I realized I needed to return more, but kept the function name the same.

@omus
Copy link
Contributor Author

omus commented Apr 18, 2017

I'm thinking that Base.read(f::FIFOBuffer, ::Type{Tuple{UInt8,Bool}}) would be appropriate.

@omus
Copy link
Contributor Author

omus commented Apr 18, 2017

I'm working on this at the moment as it's blocking some of my work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants