--- a/hglib.lua Thu Sep 08 19:40:38 2016 +0800
+++ b/hglib.lua Thu Sep 08 20:46:39 2016 +0800
+local function decode_i4(bytestring)
+ local byte = bytestring:sub(i, i):byte()
+ value = value + byte * (2 ^ ((sizes.i4 - i) * 8))
+ if value >= 2 ^ (sizes.i4 * 8 - 1) then
+ value = value - 2 ^ (sizes.i4 * 8)
read_channel = read_channel,
--- a/spec/hglib_spec.lua Thu Sep 08 19:40:38 2016 +0800
+++ b/spec/hglib_spec.lua Thu Sep 08 20:46:39 2016 +0800
local hglib = require('hglib')
+describe('hglib helper functions', function()
+ describe('decode_i4', function()
+ it('can decode 0', function()
+ assert.are_equal(0, hglib.decode_i4('\0\0\0\0'))
+ it('can decode 255', function()
+ assert.are_equal(255, hglib.decode_i4('\0\0\0\255'))
+ it('can decode 256', function()
+ assert.are_equal(256, hglib.decode_i4('\0\0\1\0'))
+ it('can decode -1', function()
+ assert.are_equal(-1, hglib.decode_i4('\255\255\255\255'))
describe('hglib client', function()
it('can connect using just file handles', function()
local rh = io.open('spec/data/hello', 'rb')