Skip to content

Instantly share code, notes, and snippets.

@soc
Created April 16, 2015 16:51
Show Gist options
  • Save soc/d2adf0f48e036507df58 to your computer and use it in GitHub Desktop.
Save soc/d2adf0f48e036507df58 to your computer and use it in GitHub Desktop.
/** Returns the size and the remaining vector. */
def segmentBodySize(vector: ByteVector): (Int, ByteVector) = {
def loop(index: Int = 0, accum: Int = 0): (Int, ByteVector) = {
val value = (vector(index) & 0xFF)
if (value != 255) {
(value + accum, vector.drop(index + 1))
} else {
loop(value + accum, index + 1)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment