Consolidating code, work on read_records!

This commit is contained in:
2023-04-24 10:50:45 -04:00
parent 08964fdb53
commit 8665fd5bb4
3 changed files with 76 additions and 83 deletions
+19 -2
View File
@@ -1,6 +1,6 @@
module bytes
export byte_vec_to_int, byte_vec_to_string, bit_at
export byte_vec_to_int, byte_vec_to_string, bit_at, bit_vector
"""
read_data_size(size::Vector{UInt8})::Real
@@ -36,4 +36,21 @@ function bit_at(byte::UInt8, idx::Int64; t::Type=Int64)::Int64
end
end
# byte_vec_to_string(UInt8.(collect("ABC")))
# byte_vec_to_string(UInt8.(collect("ABC")))
function bit_vector(byte::UInt8; little_endian=false)::Vector{UInt8}
range = if little_endian
8:-1:1
else
1:1:8
end
s = bitstring(byte)
[parse(UInt8, s[b]) for b in range]
end
function bit_vector(byte_vector::Vector{UInt8}; little_endian=false)::Vector{UInt8}
vecs = [bit_vector(byte; little_endian=little_endian) for byte byte_vector]
reduce(vcat, vecs)
end