Guest User

Untitled

a guest
Jun 4th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. pub fn uvarint(buf: []u8) !u64 {
  2. var x: u64 = 0;
  3. var s: u64 = 0;
  4.  
  5. for (buf) |i, b| {
  6. if (b < 0x80) {
  7. if (i > 9 or (i == 9 and b > 1)) {
  8. return error.Overflow;
  9. }
  10. return x | (u64)(b) << s;
  11. }
  12. x |= (u64)(b & 0x7f) << s;
  13. s += 7;
  14. }
  15. return error.BufferTooSmall;
  16. }
  17.  
  18.  
  19. test "varint" {
  20.  
  21. var buf_data = []u8{1, 2, 3, 4};
  22. var buf = buf_data[0..];
  23. const x = uvarint(buf);
  24.  
  25. }
  26.  
  27.  
  28. Output:
  29.  
  30.  
  31. zig/std/varint.zig:12:36: error: expected type 'u6', found 'u64'
  32. return x | (u64)(b) << s;
  33. ^
Add Comment
Please, Sign In to add comment