local function u(u)local c={}local N=1 while u>=128 do local z=u%128 u=(u-z)/128 c[N]=z+128 N+=1 end c[N]=u return string.char(unpack(c))end local function c(u)local c=0 local N=0 while not u.eof()do local z=u.byte()if z<128 then c+=z*128^N break end c+=(z-128)*128^N N+=1 end return c end return{encode=u;decode=c}
local function encode(n)
	local out = {}
	local i = 1
	while n >= 0x80 do
		local b = n % 0x80
		n = (n - b) / 0x80
		out[i] = b + 0x80
		i += 1
	end
	out[i] = n
	return string.char(unpack(out))
end

local function decode(stream)
	local n = 0
	local i = 0
	while not stream.eof() do
		local b = stream.byte()
		if b < 0x80 then
			n += b * 0x80 ^ i
			break
		end
		n += (b - 0x80) * 0x80 ^ i
		i += 1
	end
	return n
end

return {
	encode = encode,
	decode = decode,
}
