All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.linkedin.dex.spec.Leb128.kt Maven / Gradle / Ivy

There is a newer version: 2.3.4
Show newest version
/**
 * Copyright (c) LinkedIn Corporation. All rights reserved. Licensed under the BSD-2 Clause license.
 * See LICENSE in the project root for license information.
 */
package com.linkedin.dex.spec

import java.nio.ByteBuffer

class Leb128 private constructor() {
    companion object {
        /**
         * Reads an unsigned integer from byteBuffer.
         */
        fun readUnsignedLeb128(byteBuffer: ByteBuffer): Int {
            var result = 0
            var current: Int
            var count = 0

            do {
                current = byteBuffer.get().toInt() and 0xff
                result = result or (current and 0x7f shl count * 7)
                count++
            } while (current and 0x80 == 0x80 && count < 5)

            if (current and 0x80 == 0x80) {
                throw DexException("invalid LEB128 sequence")
            }

            return result
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy