Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ IF(DEFINED CMAKE_BUILD_TYPE)
ENDIF()

OPTION(WITH_DEBUG "Use dbug/safemutex" OFF)

OPTION(WITH_EXPERIMENTAL_UDT "With experimental user defined types" ON)

OPTION(CHECK_ERRMSG_FORMAT "Check printf format for English error messages" OFF)

OPTION(DISABLE_ALL_PSI "DISABLE all calls to the PSI interface" OFF)
Expand Down
34 changes: 34 additions & 0 deletions components/udt_example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (c) 2016, 2026, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is designed to work with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have either included with
# the program or referenced in the documentation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DISABLE_MISSING_PROFILE_WARNING()

ADD_DEFINITIONS(-DLOG_COMPONENT_TAG="udt_example")

MYSQL_ADD_COMPONENT(udt_example
udt_complex.cc
udt_example.cc
udt_log.cc
MODULE_ONLY
TEST_ONLY
)
82 changes: 82 additions & 0 deletions components/udt_example/udt_complex.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* Copyright (c) 2026, Oracle and/or its affiliates.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.

This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */

#include "udt_complex.h"

#include <cassert>
#include "my_byteorder.h"

// #include <rpc/xdr.h>

namespace udt_example {

#ifdef LATER
void Complex::serialize(enum xdr_op op, serialized_complex &buffer) {
{
XDR xdrs;

xdrmem_create(&xdrs, &buffer.buffer[0], sizeof(buffer.buffer), op);
xdr_double(&xdrs, &m_real);
xdr_double(&xdrs, &m_imaginary);
}

void Complex::serialize_from(serialized_complex & buffer) {
serialize(XDR_DECODE);
}

void Complex::serialize_to(serialized_complex & buffer) {
serialize(XDR_ENCODE);
}
#endif

void Complex::serialize_from(const serialized_complex &buffer) {
assert(sizeof(double) == 8);
const unsigned char *b = &buffer.buffer[0];

m_real = float8get(b);
m_imaginary = float8get(b + 8);
}

void Complex::serialize_to(serialized_complex & buffer) {
assert(sizeof(double) == 8);
unsigned char *b = &buffer.buffer[0];

float8store(b, m_real);
float8store(b + 8, m_imaginary);
}

Complex Complex::add(const Complex &a, const Complex &b) {
Complex result;
result.m_real = a.m_real + b.m_real;
result.m_imaginary = a.m_imaginary + b.m_imaginary;
return result;
}

Complex Complex::mul(const Complex &a, const Complex &b) {
Complex result;
result.m_real = a.m_real * b.m_real - a.m_imaginary * b.m_imaginary;
result.m_imaginary = a.m_real * b.m_imaginary + b.m_real * a.m_imaginary;
return result;
}

} // namespace udt_example
64 changes: 64 additions & 0 deletions components/udt_example/udt_complex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
Copyright (c) 2026, Oracle and/or its affiliates.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.

This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef UDT_COMPLEX_H_INCLUDED
#define UDT_COMPLEX_H_INCLUDED

#include <cstring>

namespace udt_example {

struct serialized_complex {
unsigned char buffer[16];

const unsigned char *ptr() { return &buffer[0]; }

unsigned int length() { return sizeof(buffer); }

void set(const unsigned char *ptr, unsigned int len) {
if (len == length()) {
std::memcpy(&buffer[0], ptr, len);
}
}
};

class Complex {
public:
Complex() : m_real(0.0), m_imaginary(0.0) {}
Complex(double r, double i) : m_real(r), m_imaginary(i) {}

void serialize_from(const serialized_complex &buffer);
void serialize_to(serialized_complex &buffer);

static Complex add(const Complex &a, const Complex &b);
static Complex mul(const Complex &a, const Complex &b);

double m_real;
double m_imaginary;
};

} // namespace udt_example

#endif /* UDT_EXAMPLE_LOG_H_INCLUDED */
Loading
Loading