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.180 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.179 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.178 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.177 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.176 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.175 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.174 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.173 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.172 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.171 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.170 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.169 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.167 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.166 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.165 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.164 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.163 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.162 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.161 tracks/lua/exercises/variable-length-quantity/example.lua
trackler-2.2.1.160 tracks/lua/exercises/variable-length-quantity/example.lua