Hi, I'm looking for an elegant way to find a seque...
# android
l
Hi, I'm looking for an elegant way to find a sequence of bytes in a byte array, e.g. find the sequence [0xFF] [0xFF] [0xFF] [0xFF]. Can someone help me?
v
Maybe windowed with a window size of 4 and then searching for your 4 byte sequence in the windows?
☝️ 2
l
@Vampire Can you give me some pseudo code? Edit: I'm fine. Was wondering how to compare the byte arrays, but found
contentEquals
Thanks for the fast reply
v
yw
e
a substring matching algorithm like Knuth-Morris-Pratt or Aho-Corasick can be more efficient
👍 1
I don't know if any existing implementations for Kotlin on ByteArray but if you're literally searching for [0xFF x 4] a tiny inline automaton is easy
l
Thanks a lot. Appreciated 🙏
138 Views