Skip to content

Commit cf7c3fe

Browse files
committed
add Memory(data::Vector{UInt8}) constructor
1 parent 0068ff2 commit cf7c3fe

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/memory.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ struct Memory
1111
size::UInt
1212
end
1313

14+
function Memory(data::Vector{UInt8})
15+
return Memory(pointer(data), sizeof(data))
16+
end
17+
1418
function Base.length(mem::Memory)
1519
return mem.size
1620
end

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ using Base.Test
2323
@test mem[3] === UInt8('!')
2424
@test_throws BoundsError mem[7] = 0x00
2525
@test_throws BoundsError mem[0] = 0x00
26+
27+
data = b"foobar"
28+
mem = TranscodingStreams.Memory(data)
29+
@test mem isa TranscodingStreams.Memory
30+
@test mem.ptr == pointer(data)
31+
@test mem.size == sizeof(data)
2632
end
2733

2834
@testset "Identity Codec" begin

0 commit comments

Comments
 (0)