Pieter Wuille
4d6144f97f
Compact serialization for variable-length integers
...
Variable-length integers: bytes are a MSB base-128 encoding of the number.
The high bit in each byte signifies whether another digit follows. To make
the encoding is one-to-one, one is subtracted from all but the last digit.
Thus, the byte sequence a[] with length len, where all but the last byte
has bit 128 set, encodes the number:
(a[len-1] & 0x7F) + sum(i=1..len-1, 128^i*((a[len-i-1] & 0x7F)+1))
Properties:
* Very small (0-127: 1 byte, 128-16511: 2 bytes, 16512-2113663: 3 bytes)
* Every integer has exactly one encoding
* Encoding does not depend on size of original integer type
2012-10-20 23:08:56 +02:00
..
2012-10-20 23:08:56 +02:00
2012-04-27 10:14:33 -04:00
2012-10-20 01:54:10 +02:00
2012-10-20 23:08:56 +02:00
2012-09-18 15:07:58 -04:00
2012-09-18 15:07:58 -04:00
2012-08-28 17:13:11 -04:00
2012-08-28 17:04:54 -04:00
2012-08-23 06:55:35 +02:00
2012-09-18 15:07:58 -04:00
2012-09-10 04:24:57 +02:00
2012-10-05 23:31:58 +02:00
2012-10-04 15:49:15 +02:00
2012-08-21 22:50:00 -04:00
2012-05-18 22:02:28 +08:00
2012-10-09 12:37:35 -04:00
2012-05-18 22:02:28 +08:00
2012-08-23 06:55:35 +02:00
2012-08-23 06:55:35 +02:00
2012-10-08 17:46:45 -04:00
2012-10-08 17:46:45 -04:00
2012-10-20 01:54:10 +02:00
2012-06-12 07:21:03 +02:00
2012-10-07 14:38:37 +02:00
2012-05-18 22:02:28 +08:00
2012-10-08 17:46:45 -04:00
2012-09-15 12:10:00 +02:00
2012-05-24 20:26:19 +02:00
2012-05-24 20:26:19 +02:00
2012-10-20 23:08:56 +02:00
2012-10-20 23:08:56 +02:00
2012-10-20 13:36:36 -07:00
2012-10-20 01:54:10 +02:00
2012-10-20 23:08:56 +02:00
2012-10-20 23:08:56 +02:00
2012-10-20 23:08:56 +02:00
2012-10-20 23:08:56 +02:00
2012-06-19 09:48:00 +03:00
2012-10-11 00:39:51 -07:00
2012-10-20 01:54:10 +02:00
2012-10-11 00:41:33 -07:00
2012-10-11 00:41:33 -07:00
2012-06-12 07:21:03 +02:00
2012-05-18 22:02:28 +08:00
2012-07-04 16:40:16 +02:00
2012-10-04 15:49:15 +02:00
2012-10-04 15:49:15 +02:00
2012-10-04 15:49:15 +02:00
2012-09-18 15:07:58 -04:00
2012-10-20 10:56:04 -07:00
2012-10-07 07:03:06 -07:00
2012-10-20 10:56:04 -07:00
2012-09-21 01:24:25 +02:00
2012-10-20 23:08:56 +02:00
2012-09-18 15:07:58 -04:00
2012-09-25 12:16:37 +02:00
2012-06-25 12:28:29 +08:00
2012-09-10 04:24:57 +02:00
2012-10-11 00:42:47 -07:00
2012-10-01 19:45:41 +02:00
2012-09-07 16:08:18 +02:00
2012-09-07 16:08:18 +02:00
2012-10-08 17:46:45 -04:00
2012-10-08 17:46:45 -04:00
2012-10-08 17:46:45 -04:00
2012-10-08 17:46:45 -04:00