Consolidating code, work on read_records!
This commit is contained in:
+19
-2
@@ -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
|
||||
Reference in New Issue
Block a user