Example #1
0
def _field_def_val_for_FieldMetada(field):
    if field.is_struct() or field.is_array():
        return "&g%sMetadata" % field.typ.name()
    if field.is_bool():
        return ["0", "1"][field.val]
    if field.is_color():
        if field.val > 0xffffff:
            return "0x%08x" % field.val
        else:
            return "0x%06x" % field.val
    # Note: doesn't handle default values outside of uintptr_t range,
    # which is 32bits on 32-bit arch
    if field.is_signed():
        assert metadata.is_valid_signed(32, field.val)
        return str(field.val)
    if field.is_unsigned():
        assert metadata.is_valid_unsigned(32, field.val)
        return str(field.val)
    # TODO: too lazy to do proper utf8 conversion and escaping, so
    # just returning NULL. We use non-null only for testing
    if field.is_string():
        return "NULL"
    if field.is_float():
        return '"%s"' % str(field.val)
    assert False, "don't know how to serialize %s" % str(field.typ)
Example #2
0
def _field_def_val_for_FieldMetada(field):
    if field.is_struct() or field.is_array():
        return "&g%sMetadata" % field.typ.name()
    if field.is_bool():
        return ["0", "1"][field.val]
    if field.is_color():
        if field.val > 0xffffff:
            return "0x%08x" % field.val
        else:
            return "0x%06x" % field.val
    # Note: doesn't handle default values outside of uintptr_t range,
    # which is 32bits on 32-bit arch
    if field.is_signed():
        assert metadata.is_valid_signed(32, field.val)
        return str(field.val)
    if field.is_unsigned():
        assert metadata.is_valid_unsigned(32, field.val)
        return str(field.val)
    # TODO: too lazy to do proper utf8 conversion and escaping, so
    # just returning NULL. We use non-null only for testing
    if field.is_string():
        return "NULL"
    if field.is_float():
        return '"%s"' % str(field.val)
    assert False, "don't know how to serialize %s" % str(field.typ)