Sha256: 241e81a270f1be1b6743eff6273f01a424aff99f21f2a85d72f0ebd7ee8eaed9

Contents?: true

Size: 742 Bytes

Versions: 366

Compression:

Stored size: 742 Bytes

Contents

local function decode(bytes)
  local values = {}
  local n = 0
  for i, byte in ipairs(bytes) do
    n = n << 7
    n = n + (byte & 0x7f)
    if byte & 0x80 == 0 then
      table.insert(values, n)
      n = 0
    end
    assert((i ~= #bytes) or (byte & 0x80 == 0), 'incomplete byte sequence')
  end
  return values
end

local function encode_single(n)
  local bytes = { n & 0x7f }
  n = n >> 7
  while n > 0 do
    table.insert(bytes, 1, n & 0x7f | 0x80)
    n = n >> 7
  end
  return bytes
end

local function encode(values)
  local bytes = {}
  for _, value in ipairs(values) do
    for _, byte in ipairs(encode_single(value)) do
      table.insert(bytes, byte)
    end
  end
  return bytes
end

return { decode = decode, encode = encode }

Version data entries

366 entries across 366 versions & 1 rubygems

Version Path
trackler-2.2.1.98 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.97 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.96 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.95 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.94 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.93 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.92 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.91 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.90 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.89 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.88 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.87 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.86 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.85 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.84 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.83 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.82 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.81 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.80 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.79 tracks/lua/exercises/variable-length-quantity/example.lua