private void initializeSchemaVariantWithDefaultValue()

in java/core/src/main/java/org/bondlib/StructBondType.java [581:630]


    private void initializeSchemaVariantWithDefaultValue(Variant variant, StructField field) {
        variant.nothing = field.isDefaultNothing();
        if (!variant.nothing) {
            switch (field.fieldType.getBondDataType().value) {
                case BondDataType.Values.BT_UINT8:
                case BondDataType.Values.BT_UINT16:
                case BondDataType.Values.BT_UINT32:
                case BondDataType.Values.BT_UINT64:
                    variant.uint_value = ((Number) field.getDefaultValue()).longValue();
                    break;

                case BondDataType.Values.BT_INT8:
                case BondDataType.Values.BT_INT16:
                case BondDataType.Values.BT_INT64:
                    variant.int_value = ((Number) field.getDefaultValue()).longValue();
                    break;

                case BondDataType.Values.BT_INT32:
                    // could be an enum
                    if (field.fieldType instanceof EnumBondType) {
                        variant.int_value = ((BondEnum) field.getDefaultValue()).getValue();
                    } else {
                        variant.int_value = (Integer) field.getDefaultValue();
                    }
                    break;

                case BondDataType.Values.BT_BOOL:
                    // bool is piggy-backing on the int value
                    variant.int_value = (Boolean) field.getDefaultValue() ? 1 : 0;
                    break;

                case BondDataType.Values.BT_FLOAT:
                case BondDataType.Values.BT_DOUBLE:
                    variant.double_value = ((Number) field.getDefaultValue()).doubleValue();
                    break;

                case BondDataType.Values.BT_STRING:
                    variant.string_value = (String) field.getDefaultValue();
                    break;

                case BondDataType.Values.BT_WSTRING:
                    variant.wstring_value = (String) field.getDefaultValue();
                    break;

                default:
                    // the default is null for structs and containers
                    break;
            }
        }
    }