inline void encode()

in src/codecs/field_codecs.h [284:398]


    inline void encode(PyObject *field_value, DxApi::DataWriter &writer) {
        bool type_mismatch;
        bool exists = getInt64Value(field_value, value_, type_mismatch);
        if (type_mismatch)
            THROW_EXCEPTION("Wrong type of field '%s'. Required: INTEGER.", field_name_.c_str());
        if (!exists) {
            if (!is_nullable_) {
                THROW_EXCEPTION("Field '%s' is not nullable.", field_name_.c_str());
            }

            is_null_ = true;
            switch (field_size_) {
            case 8: {
                writer.writeInt8(DxApi::Constants::INT8_NULL);
            }
            break;
            case 16: {
                writer.writeInt16(DxApi::Constants::INT16_NULL);
            }
            break;
            case 30: {
                writer.writePUInt30(DxApi::UINT30_NULL);
            }
            break;
            case 32: {
                writer.writeInt32(DxApi::Constants::INT32_NULL);
            }
            break;
            case 48: {
                writer.writeInt48(DxApi::INT48_NULL);
            }
            break;
            case 61: {
                writer.writePUInt61(DxApi::UINT61_NULL);
            }
            break;
            case 64: {
                writer.writeInt64(DxApi::INT64_NULL);
            }
            break;
            default:
                THROW_EXCEPTION("Unknow size of integer: %d.", field_size_);
            }
        } else {
            substractRelative(value_);
            is_null_ = false;
            switch (field_size_)
            {
            case 8: {
                int8_t writeValue = (int8_t)value_;
                if (!is_nullable_ && writeValue == DxApi::Constants::INT8_NULL) {
                    THROW_EXCEPTION("Field '%s' is not nullable. Value '%d' is invalid.", field_name_.c_str(), writeValue);
                }

                writer.writeInt8(writeValue);
            }
            break;
            case 16: {
                int16_t writeValue = (int16_t)value_;
                if (!is_nullable_ && writeValue == DxApi::Constants::INT16_NULL) {
                    THROW_EXCEPTION("Field '%s' is not nullable. Value '%d' is invalid.", field_name_.c_str(), writeValue);
                }

                writer.writeInt16(writeValue);
            }
            break;
            case 30: {
                uint32_t writeValue = (uint32_t)value_;
                if (!is_nullable_ && writeValue == DxApi::Constants::UINT30_NULL) {
                    THROW_EXCEPTION("Field '%s' is not nullable. Value '%d' is invalid.", field_name_.c_str(), writeValue);
                }

                writer.writePUInt30(writeValue);
            }
            break;
            case 32: {
                uint32_t writeValue = (uint32_t)value_;
                if (!is_nullable_ && writeValue == DxApi::Constants::INT32_NULL) {
                    THROW_EXCEPTION("Field '%s' is not nullable. Value '%d' is invalid.", field_name_.c_str(), writeValue);
                }

                writer.writeInt32(writeValue);
            }
            break;
            case 48: {
                if (!is_nullable_ && value_ == DxApi::INT48_NULL) {
                    THROW_EXCEPTION("Field '%s' is not nullable. Value '%d' is invalid.", field_name_.c_str(), value_);
                }

                writer.writeInt48(value_);
            }
            break;
            case 61: {
                uint64_t writeValue = (uint64_t)value_;
                if (!is_nullable_ && writeValue == DxApi::UINT61_NULL) {
                    THROW_EXCEPTION("Field '%s' is not nullable. Value '%d' is invalid.", field_name_.c_str(), writeValue);
                }

                writer.writePUInt61((uint64_t)value_);
            }
            break;
            case 64: {
                if (!is_nullable_ && value_ == DxApi::INT64_NULL) {
                    THROW_EXCEPTION("Field '%s' is not nullable. Value '%d' is invalid.", field_name_.c_str(), value_);
                }

                writer.writeInt64(value_);
            }
            break;
            default:
                THROW_EXCEPTION("Unknow size of integer: %d.", field_size_);
            }
        }
       
    }