class Protobuf::Field::VarintField
def self.cached_varint(value)
Because all tags and enums are calculated as VarInt it is "most common" to have
def self.cached_varint(value) @_varint_cache ||= {} (@_varint_cache[value] ||= encode(value, false)).dup end
def self.default
def self.default 0 end
def self.encode(value, use_cache = true)
def self.encode(value, use_cache = true) return cached_varint(value) if use_cache && value >= 0 && value <= CACHE_LIMIT bytes = [] until value < 128 bytes << (0x80 | (value & 0x7f)) value >>= 7 end (bytes << value).pack('C*') end
def acceptable?(val)
def acceptable?(val) int_val = coerce!(val) int_val >= self.class.min && int_val <= self.class.max rescue false end
def coerce!(val)
def coerce!(val) return val.to_i if val.is_a?(Numeric) Integer(val, 10) end
def decode(value)
def decode(value) value end
def encode(value)
def encode(value) ::Protobuf::Field::VarintField.encode(value) end
def wire_type
def wire_type ::Protobuf::WireType::VARINT end