summaryrefslogtreecommitdiffstats
path: root/libdex
diff options
context:
space:
mode:
authorAndy McFadden <>2009-03-24 20:41:52 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-24 20:41:52 -0700
commitd45a88794c6470d96e2139cbe803002d9d5d3a6c (patch)
treeeb76d5cfe8073b07c71838ab85dcd381a7a8cfea /libdex
parentbe67c30dd6aaa833e130e723f5810ee7789694ea (diff)
downloadandroid_dalvik-d45a88794c6470d96e2139cbe803002d9d5d3a6c.tar.gz
android_dalvik-d45a88794c6470d96e2139cbe803002d9d5d3a6c.tar.bz2
android_dalvik-d45a88794c6470d96e2139cbe803002d9d5d3a6c.zip
Automated import from //branches/master/...@141645,141645
Diffstat (limited to 'libdex')
-rw-r--r--libdex/Leb128.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/libdex/Leb128.h b/libdex/Leb128.h
index 215ae3025..41799fe5e 100644
--- a/libdex/Leb128.h
+++ b/libdex/Leb128.h
@@ -124,4 +124,41 @@ int readAndVerifyUnsignedLeb128(const u1** pStream, const u1* limit,
*/
int readAndVerifySignedLeb128(const u1** pStream, const u1* limit, bool* okay);
+
+/*
+ * Writes a 32-bit value in unsigned ULEB128 format.
+ *
+ * Returns the updated pointer.
+ */
+DEX_INLINE u1* writeUnsignedLeb128(u1* ptr, u4 data)
+{
+ while (true) {
+ u1 out = data & 0x7f;
+ if (out != data) {
+ *ptr++ = out | 0x80;
+ data >>= 7;
+ } else {
+ *ptr++ = out;
+ break;
+ }
+ }
+
+ return ptr;
+}
+
+/*
+ * Returns the number of bytes needed to encode "val" in ULEB128 form.
+ */
+DEX_INLINE int unsignedLeb128Size(u4 data)
+{
+ int count = 0;
+
+ do {
+ data >>= 7;
+ count++;
+ } while (data != 0);
+
+ return count;
+}
+
#endif