Alex Deymo | 4fd22ea | 2018-02-15 16:13:28 +0100 | [diff] [blame] | 1 | // Copyright 2018 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Tianjie Xu | 6528812 | 2017-10-13 15:10:58 -0700 | [diff] [blame] | 5 | #include "bsdiff/utils.h" |
| 6 | |
| 7 | namespace bsdiff { |
| 8 | |
Tianjie Xu | 6528812 | 2017-10-13 15:10:58 -0700 | [diff] [blame] | 9 | int64_t ParseInt64(const uint8_t* buf) { |
Kelvin Zhang | 9e1d2fe | 2021-04-19 19:47:48 -0400 | [diff] [blame] | 10 | // BSPatch uses a non-standard encoding of integers. |
| 11 | // Highest bit of that integer is used as a sign bit, 1 = negative |
| 12 | // and 0 = positive. |
| 13 | // Therefore, if the highest bit is set, flip it, then do 2's complement |
| 14 | // to get the integer in standard form |
Tianjie Xu | 6528812 | 2017-10-13 15:10:58 -0700 | [diff] [blame] | 15 | int64_t result = buf[7] & 0x7F; |
| 16 | for (int i = 6; i >= 0; i--) { |
| 17 | result <<= 8; |
| 18 | result |= buf[i]; |
| 19 | } |
| 20 | |
| 21 | if (buf[7] & 0x80) |
| 22 | result = -result; |
| 23 | return result; |
| 24 | } |
| 25 | |
Tianjie Xu | 1f1cdb2 | 2017-11-20 11:05:55 -0800 | [diff] [blame] | 26 | } // namespace bsdiff |