varint.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. // This code is derived from code distributed as part of Google LevelDB.
  2. // The original is available in leveldb as util/coding.h.
  3. // This file was retrieved Jul 15, 2013 by Robert Escriva and imported into
  4. // libe. This code is copied/modified from libe.
  5. // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
  6. // Use of this source code is governed by a BSD-style license that can be
  7. // found in the LICENSE file. See the AUTHORS file for names of contributors.
  8. //
  9. // Endian-neutral encoding:
  10. // * Fixed-length numbers are encoded with least-significant byte first
  11. // * In addition we support variable length "varint" encoding
  12. // * Strings are encoded prefixed by their length in varint format
  13. #ifndef macaroons_varint_h_
  14. #define macaroons_varint_h_
  15. #include <inttypes.h>
  16. #define VARINT_MAX_SIZE 10
  17. unsigned char*
  18. packvarint(uint64_t value, unsigned char* ptr);
  19. const unsigned char*
  20. unpackvarint(const unsigned char* ptr,
  21. const unsigned char* end,
  22. uint64_t* value);
  23. unsigned
  24. varint_length(uint64_t v);
  25. #endif /* macaroons_varint_h_ */