Trivial: Fix two VarInt examples in serialize.h #8560

pull cbarcenas wants to merge 1 commits into bitcoin:master from cbarcenas:fix_varint_examples changing 1 files +2 −2
  1. cbarcenas commented at 12:56 AM on August 23, 2016: contributor

    Two of the VarInt examples given in the comments of serialize.h are wrong. This is a minor change to correct them.

    To verify, you can compute the VarInt encodings of 16511 and 65535 by hand or use the following test program (requires C++11):

    #include <iomanip>
    #include <iostream>
    #include <sstream>
    #include <vector>
    
    #include "serialize.h"
    
    int main()
    {
      std::vector<unsigned long long> inputs = {
        0, 1, 127, 128, 255, 256, 16383, 16384, 16511, 65535, (1LL << 32)
      };
    
      for (auto& input : inputs) {
        std::stringstream output;
    
        WriteVarInt(output, input);
    
        std::cout << std::dec << input << ':';
        int c;
        while ((c = output.get()) != EOF) {
          std::cout << " 0x" << std::hex << std::setw(2) << std::setfill('0') << c;
        }
        std::cout << std::endl;
      }
    }
    
  2. Trivial: Fix two VarInt examples in serialize.h 7bd5ff4623
  3. jonasschnelli added the label Docs and Output on Aug 23, 2016
  4. laanwj commented at 6:53 AM on August 23, 2016: member
    bitcoin/src$ g++ -std=c++11 test_serialize.cpp -o test_serialize -I. -DHAVE_CONFIG_H -I../build/src
    bitcoin/src$ ./test_serialize 
    0: 0x00
    1: 0x01
    127: 0x7f
    128: 0x80 0x00
    255: 0x80 0x7f
    256: 0x81 0x00
    16383: 0xfe 0x7f
    16384: 0xff 0x00
    16511: 0xff 0x7f
    65535: 0x82 0xfe 0x7f
    4294967296: 0x8e 0xfe 0xfe 0xff 0x00
    

    I may be misreading your comment, but 128 becomes 0x80 0x00, not 0xFF 0x7F? yes I did, it's some awkward two-column format, you have it correct

    tACK https://github.com/bitcoin/bitcoin/pull/8560/commits/7bd5ff46237b06b3cf223176c1c71ef66383fa92

  5. dcousens commented at 7:22 AM on August 23, 2016: contributor

    utACK 7bd5ff4

  6. sipa commented at 11:44 AM on August 23, 2016: member

    ACK 7bd5ff46237b06b3cf223176c1c71ef66383fa92, verified by hand

  7. paveljanik commented at 7:53 PM on August 23, 2016: contributor

    ACK https://github.com/bitcoin/bitcoin/pull/8560/commits/7bd5ff46237b06b3cf223176c1c71ef66383fa92

    Brilliant eye - never ever trust old comments 👍 Thank you!

  8. fanquake commented at 5:27 AM on August 24, 2016: member

    utACK 7bd5ff4

  9. sipa merged this on Aug 24, 2016
  10. sipa closed this on Aug 24, 2016

  11. sipa referenced this in commit f12d2b5a8a on Aug 24, 2016
  12. cbarcenas deleted the branch on Aug 24, 2016
  13. luke-jr referenced this in commit c493f43621 on Sep 21, 2016
  14. codablock referenced this in commit 9157f75d3f on Sep 19, 2017
  15. codablock referenced this in commit 49768bfa47 on Jan 9, 2018
  16. codablock referenced this in commit c9ebd95163 on Jan 9, 2018
  17. lateminer referenced this in commit a5d81ed4ec on Oct 21, 2018
  18. andvgal referenced this in commit 27761620cb on Jan 6, 2019
  19. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-22 18:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me