Enfernuz/protobuf-lua

Inappropriate use of the uint32 value checker to handle the uint64 type.

Enfernuz opened this issue · 1 comments

Currently the binding does not handle uint64 values that are greater than 2^32 - 1. The reason for this is that in init.lua both for uint32 and uint64 the checker Uint32ValueChecker is used:

[FieldDescriptor.CPPTYPE_UINT32] = type_checkers.Uint32ValueChecker()
[FieldDescriptor.CPPTYPE_UINT64] = type_checkers.Uint32ValueChecker()

and the max value in the Uint32ValueChecker is 2^32 - 1:

function Uint32ValueChecker()
  local _MIN = 0
  local _MAX = 0xffffffff
  return function(proposed_value)
    if type(proposed_value) ~= 'number' then
      error(string.format('%s has type %s, but expected one of: number',
                          proposed_value, type(proposed_value)))
    end
    if _MIN > proposed_value or proposed_value > _MAX then
      error('Value out of range: ' .. proposed_value)
    end
  end
end

Fixed in a64e02c.