1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
from ..util.helpers import asbool
from ..varint import write_varint
from ..writer import write_binary_str
class SettingType(object):
@classmethod
def write(cls, value, buf):
raise NotImplementedError
class SettingUInt64(SettingType):
@classmethod
def write(cls, value, buf):
write_varint(int(value), buf)
class SettingBool(SettingType):
@classmethod
def write(cls, value, buf):
write_varint(asbool(value), buf)
class SettingString(SettingType):
@classmethod
def write(cls, value, buf):
write_binary_str(value, buf)
class SettingChar(SettingType):
@classmethod
def write(cls, value, buf):
write_binary_str(value[0], buf)
class SettingFloat(SettingType):
@classmethod
def write(cls, value, buf):
"""
Float is written in string representation.
"""
write_binary_str(str(value), buf)
class SettingMaxThreads(SettingUInt64):
@classmethod
def write(cls, value, buf):
if value == 'auto':
value = 0
super(SettingMaxThreads, cls).write(value, buf)
|