diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 0f388e8f..8f757577 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -13,6 +13,7 @@ FROM ${DEVCONTAINER_BASE} as file-normalizer COPY environment.yml \ .devcontainer/devcontainer.bashrc \ + .devcontainer/matlab-r2023b.ubuntu-22.04.dependencies.txt \ /data/ RUN chmod -R 555 /data/ @@ -116,3 +117,61 @@ RUN . /opt/conda/etc/profile.d/conda.sh \ && mkdir -p /home/vscode/.local/share/CMakeTools \ && echo "[{\"name\":\"Conda\",\"compilers\":{\"C\":\"$GCC\",\"CXX\":\"$GXX\"}}]" > /home/vscode/.local/share/CMakeTools/cmake-tools-kits.json \ && chown vscode:conda /home/vscode/.local/share/CMakeTools/cmake-tools-kits.json + + +######################################################### +# Install Matlab +# Based on mathworks/{matlab-deps:r2023b,matlab:r2023b} +# +# Configure the Matlab License Server to use Matlab within the devcontainer (including VSCode extensions): +# In your HOST environment, export the environment variable MATLAB_LICENSE_FILE, e.g. +# export MATLAB_LICENSE_FILE=/mnt/c/Users/username/Documents/MATLAB/license.lic +######################################################### + +ENV DEBIAN_FRONTEND="noninteractive" TZ="Etc/UTC" + +COPY --from=file-normalizer /data/matlab-r2023b.ubuntu-22.04.dependencies.txt /tmp/matlab-dependencies.txt + +RUN export DEBIAN_FRONTEND=noninteractive \ + && apt-get update \ + && apt-get install --no-install-recommends --yes \ + `cat /tmp/matlab-dependencies.txt` \ + wget \ + unzip \ + ca-certificates \ + && apt-get clean \ + && apt-get -y autoremove \ + && rm -rf /var/lib/apt/lists/* + +RUN [ -d /usr/share/X11/xkb ] || mkdir -p /usr/share/X11/xkb + +ARG MATLAB_RELEASE=r2023b +ARG MATLAB_PRODUCT_LIST="MATLAB" +ARG MATLAB_INSTALL_LOCATION="/opt/matlab/${MATLAB_RELEASE}" +ARG LICENSE_SERVER= + +RUN adduser --shell /bin/bash --disabled-password --gecos "" matlab \ + && echo "matlab ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/matlab \ + && chmod 0440 /etc/sudoers.d/matlab + +USER matlab +WORKDIR /home/matlab + +ENV MLM_LICENSE_FILE=${LICENSE_SERVER} + +RUN wget -q https://www.mathworks.com/mpm/glnxa64/mpm \ + && chmod +x mpm \ + && sudo HOME=${HOME} ./mpm install \ + --release=${MATLAB_RELEASE} \ + --destination=${MATLAB_INSTALL_LOCATION} \ + --products ${MATLAB_PRODUCT_LIST} \ + || (echo "MPM Installation Failure. See below for more information:" && cat /tmp/mathworks_root.log && false) \ + && sudo rm -f mpm /tmp/mathworks_root.log \ + && sudo ln -s ${MATLAB_INSTALL_LOCATION}/bin/matlab /usr/local/bin/matlab \ + && sudo ln -s ${MATLAB_INSTALL_LOCATION} /opt/matlab/latest \ + && sudo mkdir -p ${MATLAB_INSTALL_LOCATION}/licenses + +# Install workaround run-matlab-command script to unify local and CI invocations of `matlab -batch` +# See https://github.com/matlab-actions/run-command/issues/53 +RUN sudo wget -O /usr/local/bin/run-matlab-command https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/glnxa64/run-matlab-command \ + && sudo chmod +x /usr/local/bin/run-matlab-command diff --git a/.devcontainer/devcontainer-on-create.sh b/.devcontainer/devcontainer-on-create.sh new file mode 100755 index 00000000..ae7c7b4e --- /dev/null +++ b/.devcontainer/devcontainer-on-create.sh @@ -0,0 +1,11 @@ +#! /usr/bin/env bash + +set -euo pipefail + +host_license_file="/tmp/matlab.host.lic" + +if [ -s "${host_license_file}" ]; then + # We don't bind mount directly to $MATLAB_LICENSE_FILE so that we can write + # to it later without affecting the host. + sudo cp "${host_license_file}" "${MATLAB_LICENSE_FILE}" +fi diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4842ec73..3e500711 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -6,12 +6,19 @@ "dockerfile": "Dockerfile", "context": ".." }, - "runArgs": ["--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"], + "runArgs": [ + "--cap-add=SYS_PTRACE", + "--security-opt", + "seccomp=unconfined", + "--network=host" + ], "overrideCommand": false, "mounts": [ // Bind mount docker socket under an alias to support docker-from-docker - "source=/var/run/docker.sock,target=/var/run/docker-host.sock,type=bind" + "source=/var/run/docker.sock,target=/var/run/docker-host.sock,type=bind", + "source=${localEnv:MATLAB_LICENSE_FILE:/dev/null},target=/tmp/matlab.host.lic,type=bind,readonly" ], + "onCreateCommand": ".devcontainer/devcontainer-on-create.sh", "remoteUser": "vscode", // Configure tool-specific properties. @@ -102,6 +109,7 @@ "JacquesLucke.gcov-viewer", "jinliming2.vscode-go-template", "matepek.vscode-catch2-test-adapter", + "mathworks.language-matlab", "mhutchie.git-graph", "ms-python.black-formatter", "ms-python.python", @@ -118,6 +126,7 @@ "containerEnv": { "PYTHONPATH": "/workspaces/yardl/python", - "CGO_ENABLED": "0" + "CGO_ENABLED": "0", + "MATLAB_LICENSE_FILE": "/opt/matlab/latest/licenses/license.lic" } } diff --git a/.devcontainer/matlab-r2023b.ubuntu-22.04.dependencies.txt b/.devcontainer/matlab-r2023b.ubuntu-22.04.dependencies.txt new file mode 100644 index 00000000..230ba3f5 --- /dev/null +++ b/.devcontainer/matlab-r2023b.ubuntu-22.04.dependencies.txt @@ -0,0 +1,44 @@ +ca-certificates +libasound2 +libc6 +libcairo-gobject2 +libcairo2 +libcap2 +libcups2 +libdrm2 +libgbm1 +libgdk-pixbuf-2.0-0 +libgl1 +libglib2.0-0 +libgstreamer-plugins-base1.0-0 +libgstreamer1.0-0 +libgtk-3-0 +libice6 +libltdl7 +libnspr4 +libnss3 +libpam0g +libpango-1.0-0 +libpangocairo-1.0-0 +libpangoft2-1.0-0 +libsndfile1 +libuuid1 +libwayland-client0 +libxcomposite1 +libxcursor1 +libxdamage1 +libxfixes3 +libxft2 +libxinerama1 +libxrandr2 +libxt6 +libxtst6 +libxxf86vm1 +locales +locales-all +make +net-tools +procps +sudo +unzip +zlib1g \ No newline at end of file diff --git a/.github/actions/configure-environment/action.yml b/.github/actions/configure-environment/action.yml index 03fd2377..9b03f338 100644 --- a/.github/actions/configure-environment/action.yml +++ b/.github/actions/configure-environment/action.yml @@ -44,7 +44,22 @@ runs: if: steps.cache-conda.outputs.cache-hit != 'true' - - uses: actions/setup-go@v4 + - name: Setup Go + uses: actions/setup-go@v4 with: go-version: '1.21.3' cache-dependency-path: tooling/go.sum + + - name: Setup Matlab + uses: matlab-actions/setup-matlab@v2 + with: + release: R2022b + cache: true + + # Workaround to running `matlab -batch` from within justfile and Python + # See: https://github.com/matlab-actions/run-command/issues/53 + - name: Get run-matlab-command + shell: bash + run: | + wget -O /usr/local/bin/run-matlab-command https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/glnxa64/run-matlab-command + chmod +x /usr/local/bin/run-matlab-command diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef4f1cad..90c5a663 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,7 +35,7 @@ jobs: uses: ./.github/actions/configure-environment - name: Build and test - run: just cpp_version=${{ matrix.cppVersion }} validate-with-no-changes + run: just cpp_version=${{ matrix.cppVersion }} matlab=enabled validate-with-no-changes buildBinaries: name: Build yardl binaries diff --git a/.gitignore b/.gitignore index 381b10e4..191f3b17 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,5 @@ cpp/build/ cpp/sandbox/generated/ **/*.bin + +matlab_workspace.mat diff --git a/README.md b/README.md index 7aba2871..bb950242 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,16 @@ $ just from the repo root. +To enable support for Matlab, you must provide a Matlab license file to the devcontainer. +In your HOST environment, export the environment variable `MATLAB_LICENSE_FILE`, +e.g. in `$HOME/.profile` + +```bash +export MATLAB_LICENSE_FILE=/mnt/c/Users/username/Documents/MATLAB/license.lic +``` + +Then invoke `just matlab=enabled ...`. + ## Contributing This project welcomes contributions and suggestions. Most contributions require diff --git a/cpp/test/benchmark.cc b/cpp/test/benchmark.cc index 38001b32..7631e5e1 100644 --- a/cpp/test/benchmark.cc +++ b/cpp/test/benchmark.cc @@ -310,7 +310,7 @@ std::optional> GetScenarioFunction(std::string sce int main(int argc, char* argv[]) { if (argc != 3) { - std::cerr << "Incorrect number of arguments. Usage: banchmark " << std::endl; + std::cerr << "Incorrect number of arguments. Usage: benchmark " << std::endl; return 1; } diff --git a/cpp/test/generated/binary/protocols.cc b/cpp/test/generated/binary/protocols.cc index 55163ae6..75a664d2 100644 --- a/cpp/test/generated/binary/protocols.cc +++ b/cpp/test/generated/binary/protocols.cc @@ -547,13 +547,14 @@ struct IsTriviallySerializable { IsTriviallySerializable::value && IsTriviallySerializable::value && IsTriviallySerializable::value && + IsTriviallySerializable::value && IsTriviallySerializable::value && IsTriviallySerializable::value && IsTriviallySerializable::value && IsTriviallySerializable::value && IsTriviallySerializable::value && - (sizeof(__T__) == (sizeof(__T__::array_field) + sizeof(__T__::array_field_map_dimensions) + sizeof(__T__::dynamic_array_field) + sizeof(__T__::fixed_array_field) + sizeof(__T__::int_field) + sizeof(__T__::int8_field) + sizeof(__T__::uint8_field) + sizeof(__T__::int16_field) + sizeof(__T__::uint16_field) + sizeof(__T__::uint32_field) + sizeof(__T__::int64_field) + sizeof(__T__::uint64_field) + sizeof(__T__::size_field) + sizeof(__T__::float32_field) + sizeof(__T__::float64_field) + sizeof(__T__::complexfloat32_field) + sizeof(__T__::complexfloat64_field) + sizeof(__T__::string_field) + sizeof(__T__::tuple_field) + sizeof(__T__::vector_field) + sizeof(__T__::vector_of_vectors_field) + sizeof(__T__::fixed_vector_field) + sizeof(__T__::optional_named_array) + sizeof(__T__::int_float_union) + sizeof(__T__::nullable_int_float_union) + sizeof(__T__::union_with_nested_generic_union) + sizeof(__T__::map_field))) && - offsetof(__T__, array_field) < offsetof(__T__, array_field_map_dimensions) && offsetof(__T__, array_field_map_dimensions) < offsetof(__T__, dynamic_array_field) && offsetof(__T__, dynamic_array_field) < offsetof(__T__, fixed_array_field) && offsetof(__T__, fixed_array_field) < offsetof(__T__, int_field) && offsetof(__T__, int_field) < offsetof(__T__, int8_field) && offsetof(__T__, int8_field) < offsetof(__T__, uint8_field) && offsetof(__T__, uint8_field) < offsetof(__T__, int16_field) && offsetof(__T__, int16_field) < offsetof(__T__, uint16_field) && offsetof(__T__, uint16_field) < offsetof(__T__, uint32_field) && offsetof(__T__, uint32_field) < offsetof(__T__, int64_field) && offsetof(__T__, int64_field) < offsetof(__T__, uint64_field) && offsetof(__T__, uint64_field) < offsetof(__T__, size_field) && offsetof(__T__, size_field) < offsetof(__T__, float32_field) && offsetof(__T__, float32_field) < offsetof(__T__, float64_field) && offsetof(__T__, float64_field) < offsetof(__T__, complexfloat32_field) && offsetof(__T__, complexfloat32_field) < offsetof(__T__, complexfloat64_field) && offsetof(__T__, complexfloat64_field) < offsetof(__T__, string_field) && offsetof(__T__, string_field) < offsetof(__T__, tuple_field) && offsetof(__T__, tuple_field) < offsetof(__T__, vector_field) && offsetof(__T__, vector_field) < offsetof(__T__, vector_of_vectors_field) && offsetof(__T__, vector_of_vectors_field) < offsetof(__T__, fixed_vector_field) && offsetof(__T__, fixed_vector_field) < offsetof(__T__, optional_named_array) && offsetof(__T__, optional_named_array) < offsetof(__T__, int_float_union) && offsetof(__T__, int_float_union) < offsetof(__T__, nullable_int_float_union) && offsetof(__T__, nullable_int_float_union) < offsetof(__T__, union_with_nested_generic_union) && offsetof(__T__, union_with_nested_generic_union) < offsetof(__T__, map_field); + (sizeof(__T__) == (sizeof(__T__::array_field) + sizeof(__T__::array_field_map_dimensions) + sizeof(__T__::dynamic_array_field) + sizeof(__T__::fixed_array_field) + sizeof(__T__::int_field) + sizeof(__T__::int8_field) + sizeof(__T__::uint8_field) + sizeof(__T__::int16_field) + sizeof(__T__::uint16_field) + sizeof(__T__::uint32_field) + sizeof(__T__::int64_field) + sizeof(__T__::uint64_field) + sizeof(__T__::size_field) + sizeof(__T__::float32_field) + sizeof(__T__::float64_field) + sizeof(__T__::complexfloat32_field) + sizeof(__T__::complexfloat64_field) + sizeof(__T__::string_field) + sizeof(__T__::tuple_field) + sizeof(__T__::vector_field) + sizeof(__T__::vector_of_vectors_field) + sizeof(__T__::fixed_vector_field) + sizeof(__T__::fixed_vector_of_vectors_field) + sizeof(__T__::optional_named_array) + sizeof(__T__::int_float_union) + sizeof(__T__::nullable_int_float_union) + sizeof(__T__::union_with_nested_generic_union) + sizeof(__T__::map_field))) && + offsetof(__T__, array_field) < offsetof(__T__, array_field_map_dimensions) && offsetof(__T__, array_field_map_dimensions) < offsetof(__T__, dynamic_array_field) && offsetof(__T__, dynamic_array_field) < offsetof(__T__, fixed_array_field) && offsetof(__T__, fixed_array_field) < offsetof(__T__, int_field) && offsetof(__T__, int_field) < offsetof(__T__, int8_field) && offsetof(__T__, int8_field) < offsetof(__T__, uint8_field) && offsetof(__T__, uint8_field) < offsetof(__T__, int16_field) && offsetof(__T__, int16_field) < offsetof(__T__, uint16_field) && offsetof(__T__, uint16_field) < offsetof(__T__, uint32_field) && offsetof(__T__, uint32_field) < offsetof(__T__, int64_field) && offsetof(__T__, int64_field) < offsetof(__T__, uint64_field) && offsetof(__T__, uint64_field) < offsetof(__T__, size_field) && offsetof(__T__, size_field) < offsetof(__T__, float32_field) && offsetof(__T__, float32_field) < offsetof(__T__, float64_field) && offsetof(__T__, float64_field) < offsetof(__T__, complexfloat32_field) && offsetof(__T__, complexfloat32_field) < offsetof(__T__, complexfloat64_field) && offsetof(__T__, complexfloat64_field) < offsetof(__T__, string_field) && offsetof(__T__, string_field) < offsetof(__T__, tuple_field) && offsetof(__T__, tuple_field) < offsetof(__T__, vector_field) && offsetof(__T__, vector_field) < offsetof(__T__, vector_of_vectors_field) && offsetof(__T__, vector_of_vectors_field) < offsetof(__T__, fixed_vector_field) && offsetof(__T__, fixed_vector_field) < offsetof(__T__, fixed_vector_of_vectors_field) && offsetof(__T__, fixed_vector_of_vectors_field) < offsetof(__T__, optional_named_array) && offsetof(__T__, optional_named_array) < offsetof(__T__, int_float_union) && offsetof(__T__, int_float_union) < offsetof(__T__, nullable_int_float_union) && offsetof(__T__, nullable_int_float_union) < offsetof(__T__, union_with_nested_generic_union) && offsetof(__T__, union_with_nested_generic_union) < offsetof(__T__, map_field); }; template <> @@ -2439,6 +2440,7 @@ template ReadA, typename B, yardl::binary:: yardl::binary::WriteVector(stream, value.vector_field); yardl::binary::WriteVector, yardl::binary::WriteVector>(stream, value.vector_of_vectors_field); yardl::binary::WriteArray(stream, value.fixed_vector_field); + yardl::binary::WriteArray, yardl::binary::WriteArray, 2>(stream, value.fixed_vector_of_vectors_field); yardl::binary::WriteOptional(stream, value.optional_named_array); WriteUnion(stream, value.int_float_union); WriteUnion(stream, value.nullable_int_float_union); @@ -2474,6 +2476,7 @@ template ReadA, typename B, yardl::binary:: yardl::binary::ReadVector(stream, value.vector_field); yardl::binary::ReadVector, yardl::binary::ReadVector>(stream, value.vector_of_vectors_field); yardl::binary::ReadArray(stream, value.fixed_vector_field); + yardl::binary::ReadArray, yardl::binary::ReadArray, 2>(stream, value.fixed_vector_of_vectors_field); yardl::binary::ReadOptional(stream, value.optional_named_array); ReadUnion(stream, value.int_float_union); ReadUnion(stream, value.nullable_int_float_union); @@ -3469,6 +3472,68 @@ void DynamicNDArraysReader::CloseImpl() { stream_.VerifyFinished(); } +void MultiDArraysWriter::WriteImagesImpl(yardl::NDArray const& value) { + yardl::binary::WriteBlock, yardl::binary::WriteNDArray>(stream_, value); +} + +void MultiDArraysWriter::WriteImagesImpl(std::vector> const& values) { + if (!values.empty()) { + yardl::binary::WriteVector, yardl::binary::WriteNDArray>(stream_, values); + } +} + +void MultiDArraysWriter::EndImagesImpl() { + yardl::binary::WriteInteger(stream_, 0U); +} + +void MultiDArraysWriter::WriteFramesImpl(yardl::FixedNDArray const& value) { + yardl::binary::WriteBlock, yardl::binary::WriteFixedNDArray>(stream_, value); +} + +void MultiDArraysWriter::WriteFramesImpl(std::vector> const& values) { + if (!values.empty()) { + yardl::binary::WriteVector, yardl::binary::WriteFixedNDArray>(stream_, values); + } +} + +void MultiDArraysWriter::EndFramesImpl() { + yardl::binary::WriteInteger(stream_, 0U); +} + +void MultiDArraysWriter::Flush() { + stream_.Flush(); +} + +void MultiDArraysWriter::CloseImpl() { + stream_.Flush(); +} + +bool MultiDArraysReader::ReadImagesImpl(yardl::NDArray& value) { + bool read_block_successful = false; + read_block_successful = yardl::binary::ReadBlock, yardl::binary::ReadNDArray>(stream_, current_block_remaining_, value); + return read_block_successful; +} + +bool MultiDArraysReader::ReadImagesImpl(std::vector>& values) { + yardl::binary::ReadBlocksIntoVector, yardl::binary::ReadNDArray>(stream_, current_block_remaining_, values); + return current_block_remaining_ != 0; +} + +bool MultiDArraysReader::ReadFramesImpl(yardl::FixedNDArray& value) { + bool read_block_successful = false; + read_block_successful = yardl::binary::ReadBlock, yardl::binary::ReadFixedNDArray>(stream_, current_block_remaining_, value); + return read_block_successful; +} + +bool MultiDArraysReader::ReadFramesImpl(std::vector>& values) { + yardl::binary::ReadBlocksIntoVector, yardl::binary::ReadFixedNDArray>(stream_, current_block_remaining_, values); + return current_block_remaining_ != 0; +} + +void MultiDArraysReader::CloseImpl() { + stream_.VerifyFinished(); +} + void MapsWriter::WriteStringToIntImpl(std::unordered_map const& value) { yardl::binary::WriteMap(stream_, value); } diff --git a/cpp/test/generated/binary/protocols.h b/cpp/test/generated/binary/protocols.h index cd5ca2c4..e088180b 100644 --- a/cpp/test/generated/binary/protocols.h +++ b/cpp/test/generated/binary/protocols.h @@ -858,6 +858,53 @@ class DynamicNDArraysReader : public test_model::DynamicNDArraysReaderBase, yard Version version_; }; +// Binary writer for the MultiDArrays protocol. +class MultiDArraysWriter : public test_model::MultiDArraysWriterBase, yardl::binary::BinaryWriter { + public: + MultiDArraysWriter(std::ostream& stream, Version version = Version::Current) + : yardl::binary::BinaryWriter(stream, test_model::MultiDArraysWriterBase::SchemaFromVersion(version)), version_(version) {} + + MultiDArraysWriter(std::string file_name, Version version = Version::Current) + : yardl::binary::BinaryWriter(file_name, test_model::MultiDArraysWriterBase::SchemaFromVersion(version)), version_(version) {} + + void Flush() override; + + protected: + void WriteImagesImpl(yardl::NDArray const& value) override; + void WriteImagesImpl(std::vector> const& values) override; + void EndImagesImpl() override; + void WriteFramesImpl(yardl::FixedNDArray const& value) override; + void WriteFramesImpl(std::vector> const& values) override; + void EndFramesImpl() override; + void CloseImpl() override; + + Version version_; +}; + +// Binary reader for the MultiDArrays protocol. +class MultiDArraysReader : public test_model::MultiDArraysReaderBase, yardl::binary::BinaryReader { + public: + MultiDArraysReader(std::istream& stream) + : yardl::binary::BinaryReader(stream), version_(test_model::MultiDArraysReaderBase::VersionFromSchema(schema_read_)) {} + + MultiDArraysReader(std::string file_name) + : yardl::binary::BinaryReader(file_name), version_(test_model::MultiDArraysReaderBase::VersionFromSchema(schema_read_)) {} + + Version GetVersion() { return version_; } + + protected: + bool ReadImagesImpl(yardl::NDArray& value) override; + bool ReadImagesImpl(std::vector>& values) override; + bool ReadFramesImpl(yardl::FixedNDArray& value) override; + bool ReadFramesImpl(std::vector>& values) override; + void CloseImpl() override; + + Version version_; + + private: + size_t current_block_remaining_ = 0; +}; + // Binary writer for the Maps protocol. class MapsWriter : public test_model::MapsWriterBase, yardl::binary::BinaryWriter { public: diff --git a/cpp/test/generated/factories.cc b/cpp/test/generated/factories.cc index cc5a2367..2f94b6ee 100644 --- a/cpp/test/generated/factories.cc +++ b/cpp/test/generated/factories.cc @@ -567,6 +567,34 @@ std::unique_ptr CreateReader +std::unique_ptr CreateWriter(Format format, std::string const& filename) { + switch (format) { + case Format::kHdf5: + return std::make_unique(filename); + case Format::kBinary: + return std::make_unique(filename); + case Format::kNDJson: + return std::make_unique(filename); + default: + throw std::runtime_error("Unknown format"); + } +} + +template<> +std::unique_ptr CreateReader(Format format, std::string const& filename) { + switch (format) { + case Format::kHdf5: + return std::make_unique(filename); + case Format::kBinary: + return std::make_unique(filename); + case Format::kNDJson: + return std::make_unique(filename); + default: + throw std::runtime_error("Unknown format"); + } +} + template<> std::unique_ptr CreateWriter(Format format, std::string const& filename) { switch (format) { diff --git a/cpp/test/generated/hdf5/protocols.cc b/cpp/test/generated/hdf5/protocols.cc index 5efaead7..6723854c 100644 --- a/cpp/test/generated/hdf5/protocols.cc +++ b/cpp/test/generated/hdf5/protocols.cc @@ -1010,6 +1010,7 @@ struct _Inner_RecordWithComputedFields { vector_field(o.vector_field), vector_of_vectors_field(o.vector_of_vectors_field), fixed_vector_field(o.fixed_vector_field), + fixed_vector_of_vectors_field(o.fixed_vector_of_vectors_field), optional_named_array(o.optional_named_array), int_float_union(o.int_float_union), nullable_int_float_union(o.nullable_int_float_union), @@ -1040,6 +1041,7 @@ struct _Inner_RecordWithComputedFields { yardl::hdf5::ToOuter(vector_field, o.vector_field); yardl::hdf5::ToOuter(vector_of_vectors_field, o.vector_of_vectors_field); yardl::hdf5::ToOuter(fixed_vector_field, o.fixed_vector_field); + yardl::hdf5::ToOuter(fixed_vector_of_vectors_field, o.fixed_vector_of_vectors_field); yardl::hdf5::ToOuter(optional_named_array, o.optional_named_array); yardl::hdf5::ToOuter(int_float_union, o.int_float_union); yardl::hdf5::ToOuter(nullable_int_float_union, o.nullable_int_float_union); @@ -1069,6 +1071,7 @@ struct _Inner_RecordWithComputedFields { yardl::hdf5::InnerVlen vector_field; yardl::hdf5::InnerVlen, std::vector> vector_of_vectors_field; std::array fixed_vector_field; + std::array, 2> fixed_vector_of_vectors_field; yardl::hdf5::InnerOptional, test_model::NamedNDArray> optional_named_array; ::InnerUnion2 int_float_union; ::InnerUnion2 nullable_int_float_union; @@ -1514,6 +1517,7 @@ template t.insertMember("vectorField", HOFFSET(RecordType, vector_field), yardl::hdf5::InnerVlenDdl(H5::PredType::NATIVE_INT32)); t.insertMember("vectorOfVectorsField", HOFFSET(RecordType, vector_of_vectors_field), yardl::hdf5::InnerVlenDdl(yardl::hdf5::InnerVlenDdl(H5::PredType::NATIVE_INT32))); t.insertMember("fixedVectorField", HOFFSET(RecordType, fixed_vector_field), yardl::hdf5::FixedVectorDdl(H5::PredType::NATIVE_INT32, 3)); + t.insertMember("fixedVectorOfVectorsField", HOFFSET(RecordType, fixed_vector_of_vectors_field), yardl::hdf5::FixedVectorDdl(yardl::hdf5::FixedVectorDdl(H5::PredType::NATIVE_INT32, 3), 2)); t.insertMember("optionalNamedArray", HOFFSET(RecordType, optional_named_array), yardl::hdf5::OptionalTypeDdl, test_model::NamedNDArray>(yardl::hdf5::NDArrayDdl(H5::PredType::NATIVE_INT32))); t.insertMember("intFloatUnion", HOFFSET(RecordType, int_float_union), ::InnerUnion2Ddl(false, H5::PredType::NATIVE_INT32, "int32", H5::PredType::NATIVE_FLOAT, "float32")); t.insertMember("nullableIntFloatUnion", HOFFSET(RecordType, nullable_int_float_union), ::InnerUnion2Ddl(true, H5::PredType::NATIVE_INT32, "int32", H5::PredType::NATIVE_FLOAT, "float32")); @@ -2587,6 +2591,114 @@ void DynamicNDArraysReader::ReadRecordWithDynamicNDArraysImpl(test_model::Record yardl::hdf5::ReadScalarDataset(group_, "recordWithDynamicNDArrays", test_model::hdf5::GetRecordWithDynamicNDArraysHdf5Ddl(), value); } +MultiDArraysWriter::MultiDArraysWriter(std::string path) + : yardl::hdf5::Hdf5Writer::Hdf5Writer(path, "MultiDArrays", schema_) { +} + +void MultiDArraysWriter::WriteImagesImpl(yardl::NDArray const& value) { + if (!images_dataset_state_) { + images_dataset_state_ = std::make_unique(group_, "images", yardl::hdf5::NDArrayDdl(H5::PredType::NATIVE_FLOAT), std::max(sizeof(yardl::hdf5::InnerNdArray), sizeof(yardl::NDArray))); + } + + images_dataset_state_->Append, yardl::NDArray>(value); +} + +void MultiDArraysWriter::WriteImagesImpl(std::vector> const& values) { + if (!images_dataset_state_) { + images_dataset_state_ = std::make_unique(group_, "images", yardl::hdf5::NDArrayDdl(H5::PredType::NATIVE_FLOAT), std::max(sizeof(yardl::hdf5::InnerNdArray), sizeof(yardl::NDArray))); + } + + images_dataset_state_->AppendBatch, yardl::NDArray>(values); +} + +void MultiDArraysWriter::EndImagesImpl() { + if (!images_dataset_state_) { + images_dataset_state_ = std::make_unique(group_, "images", yardl::hdf5::NDArrayDdl(H5::PredType::NATIVE_FLOAT), std::max(sizeof(yardl::hdf5::InnerNdArray), sizeof(yardl::NDArray))); + } + + images_dataset_state_.reset(); +} + +void MultiDArraysWriter::WriteFramesImpl(yardl::FixedNDArray const& value) { + if (!frames_dataset_state_) { + frames_dataset_state_ = std::make_unique(group_, "frames", yardl::hdf5::FixedNDArrayDdl(H5::PredType::NATIVE_FLOAT, {1, 1, 64, 32}), 0); + } + + frames_dataset_state_->Append, yardl::FixedNDArray>(value); +} + +void MultiDArraysWriter::WriteFramesImpl(std::vector> const& values) { + if (!frames_dataset_state_) { + frames_dataset_state_ = std::make_unique(group_, "frames", yardl::hdf5::FixedNDArrayDdl(H5::PredType::NATIVE_FLOAT, {1, 1, 64, 32}), 0); + } + + frames_dataset_state_->AppendBatch, yardl::FixedNDArray>(values); +} + +void MultiDArraysWriter::EndFramesImpl() { + if (!frames_dataset_state_) { + frames_dataset_state_ = std::make_unique(group_, "frames", yardl::hdf5::FixedNDArrayDdl(H5::PredType::NATIVE_FLOAT, {1, 1, 64, 32}), 0); + } + + frames_dataset_state_.reset(); +} + +MultiDArraysReader::MultiDArraysReader(std::string path) + : yardl::hdf5::Hdf5Reader::Hdf5Reader(path, "MultiDArrays", schema_) { +} + +bool MultiDArraysReader::ReadImagesImpl(yardl::NDArray& value) { + if (!images_dataset_state_) { + images_dataset_state_ = std::make_unique(group_, "images", yardl::hdf5::NDArrayDdl(H5::PredType::NATIVE_FLOAT), std::max(sizeof(yardl::hdf5::InnerNdArray), sizeof(yardl::NDArray))); + } + + bool has_value = images_dataset_state_->Read, yardl::NDArray>(value); + if (!has_value) { + images_dataset_state_.reset(); + } + + return has_value; +} + +bool MultiDArraysReader::ReadImagesImpl(std::vector>& values) { + if (!images_dataset_state_) { + images_dataset_state_ = std::make_unique(group_, "images", yardl::hdf5::NDArrayDdl(H5::PredType::NATIVE_FLOAT)); + } + + bool has_more = images_dataset_state_->ReadBatch, yardl::NDArray>(values); + if (!has_more) { + images_dataset_state_.reset(); + } + + return has_more; +} + +bool MultiDArraysReader::ReadFramesImpl(yardl::FixedNDArray& value) { + if (!frames_dataset_state_) { + frames_dataset_state_ = std::make_unique(group_, "frames", yardl::hdf5::FixedNDArrayDdl(H5::PredType::NATIVE_FLOAT, {1, 1, 64, 32}), 0); + } + + bool has_value = frames_dataset_state_->Read, yardl::FixedNDArray>(value); + if (!has_value) { + frames_dataset_state_.reset(); + } + + return has_value; +} + +bool MultiDArraysReader::ReadFramesImpl(std::vector>& values) { + if (!frames_dataset_state_) { + frames_dataset_state_ = std::make_unique(group_, "frames", yardl::hdf5::FixedNDArrayDdl(H5::PredType::NATIVE_FLOAT, {1, 1, 64, 32})); + } + + bool has_more = frames_dataset_state_->ReadBatch, yardl::FixedNDArray>(values); + if (!has_more) { + frames_dataset_state_.reset(); + } + + return has_more; +} + MapsWriter::MapsWriter(std::string path) : yardl::hdf5::Hdf5Writer::Hdf5Writer(path, "Maps", schema_) { } diff --git a/cpp/test/generated/hdf5/protocols.h b/cpp/test/generated/hdf5/protocols.h index 15988c68..29abd127 100644 --- a/cpp/test/generated/hdf5/protocols.h +++ b/cpp/test/generated/hdf5/protocols.h @@ -659,6 +659,47 @@ class DynamicNDArraysReader : public test_model::DynamicNDArraysReaderBase, publ private: }; +// HDF5 writer for the MultiDArrays protocol. +class MultiDArraysWriter : public test_model::MultiDArraysWriterBase, public yardl::hdf5::Hdf5Writer { + public: + MultiDArraysWriter(std::string path); + + protected: + void WriteImagesImpl(yardl::NDArray const& value) override; + + void WriteImagesImpl(std::vector> const& values) override; + + void EndImagesImpl() override; + + void WriteFramesImpl(yardl::FixedNDArray const& value) override; + + void WriteFramesImpl(std::vector> const& values) override; + + void EndFramesImpl() override; + + private: + std::unique_ptr images_dataset_state_; + std::unique_ptr frames_dataset_state_; +}; + +// HDF5 reader for the MultiDArrays protocol. +class MultiDArraysReader : public test_model::MultiDArraysReaderBase, public yardl::hdf5::Hdf5Reader { + public: + MultiDArraysReader(std::string path); + + bool ReadImagesImpl(yardl::NDArray& value) override; + + bool ReadImagesImpl(std::vector>& values) override; + + bool ReadFramesImpl(yardl::FixedNDArray& value) override; + + bool ReadFramesImpl(std::vector>& values) override; + + private: + std::unique_ptr images_dataset_state_; + std::unique_ptr frames_dataset_state_; +}; + // HDF5 writer for the Maps protocol. class MapsWriter : public test_model::MapsWriterBase, public yardl::hdf5::Hdf5Writer { public: diff --git a/cpp/test/generated/mocks.cc b/cpp/test/generated/mocks.cc index 1afea04e..7234b5ed 100644 --- a/cpp/test/generated/mocks.cc +++ b/cpp/test/generated/mocks.cc @@ -2311,6 +2311,141 @@ class TestDynamicNDArraysWriterBase : public DynamicNDArraysWriterBase { bool close_called_ = false; }; +class MockMultiDArraysWriter : public MultiDArraysWriterBase { + public: + void WriteImagesImpl (yardl::NDArray const& value) override { + if (WriteImagesImpl_expected_values_.empty()) { + throw std::runtime_error("Unexpected call to WriteImagesImpl"); + } + if (WriteImagesImpl_expected_values_.front() != value) { + throw std::runtime_error("Unexpected argument value for call to WriteImagesImpl"); + } + WriteImagesImpl_expected_values_.pop(); + } + + std::queue> WriteImagesImpl_expected_values_; + + void ExpectWriteImagesImpl (yardl::NDArray const& value) { + WriteImagesImpl_expected_values_.push(value); + } + + void EndImagesImpl () override { + if (--EndImagesImpl_expected_call_count_ < 0) { + throw std::runtime_error("Unexpected call to EndImagesImpl"); + } + } + + int EndImagesImpl_expected_call_count_ = 0; + + void ExpectEndImagesImpl () { + EndImagesImpl_expected_call_count_++; + } + + void WriteFramesImpl (yardl::FixedNDArray const& value) override { + if (WriteFramesImpl_expected_values_.empty()) { + throw std::runtime_error("Unexpected call to WriteFramesImpl"); + } + if (WriteFramesImpl_expected_values_.front() != value) { + throw std::runtime_error("Unexpected argument value for call to WriteFramesImpl"); + } + WriteFramesImpl_expected_values_.pop(); + } + + std::queue> WriteFramesImpl_expected_values_; + + void ExpectWriteFramesImpl (yardl::FixedNDArray const& value) { + WriteFramesImpl_expected_values_.push(value); + } + + void EndFramesImpl () override { + if (--EndFramesImpl_expected_call_count_ < 0) { + throw std::runtime_error("Unexpected call to EndFramesImpl"); + } + } + + int EndFramesImpl_expected_call_count_ = 0; + + void ExpectEndFramesImpl () { + EndFramesImpl_expected_call_count_++; + } + + void Verify() { + if (!WriteImagesImpl_expected_values_.empty()) { + throw std::runtime_error("Expected call to WriteImagesImpl was not received"); + } + if (EndImagesImpl_expected_call_count_ > 0) { + throw std::runtime_error("Expected call to EndImagesImpl was not received"); + } + if (!WriteFramesImpl_expected_values_.empty()) { + throw std::runtime_error("Expected call to WriteFramesImpl was not received"); + } + if (EndFramesImpl_expected_call_count_ > 0) { + throw std::runtime_error("Expected call to EndFramesImpl was not received"); + } + } +}; + +class TestMultiDArraysWriterBase : public MultiDArraysWriterBase { + public: + TestMultiDArraysWriterBase(std::unique_ptr writer, std::function()> create_reader) : writer_(std::move(writer)), create_reader_(create_reader) { + } + + ~TestMultiDArraysWriterBase() { + if (!close_called_ && !std::uncaught_exceptions()) { + ADD_FAILURE() << "Close() needs to be called on 'TestMultiDArraysWriterBase' to verify mocks"; + } + } + + protected: + void WriteImagesImpl(yardl::NDArray const& value) override { + writer_->WriteImages(value); + mock_writer_.ExpectWriteImagesImpl(value); + } + + void WriteImagesImpl(std::vector> const& values) override { + writer_->WriteImages(values); + for (auto const& v : values) { + mock_writer_.ExpectWriteImagesImpl(v); + } + } + + void EndImagesImpl() override { + writer_->EndImages(); + mock_writer_.ExpectEndImagesImpl(); + } + + void WriteFramesImpl(yardl::FixedNDArray const& value) override { + writer_->WriteFrames(value); + mock_writer_.ExpectWriteFramesImpl(value); + } + + void WriteFramesImpl(std::vector> const& values) override { + writer_->WriteFrames(values); + for (auto const& v : values) { + mock_writer_.ExpectWriteFramesImpl(v); + } + } + + void EndFramesImpl() override { + writer_->EndFrames(); + mock_writer_.ExpectEndFramesImpl(); + } + + void CloseImpl() override { + close_called_ = true; + writer_->Close(); + std::unique_ptr reader = create_reader_(); + reader->CopyTo(mock_writer_, 2, 1); + mock_writer_.Verify(); + } + + private: + std::unique_ptr writer_; + std::function()> create_reader_; + MockMultiDArraysWriter mock_writer_; + bool close_called_ = false; +}; + class MockMapsWriter : public MapsWriterBase { public: void WriteStringToIntImpl (std::unordered_map const& value) override { @@ -4268,6 +4403,14 @@ std::unique_ptr CreateValidatingWriter +std::unique_ptr CreateValidatingWriter(Format format, std::string const& filename) { + return std::make_unique( + CreateWriter(format, filename), + [format, filename](){ return CreateReader(format, filename);} + ); +} + template<> std::unique_ptr CreateValidatingWriter(Format format, std::string const& filename) { return std::make_unique( diff --git a/cpp/test/generated/model.json b/cpp/test/generated/model.json index 6a33f89f..047e650a 100644 --- a/cpp/test/generated/model.json +++ b/cpp/test/generated/model.json @@ -2444,6 +2444,20 @@ } } }, + { + "name": "fixedVectorOfVectorsField", + "type": { + "vector": { + "items": { + "vector": { + "items": "int32", + "length": 3 + } + }, + "length": 2 + } + } + }, { "name": "optionalNamedArray", "type": [ @@ -2716,6 +2730,37 @@ } } }, + { + "name": "accessFixedVectorOfVectorsField", + "expression": { + "subscript": { + "target": { + "subscript": { + "target": { + "memberAccess": { + "member": "fixedVectorOfVectorsField", + "kind": "field" + } + }, + "arguments": [ + { + "expression": { + "integer": 1 + } + } + ] + } + }, + "arguments": [ + { + "expression": { + "integer": 2 + } + } + ] + } + } + }, { "name": "arraySize", "expression": { @@ -2952,6 +2997,12 @@ "integer": 3 } }, + { + "name": "fixedVectorOfVectorsSize", + "expression": { + "integer": 2 + } + }, { "name": "arrayDimensionXIndex", "expression": { @@ -4668,6 +4719,67 @@ } ] }, + { + "name": "MultiDArrays", + "sequence": [ + { + "name": "images", + "type": { + "stream": { + "items": { + "array": { + "items": "float32", + "dimensions": [ + { + "name": "ch" + }, + { + "name": "z" + }, + { + "name": "y" + }, + { + "name": "x" + } + ] + } + } + } + } + }, + { + "name": "frames", + "type": { + "stream": { + "items": { + "array": { + "items": "float32", + "dimensions": [ + { + "name": "ch", + "length": 1 + }, + { + "name": "z", + "length": 1 + }, + { + "name": "y", + "length": 64 + }, + { + "name": "x", + "length": 32 + } + ] + } + } + } + } + } + ] + }, { "name": "Maps", "sequence": [ diff --git a/cpp/test/generated/ndjson/protocols.cc b/cpp/test/generated/ndjson/protocols.cc index 170632a4..2d3ad6de 100644 --- a/cpp/test/generated/ndjson/protocols.cc +++ b/cpp/test/generated/ndjson/protocols.cc @@ -2378,6 +2378,9 @@ void to_json(ordered_json& j, test_model::RecordWithComputedFields const& value) if (yardl::ndjson::ShouldSerializeFieldValue(value.fixed_vector_field)) { j.push_back({"fixedVectorField", value.fixed_vector_field}); } + if (yardl::ndjson::ShouldSerializeFieldValue(value.fixed_vector_of_vectors_field)) { + j.push_back({"fixedVectorOfVectorsField", value.fixed_vector_of_vectors_field}); + } if (yardl::ndjson::ShouldSerializeFieldValue(value.optional_named_array)) { j.push_back({"optionalNamedArray", value.optional_named_array}); } @@ -2462,6 +2465,9 @@ void from_json(ordered_json const& j, test_model::RecordWithComputedFields& valu if (auto it = j.find("fixedVectorField"); it != j.end()) { it->get_to(value.fixed_vector_field); } + if (auto it = j.find("fixedVectorOfVectorsField"); it != j.end()) { + it->get_to(value.fixed_vector_of_vectors_field); + } if (auto it = j.find("optionalNamedArray"); it != j.end()) { it->get_to(value.optional_named_array); } @@ -3257,6 +3263,34 @@ void DynamicNDArraysReader::CloseImpl() { VerifyFinished(); } +void MultiDArraysWriter::WriteImagesImpl(yardl::NDArray const& value) { + ordered_json json_value = value; + yardl::ndjson::WriteProtocolValue(stream_, "images", json_value);} + +void MultiDArraysWriter::WriteFramesImpl(yardl::FixedNDArray const& value) { + ordered_json json_value = value; + yardl::ndjson::WriteProtocolValue(stream_, "frames", json_value);} + +void MultiDArraysWriter::Flush() { + stream_.flush(); +} + +void MultiDArraysWriter::CloseImpl() { + stream_.flush(); +} + +bool MultiDArraysReader::ReadImagesImpl(yardl::NDArray& value) { + return yardl::ndjson::ReadProtocolValue(stream_, line_, "images", false, unused_step_, value); +} + +bool MultiDArraysReader::ReadFramesImpl(yardl::FixedNDArray& value) { + return yardl::ndjson::ReadProtocolValue(stream_, line_, "frames", false, unused_step_, value); +} + +void MultiDArraysReader::CloseImpl() { + VerifyFinished(); +} + void MapsWriter::WriteStringToIntImpl(std::unordered_map const& value) { ordered_json json_value = value; yardl::ndjson::WriteProtocolValue(stream_, "stringToInt", json_value);} diff --git a/cpp/test/generated/ndjson/protocols.h b/cpp/test/generated/ndjson/protocols.h index 72ad96ac..d1b50b62 100644 --- a/cpp/test/generated/ndjson/protocols.h +++ b/cpp/test/generated/ndjson/protocols.h @@ -777,6 +777,44 @@ class DynamicNDArraysReader : public test_model::DynamicNDArraysReaderBase, yard void CloseImpl() override; }; +// NDJSON writer for the MultiDArrays protocol. +class MultiDArraysWriter : public test_model::MultiDArraysWriterBase, yardl::ndjson::NDJsonWriter { + public: + MultiDArraysWriter(std::ostream& stream) + : yardl::ndjson::NDJsonWriter(stream, schema_) { + } + + MultiDArraysWriter(std::string file_name) + : yardl::ndjson::NDJsonWriter(file_name, schema_) { + } + + void Flush() override; + + protected: + void WriteImagesImpl(yardl::NDArray const& value) override; + void EndImagesImpl() override {} + void WriteFramesImpl(yardl::FixedNDArray const& value) override; + void EndFramesImpl() override {} + void CloseImpl() override; +}; + +// NDJSON reader for the MultiDArrays protocol. +class MultiDArraysReader : public test_model::MultiDArraysReaderBase, yardl::ndjson::NDJsonReader { + public: + MultiDArraysReader(std::istream& stream) + : yardl::ndjson::NDJsonReader(stream, schema_) { + } + + MultiDArraysReader(std::string file_name) + : yardl::ndjson::NDJsonReader(file_name, schema_) { + } + + protected: + bool ReadImagesImpl(yardl::NDArray& value) override; + bool ReadFramesImpl(yardl::FixedNDArray& value) override; + void CloseImpl() override; +}; + // NDJSON writer for the Maps protocol. class MapsWriter : public test_model::MapsWriterBase, yardl::ndjson::NDJsonWriter { public: diff --git a/cpp/test/generated/protocols.cc b/cpp/test/generated/protocols.cc index b85c321b..cff90358 100644 --- a/cpp/test/generated/protocols.cc +++ b/cpp/test/generated/protocols.cc @@ -3593,6 +3593,288 @@ void DynamicNDArraysReaderBase::CopyTo(DynamicNDArraysWriterBase& writer) { } } +namespace { +void MultiDArraysWriterBaseInvalidState(uint8_t attempted, [[maybe_unused]] bool end, uint8_t current) { + std::string expected_method; + switch (current) { + case 0: expected_method = "WriteImages() or EndImages()"; break; + case 1: expected_method = "WriteFrames() or EndFrames()"; break; + } + std::string attempted_method; + switch (attempted) { + case 0: attempted_method = end ? "EndImages()" : "WriteImages()"; break; + case 1: attempted_method = end ? "EndFrames()" : "WriteFrames()"; break; + case 2: attempted_method = "Close()"; break; + } + throw std::runtime_error("Expected call to " + expected_method + " but received call to " + attempted_method + " instead."); +} + +void MultiDArraysReaderBaseInvalidState(uint8_t attempted, uint8_t current) { + auto f = [](uint8_t i) -> std::string { + switch (i/2) { + case 0: return "ReadImages()"; + case 1: return "ReadFrames()"; + case 2: return "Close()"; + default: return ""; + } + }; + throw std::runtime_error("Expected call to " + f(current) + " but received call to " + f(attempted) + " instead."); +} + +} // namespace + +std::string MultiDArraysWriterBase::schema_ = R"({"protocol":{"name":"MultiDArrays","sequence":[{"name":"images","type":{"stream":{"items":{"array":{"items":"float32","dimensions":[{"name":"ch"},{"name":"z"},{"name":"y"},{"name":"x"}]}}}}},{"name":"frames","type":{"stream":{"items":{"array":{"items":"float32","dimensions":[{"name":"ch","length":1},{"name":"z","length":1},{"name":"y","length":64},{"name":"x","length":32}]}}}}}]},"types":null})"; + +std::vector MultiDArraysWriterBase::previous_schemas_ = { +}; + +std::string MultiDArraysWriterBase::SchemaFromVersion(Version version) { + switch (version) { + case Version::Current: return MultiDArraysWriterBase::schema_; break; + default: throw std::runtime_error("The version does not correspond to any schema supported by protocol MultiDArrays."); + } + +} +void MultiDArraysWriterBase::WriteImages(yardl::NDArray const& value) { + if (unlikely(state_ != 0)) { + MultiDArraysWriterBaseInvalidState(0, false, state_); + } + + WriteImagesImpl(value); +} + +void MultiDArraysWriterBase::WriteImages(std::vector> const& values) { + if (unlikely(state_ != 0)) { + MultiDArraysWriterBaseInvalidState(0, false, state_); + } + + WriteImagesImpl(values); +} + +void MultiDArraysWriterBase::EndImages() { + if (unlikely(state_ != 0)) { + MultiDArraysWriterBaseInvalidState(0, true, state_); + } + + EndImagesImpl(); + state_ = 1; +} + +// fallback implementation +void MultiDArraysWriterBase::WriteImagesImpl(std::vector> const& values) { + for (auto const& v : values) { + WriteImagesImpl(v); + } +} + +void MultiDArraysWriterBase::WriteFrames(yardl::FixedNDArray const& value) { + if (unlikely(state_ != 1)) { + MultiDArraysWriterBaseInvalidState(1, false, state_); + } + + WriteFramesImpl(value); +} + +void MultiDArraysWriterBase::WriteFrames(std::vector> const& values) { + if (unlikely(state_ != 1)) { + MultiDArraysWriterBaseInvalidState(1, false, state_); + } + + WriteFramesImpl(values); +} + +void MultiDArraysWriterBase::EndFrames() { + if (unlikely(state_ != 1)) { + MultiDArraysWriterBaseInvalidState(1, true, state_); + } + + EndFramesImpl(); + state_ = 2; +} + +// fallback implementation +void MultiDArraysWriterBase::WriteFramesImpl(std::vector> const& values) { + for (auto const& v : values) { + WriteFramesImpl(v); + } +} + +void MultiDArraysWriterBase::Close() { + if (unlikely(state_ != 2)) { + MultiDArraysWriterBaseInvalidState(2, false, state_); + } + + CloseImpl(); +} + +std::string MultiDArraysReaderBase::schema_ = MultiDArraysWriterBase::schema_; + +std::vector MultiDArraysReaderBase::previous_schemas_ = MultiDArraysWriterBase::previous_schemas_; + +Version MultiDArraysReaderBase::VersionFromSchema(std::string const& schema) { + if (schema == MultiDArraysWriterBase::schema_) { + return Version::Current; + } + throw std::runtime_error("The schema does not match any version supported by protocol MultiDArrays."); +} +bool MultiDArraysReaderBase::ReadImages(yardl::NDArray& value) { + if (unlikely(state_ != 0)) { + if (state_ == 1) { + state_ = 2; + return false; + } + MultiDArraysReaderBaseInvalidState(0, state_); + } + + bool result = ReadImagesImpl(value); + if (!result) { + state_ = 2; + } + return result; +} + +bool MultiDArraysReaderBase::ReadImages(std::vector>& values) { + if (values.capacity() == 0) { + throw std::runtime_error("vector must have a nonzero capacity."); + } + if (unlikely(state_ != 0)) { + if (state_ == 1) { + state_ = 2; + values.clear(); + return false; + } + MultiDArraysReaderBaseInvalidState(0, state_); + } + + if (!ReadImagesImpl(values)) { + state_ = 1; + return values.size() > 0; + } + return true; +} + +// fallback implementation +bool MultiDArraysReaderBase::ReadImagesImpl(std::vector>& values) { + size_t i = 0; + while (true) { + if (i == values.size()) { + values.resize(i + 1); + } + if (!ReadImagesImpl(values[i])) { + values.resize(i); + return false; + } + i++; + if (i == values.capacity()) { + return true; + } + } +} + +bool MultiDArraysReaderBase::ReadFrames(yardl::FixedNDArray& value) { + if (unlikely(state_ != 2)) { + if (state_ == 3) { + state_ = 4; + return false; + } + if (state_ == 1) { + state_ = 2; + } else { + MultiDArraysReaderBaseInvalidState(2, state_); + } + } + + bool result = ReadFramesImpl(value); + if (!result) { + state_ = 4; + } + return result; +} + +bool MultiDArraysReaderBase::ReadFrames(std::vector>& values) { + if (values.capacity() == 0) { + throw std::runtime_error("vector must have a nonzero capacity."); + } + if (unlikely(state_ != 2)) { + if (state_ == 3) { + state_ = 4; + values.clear(); + return false; + } + if (state_ == 1) { + state_ = 2; + } else { + MultiDArraysReaderBaseInvalidState(2, state_); + } + } + + if (!ReadFramesImpl(values)) { + state_ = 3; + return values.size() > 0; + } + return true; +} + +// fallback implementation +bool MultiDArraysReaderBase::ReadFramesImpl(std::vector>& values) { + size_t i = 0; + while (true) { + if (i == values.size()) { + values.resize(i + 1); + } + if (!ReadFramesImpl(values[i])) { + values.resize(i); + return false; + } + i++; + if (i == values.capacity()) { + return true; + } + } +} + +void MultiDArraysReaderBase::Close() { + if (unlikely(state_ != 4)) { + if (state_ == 3) { + state_ = 4; + } else { + MultiDArraysReaderBaseInvalidState(4, state_); + } + } + + CloseImpl(); +} +void MultiDArraysReaderBase::CopyTo(MultiDArraysWriterBase& writer, size_t images_buffer_size, size_t frames_buffer_size) { + if (images_buffer_size > 1) { + std::vector> values; + values.reserve(images_buffer_size); + while(ReadImages(values)) { + writer.WriteImages(values); + } + writer.EndImages(); + } else { + yardl::NDArray value; + while(ReadImages(value)) { + writer.WriteImages(value); + } + writer.EndImages(); + } + if (frames_buffer_size > 1) { + std::vector> values; + values.reserve(frames_buffer_size); + while(ReadFrames(values)) { + writer.WriteFrames(values); + } + writer.EndFrames(); + } else { + yardl::FixedNDArray value; + while(ReadFrames(value)) { + writer.WriteFrames(value); + } + writer.EndFrames(); + } +} + namespace { void MapsWriterBaseInvalidState(uint8_t attempted, [[maybe_unused]] bool end, uint8_t current) { std::string expected_method; @@ -6145,7 +6427,7 @@ void ProtocolWithComputedFieldsReaderBaseInvalidState(uint8_t attempted, uint8_t } // namespace -std::string ProtocolWithComputedFieldsWriterBase::schema_ = R"({"protocol":{"name":"ProtocolWithComputedFields","sequence":[{"name":"recordWithComputedFields","type":"TestModel.RecordWithComputedFields"}]},"types":[{"name":"GenericRecordWithComputedFields","typeParameters":["T0","T1"],"fields":[{"name":"f1","type":[{"tag":"T0","type":"T0"},{"tag":"T1","type":"T1"}]}]},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"Tuples.Tuple","typeArguments":["T1","T2"]}},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"BasicTypes.MyTuple","typeArguments":["T1","T2"]}},{"name":"NamedNDArray","type":{"array":{"items":"int32","dimensions":[{"name":"dimA"},{"name":"dimB"}]}}},{"name":"RecordWithComputedFields","fields":[{"name":"arrayField","type":{"array":{"items":"int32","dimensions":[{"name":"x"},{"name":"y"}]}}},{"name":"arrayFieldMapDimensions","type":{"array":{"items":"int32","dimensions":[{"name":"x"},{"name":"y"}]}}},{"name":"dynamicArrayField","type":{"array":{"items":"int32"}}},{"name":"fixedArrayField","type":{"array":{"items":"int32","dimensions":[{"name":"x","length":3},{"name":"y","length":4}]}}},{"name":"intField","type":"int32"},{"name":"int8Field","type":"int8"},{"name":"uint8Field","type":"uint8"},{"name":"int16Field","type":"int16"},{"name":"uint16Field","type":"uint16"},{"name":"uint32Field","type":"uint32"},{"name":"int64Field","type":"int64"},{"name":"uint64Field","type":"uint64"},{"name":"sizeField","type":"size"},{"name":"float32Field","type":"float32"},{"name":"float64Field","type":"float64"},{"name":"complexfloat32Field","type":"complexfloat32"},{"name":"complexfloat64Field","type":"complexfloat64"},{"name":"stringField","type":"string"},{"name":"tupleField","type":{"name":"TestModel.MyTuple","typeArguments":["int32","int32"]}},{"name":"vectorField","type":{"vector":{"items":"int32"}}},{"name":"vectorOfVectorsField","type":{"vector":{"items":{"vector":{"items":"int32"}}}}},{"name":"fixedVectorField","type":{"vector":{"items":"int32","length":3}}},{"name":"optionalNamedArray","type":[null,"TestModel.NamedNDArray"]},{"name":"intFloatUnion","type":[{"tag":"int32","type":"int32"},{"tag":"float32","type":"float32"}]},{"name":"nullableIntFloatUnion","type":[null,{"tag":"int32","type":"int32"},{"tag":"float32","type":"float32"}]},{"name":"unionWithNestedGenericUnion","type":[{"tag":"int","explicitTag":true,"type":"int32"},{"tag":"genericRecordWithComputedFields","explicitTag":true,"type":{"name":"BasicTypes.GenericRecordWithComputedFields","typeArguments":["string","float32"]}}]},{"name":"mapField","type":{"map":{"keys":"string","values":"string"}}}]},{"name":"Tuple","typeParameters":["T1","T2"],"fields":[{"name":"v1","type":"T1"},{"name":"v2","type":"T2"}]}]})"; +std::string ProtocolWithComputedFieldsWriterBase::schema_ = R"({"protocol":{"name":"ProtocolWithComputedFields","sequence":[{"name":"recordWithComputedFields","type":"TestModel.RecordWithComputedFields"}]},"types":[{"name":"GenericRecordWithComputedFields","typeParameters":["T0","T1"],"fields":[{"name":"f1","type":[{"tag":"T0","type":"T0"},{"tag":"T1","type":"T1"}]}]},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"Tuples.Tuple","typeArguments":["T1","T2"]}},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"BasicTypes.MyTuple","typeArguments":["T1","T2"]}},{"name":"NamedNDArray","type":{"array":{"items":"int32","dimensions":[{"name":"dimA"},{"name":"dimB"}]}}},{"name":"RecordWithComputedFields","fields":[{"name":"arrayField","type":{"array":{"items":"int32","dimensions":[{"name":"x"},{"name":"y"}]}}},{"name":"arrayFieldMapDimensions","type":{"array":{"items":"int32","dimensions":[{"name":"x"},{"name":"y"}]}}},{"name":"dynamicArrayField","type":{"array":{"items":"int32"}}},{"name":"fixedArrayField","type":{"array":{"items":"int32","dimensions":[{"name":"x","length":3},{"name":"y","length":4}]}}},{"name":"intField","type":"int32"},{"name":"int8Field","type":"int8"},{"name":"uint8Field","type":"uint8"},{"name":"int16Field","type":"int16"},{"name":"uint16Field","type":"uint16"},{"name":"uint32Field","type":"uint32"},{"name":"int64Field","type":"int64"},{"name":"uint64Field","type":"uint64"},{"name":"sizeField","type":"size"},{"name":"float32Field","type":"float32"},{"name":"float64Field","type":"float64"},{"name":"complexfloat32Field","type":"complexfloat32"},{"name":"complexfloat64Field","type":"complexfloat64"},{"name":"stringField","type":"string"},{"name":"tupleField","type":{"name":"TestModel.MyTuple","typeArguments":["int32","int32"]}},{"name":"vectorField","type":{"vector":{"items":"int32"}}},{"name":"vectorOfVectorsField","type":{"vector":{"items":{"vector":{"items":"int32"}}}}},{"name":"fixedVectorField","type":{"vector":{"items":"int32","length":3}}},{"name":"fixedVectorOfVectorsField","type":{"vector":{"items":{"vector":{"items":"int32","length":3}},"length":2}}},{"name":"optionalNamedArray","type":[null,"TestModel.NamedNDArray"]},{"name":"intFloatUnion","type":[{"tag":"int32","type":"int32"},{"tag":"float32","type":"float32"}]},{"name":"nullableIntFloatUnion","type":[null,{"tag":"int32","type":"int32"},{"tag":"float32","type":"float32"}]},{"name":"unionWithNestedGenericUnion","type":[{"tag":"int","explicitTag":true,"type":"int32"},{"tag":"genericRecordWithComputedFields","explicitTag":true,"type":{"name":"BasicTypes.GenericRecordWithComputedFields","typeArguments":["string","float32"]}}]},{"name":"mapField","type":{"map":{"keys":"string","values":"string"}}}]},{"name":"Tuple","typeParameters":["T1","T2"],"fields":[{"name":"v1","type":"T1"},{"name":"v2","type":"T2"}]}]})"; std::vector ProtocolWithComputedFieldsWriterBase::previous_schemas_ = { }; diff --git a/cpp/test/generated/protocols.h b/cpp/test/generated/protocols.h index ebea114d..f3decd7c 100644 --- a/cpp/test/generated/protocols.h +++ b/cpp/test/generated/protocols.h @@ -1563,6 +1563,98 @@ class DynamicNDArraysReaderBase { uint8_t state_ = 0; }; +// Abstract writer for the MultiDArrays protocol. +class MultiDArraysWriterBase { + public: + // Ordinal 0. + // Call this method for each element of the `images` stream, then call `EndImages() when done.` + void WriteImages(yardl::NDArray const& value); + + // Ordinal 0. + // Call this method to write many values to the `images` stream, then call `EndImages()` when done. + void WriteImages(std::vector> const& values); + + // Marks the end of the `images` stream. + void EndImages(); + + // Ordinal 1. + // Call this method for each element of the `frames` stream, then call `EndFrames() when done.` + void WriteFrames(yardl::FixedNDArray const& value); + + // Ordinal 1. + // Call this method to write many values to the `frames` stream, then call `EndFrames()` when done. + void WriteFrames(std::vector> const& values); + + // Marks the end of the `frames` stream. + void EndFrames(); + + // Optionaly close this writer before destructing. Validates that all steps were completed. + void Close(); + + virtual ~MultiDArraysWriterBase() = default; + + // Flushes all buffered data. + virtual void Flush() {} + + protected: + virtual void WriteImagesImpl(yardl::NDArray const& value) = 0; + virtual void WriteImagesImpl(std::vector> const& value); + virtual void EndImagesImpl() = 0; + virtual void WriteFramesImpl(yardl::FixedNDArray const& value) = 0; + virtual void WriteFramesImpl(std::vector> const& value); + virtual void EndFramesImpl() = 0; + virtual void CloseImpl() {} + + static std::string schema_; + + static std::vector previous_schemas_; + + static std::string SchemaFromVersion(Version version); + + private: + uint8_t state_ = 0; + + friend class MultiDArraysReaderBase; +}; + +// Abstract reader for the MultiDArrays protocol. +class MultiDArraysReaderBase { + public: + // Ordinal 0. + [[nodiscard]] bool ReadImages(yardl::NDArray& value); + + // Ordinal 0. + [[nodiscard]] bool ReadImages(std::vector>& values); + + // Ordinal 1. + [[nodiscard]] bool ReadFrames(yardl::FixedNDArray& value); + + // Ordinal 1. + [[nodiscard]] bool ReadFrames(std::vector>& values); + + // Optionaly close this writer before destructing. Validates that all steps were completely read. + void Close(); + + void CopyTo(MultiDArraysWriterBase& writer, size_t images_buffer_size = 1, size_t frames_buffer_size = 1); + + virtual ~MultiDArraysReaderBase() = default; + + protected: + virtual bool ReadImagesImpl(yardl::NDArray& value) = 0; + virtual bool ReadImagesImpl(std::vector>& values); + virtual bool ReadFramesImpl(yardl::FixedNDArray& value) = 0; + virtual bool ReadFramesImpl(std::vector>& values); + virtual void CloseImpl() {} + static std::string schema_; + + static std::vector previous_schemas_; + + static Version VersionFromSchema(const std::string& schema); + + private: + uint8_t state_ = 0; +}; + // Abstract writer for the Maps protocol. class MapsWriterBase { public: diff --git a/cpp/test/generated/translator_impl.cc b/cpp/test/generated/translator_impl.cc index dee84daa..8fab9a21 100644 --- a/cpp/test/generated/translator_impl.cc +++ b/cpp/test/generated/translator_impl.cc @@ -238,6 +238,17 @@ void TranslateStream(std::string const& protocol_name, yardl::testing::Format in reader->CopyTo(*writer); return; } + if (protocol_name == "MultiDArrays") { + auto reader = input_format == yardl::testing::Format::kBinary + ? std::unique_ptr(new test_model::binary::MultiDArraysReader(input)) + : std::unique_ptr(new test_model::ndjson::MultiDArraysReader(input)); + + auto writer = output_format == yardl::testing::Format::kBinary + ? std::unique_ptr(new test_model::binary::MultiDArraysWriter(output)) + : std::unique_ptr(new test_model::ndjson::MultiDArraysWriter(output)); + reader->CopyTo(*writer); + return; + } if (protocol_name == "Maps") { auto reader = input_format == yardl::testing::Format::kBinary ? std::unique_ptr(new test_model::binary::MapsReader(input)) diff --git a/cpp/test/generated/types.h b/cpp/test/generated/types.h index 109b55c3..e51f96d1 100644 --- a/cpp/test/generated/types.h +++ b/cpp/test/generated/types.h @@ -908,6 +908,7 @@ struct RecordWithComputedFields { std::vector vector_field{}; std::vector> vector_of_vectors_field{}; std::array fixed_vector_field{}; + std::array, 2> fixed_vector_of_vectors_field{}; std::optional optional_named_array{}; std::variant int_float_union{}; std::variant nullable_int_float_union{}; @@ -1030,6 +1031,14 @@ struct RecordWithComputedFields { return const_cast(std::as_const(*this).AccessVectorOfVectorsField()); } + int32_t const& AccessFixedVectorOfVectorsField() const { + return fixed_vector_of_vectors_field.at(1).at(2); + } + + int32_t& AccessFixedVectorOfVectorsField() { + return const_cast(std::as_const(*this).AccessFixedVectorOfVectorsField()); + } + yardl::Size ArraySize() const { return array_field.size(); } @@ -1090,6 +1099,10 @@ struct RecordWithComputedFields { return 3ULL; } + yardl::Size FixedVectorOfVectorsSize() const { + return 2ULL; + } + yardl::Size ArrayDimensionXIndex() const { return 0ULL; } @@ -1345,6 +1358,7 @@ struct RecordWithComputedFields { vector_field == other.vector_field && vector_of_vectors_field == other.vector_of_vectors_field && fixed_vector_field == other.fixed_vector_field && + fixed_vector_of_vectors_field == other.fixed_vector_of_vectors_field && optional_named_array == other.optional_named_array && int_float_union == other.int_float_union && nullable_int_float_union == other.nullable_int_float_union && diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index c07405f3..054fcc9a 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -20,6 +20,11 @@ export default defineConfig({ link: "/cpp/introduction", activeMatch: "/cpp/", }, + { + text: "Matlab Documentation", + link: "/matlab/introduction", + activeMatch: "/matlab/", + }, { text: "Reference", link: "/reference/binary", @@ -70,6 +75,26 @@ export default defineConfig({ }, { text: "Reference", link: "/reference/binary" }, ], + "/matlab/": [ + { + text: "Getting Started (Matlab)", + collapsed: false, + items: [ + { text: "Introduction", link: "/matlab/introduction" }, + { text: "Quick Start", link: "/matlab/quickstart" }, + ], + }, + { + text: "Yardl Guide (Matlab)", + collapsed: false, + items: [ + { text: "Packages", link: "/matlab/packages" }, + { text: "The Yardl Language", link: "/matlab/language" }, + // { text: "Schema Evolution", link: "/matlab/evolution" }, + ], + }, + { text: "Reference", link: "/reference/binary" }, + ], "/reference/": [ { text: "Reference", @@ -116,6 +141,10 @@ export default defineConfig({ if (documentId.startsWith("/yardl/python")) { return ["Python"].concat(fieldValue); } + + if (documentId.startsWith("/yardl/matlab")) { + return ["Matlab"].concat(fieldValue); + } } return fieldValue; diff --git a/docs/cpp/language.md b/docs/cpp/language.md index 2e848eda..6ec50b3e 100644 --- a/docs/cpp/language.md +++ b/docs/cpp/language.md @@ -95,7 +95,7 @@ Yardl has the following primitive types: | `int32` | | | `int` | Alias of `int32` | | `uint32` | | -| `uint` | Alias of `unit32` | +| `uint` | Alias of `uint32` | | `int64` | | | `long` | Alias of `int64` | | `uint64` | | @@ -249,7 +249,7 @@ Or with explicit values and an optional base type: ```yaml Permissions: !flags - base: unit8 + base: uint8 values: read: 1 write: 2 diff --git a/docs/cpp/packages.md b/docs/cpp/packages.md index 9410fb27..0690bf0c 100644 --- a/docs/cpp/packages.md +++ b/docs/cpp/packages.md @@ -45,6 +45,11 @@ cpp: python: # The directory where the generated Python package will be written outputDir: ../path/relative/to/this/file + +# Settings for MATLAB code generation (optional) +matlab: + # The directory where the generated MATLAB packages will be written + outputDir: ../path/relative/to/this/file ``` In the future, this file will be able to reference previous versions of diff --git a/docs/index.md b/docs/index.md index 905344ad..4eb348e4 100644 --- a/docs/index.md +++ b/docs/index.md @@ -15,13 +15,16 @@ hero: - theme: brand text: Get Started With C++ link: /cpp/installation + - theme: brand + text: Get Started With MATLAB + link: /matlab/quickstart - theme: alt text: View on GitHub link: https://github.com/microsoft/yardl features: - title: Multiple Languages - details: Define your model in a simple YAML syntax and generate clean Python and C++. + details: Define your model in a simple YAML syntax and generate clean Python, C++, and MATLAB. - title: Multiple Formats details: Supports writing to a compact binary format, NDJSON, or HDF5. - title: Stream-Oriented diff --git a/docs/matlab/evolution.md b/docs/matlab/evolution.md new file mode 100644 index 00000000..47f3bb5c --- /dev/null +++ b/docs/matlab/evolution.md @@ -0,0 +1 @@ + diff --git a/docs/matlab/introduction.md b/docs/matlab/introduction.md new file mode 100644 index 00000000..3b31ecd2 --- /dev/null +++ b/docs/matlab/introduction.md @@ -0,0 +1,68 @@ +# Introduction + +Yardl is a simple schema language and command-line tool that generates domain +types and serialization code. + +:::details Simple Example +Given a Yardl definition like this: + +```yaml +# This is an example protocol, which is defined as a Header value +# followed by a stream of zero or more Sample values +MyProtocol: !protocol + sequence: + header: Header + samples: !stream + items: Sample + +# Header is a record with a single string field +Header: !record + fields: + subject: string + +# Sample is a record made up of a datetime and +# a vector of integers +Sample: !record + fields: + timestamp: datetime + data: int* +``` + +After running `yardl generate`, you can write code like the following to write +data to a file in a compact binary format: + +```matlab +addpath("./matlab/"); + +Sample = @sandbox.Sample; +samples = [Sample(yardl.DateTime.now(), [1, 2, 3]), Sample(yardl.DateTime.now(), [4, 5, 6])]; + +outfile = "sandbox.bin"; + +w = sandbox.binary.MyProtocolWriter(outfile); +w.write_header(sandbox.Header("Me")); +w.write_samples(samples); +w.end_samples(); +w.close(); +``` + +And then another script can read it in from the file: + +```matlab +addpath("./matlab/"); + +infile = "sandbox.bin"; + +r = sandbox.binary.MyProtocolReader(infile); +disp(r.read_header()); +while r.has_samples() + sample = r.read_samples(); + disp(sample.timestamp.to_datetime()); + disp(sample.data); +end +r.close(); +``` + +::: + + diff --git a/docs/matlab/language.md b/docs/matlab/language.md new file mode 100644 index 00000000..df617d77 --- /dev/null +++ b/docs/matlab/language.md @@ -0,0 +1,753 @@ +# The Yardl Language + +:::info Note + +The MATLAB implementation supports the binary format, but does not +currently support HDF5 or NDJSON. + +::: + +Yardl model files use YAML syntax and are required to have either a `.yml` or +`.yaml` file extension. + +To efficiently work with Yardl, we recommend that you run the following from the +yardl package (model) directory: + +```bash +yardl generate --watch +``` + +This watches the directory for changes and generates code whenever a file is +saved. This allows you to get rapid feedback as you experiment. + +Comments placed above top-level types and their fields are captured and added to +the generated code as docstrings. + +`yardl generate` only generates code once the model files in the package have +been validated. It will write out any validation errors to standard error. + +## Protocols + +As explained in the [quick start](quickstart), protocols define a sequence of +values, called "steps", that are required to be transmitted, in order. They are +defined like this: + +```yaml +MyProtocol: !protocol + sequence: + a: int + b: !stream + items: float + c: !stream + items: string +``` + +In the example, the first step is a single integer named `a`. Following that +will be a stream (named `b`) of zero or more floating-point numbers, and a +stream (named `c`) of strings. + +You can write to this protocol like this: + +```matlab +w = sandbox.binary.MyProtocolWriter("sandbox.bin"); + +w.write_a(1); % Write single protocol step + +w.write_b(1:10); % Write stream items +w.end_b(); % Call stream end method to signal that it is complete + +w.write_c(["a", "b"]); % Write stream items +w.write_c(["c", "d"]); % Write more stream items +w.end_c(); % Signal that the 'c' stream is complete + +w.close(); % Must close the Writer +``` + +And read the data back like this: + +```matlab +r = sandbox.binary.MyProtocolReader("sandbox.bin"); + +disp(r.read_a()); % Read single protocol step + +while r.has_b() % Check whether stream has ended + disp(r.read_b()); % Read stream items in a loop +end + +while r.has_c() % Check whether stream has ended + disp(r.read_c()); % Read stream items in a loop +end + +r.close(); % Must close the reader +``` + +It is an error to attempt to read or write a protocol's steps out of order or to +close a reader or writer without having written or read all steps. + +```matlab +w = sandbox.binary.MyProtocolWriter("sandbox.bin"); +w.write_b(1:10); % Error: Expected to call to 'write_a' but received call to 'write_b' // [!code error] +``` + +Generated protocol readers have a `copy_to()` method that allows you to copy the +contents of the protocol to another protocol writer. This makes is easy to, say, +read from an NDJSON file and send the data in the binary format over a network +connection. + +## Records + +Records have fields and, optionally, [computed fields](#computed-fields). In +generated MATLAB code, they map to class definitions. + +Fields have a name and can be of any primitive or compound type. For example: + +```yaml +MyRecord: !record + fields: + myIntField: int + myStringField: string +``` + +Records must be declared at the top level and cannot be inlined. For example, +this is not supported: + +```yaml +RecordA: !record + fields: + recA: !record # NOT SUPPORTED! // [!code error] + fields: // [!code error] + a: int // [!code error] + recB: RecordB # But this is fine. + +RecordB: !record + fields: + c: int +``` + +Note that Yardl does not support type inheritance. + +The generated class constructors accept *named* arguments for each field and +in most cases they are optional. They are only required when the field type is +[generic](#generics). + +Example: + +```matlab +r1 = MyRecord(); +r1.myIntField = uint32(42); +r1.myStringField = "hello, world"; + +r2 = MyRecord(myIntField=uint32(42), myStringField="hello, world"); +``` + +## Primitive Types + +Yardl has the following primitive types: + +| Yardl Type | Comment | MATLAB Type | +| ---------------- | ----------------------------------------------------------------------- | -------------------| +| `bool` | | `logical` | +| `int8` | | `int8` | +| `uint8` | | `uint8` | +| `byte` | Alias of `uint8` | | +| `int16` | | `int16` | +| `uint16` | | `uint16` | +| `int32` | | `int32` | +| `int` | Alias of `int32` | | +| `uint32` | | `uint32` | +| `uint` | Alias of `unit32` | | +| `int64` | | `int64` | +| `long` | Alias of `int64` | | +| `uint64` | | `uint64` | +| `ulong` | Alias of `uint64` | | +| `size` | Equivalent to `uint64` | | +| `float32` | | `single` | +| `float` | Alias of `float32` | | +| `float64` | | `double` | +| `double` | Alias of `float64` | | +| `complexfloat32` | A complex number where each component is a 32-bit floating-point number | `complex(single)` | +| `complexfloat` | Alias of `complexfloat32` | | +| `complexfloat64` | A complex number where each component is a 64-bit floating-point number | `complex(double)` | +| `complexdouble` | Alias of `complexfloat64` | | +| `string` | | `string` | +| `date` | A number of days since the epoch | `yardl.Date` | +| `time` | A number of nanoseconds after midnight | `yardl.Time` | +| `datetime` | A number of nanoseconds since the epoch | `yardl.DateTime` | + +`yardl.Date`, `yardl.Time`, and `yardl.DateTime` are custom classes because +Yardl uses nanosecond precision and MATLAB's `datetime` has only microsecond precision. +Each of them can be easily converted to/from a MATLAB `datetime` by calling +the corresponding `to_datetime()` or `from_datetime()` method. + +## Optional Types + +If a value is optional, its type has a `?` suffix. + +```yaml +Rec: !record + fields: + optionalInt: int? +``` + +They can also be expressed as a YAML array of length two, with `null` in the +first position: + +```yaml +Rec: !record + fields: + optionalInt: [null, int] # equivalent to the example above +``` + +In MATLAB, optional values can be instantiated using `yardl.Optional(value)`, and have the value `yardl.None` when not set. + +## Unions + +Optional types are a special case of unions, which are used when a value can be +one of several types: + +```yaml +Rec: !record + fields: + intOrFloat: [int, float] + intOrFloatExpandedForm: + - int + - float + nullableIntOrFloat: + - null + - int + - float +``` + +The `null` type in the example above means that no value (`yardl.None` in MATLAB) is +also a possibility. + +### Generated Union Types + +For the MATLAB codegen, we represent unions as a [tagged +union](https://en.wikipedia.org/wiki/Tagged_union) and we generate a class for +each union in a model. In the example above, the union `[int, float]` would have +a class named `Int32OrFloat32`. Each union case then has a corresponding static +constructor method in the union class. + +This union class can be used like this: + +```matlab +function process_my_union(u) + if u.isInt32() + fprintf("%d is an int32\n", u.value); + elseif u.isFloat32() + fprintf("%f is a float\n", u.value); + else + error("Unrecognized union type"); + end +end + +process_my_union(sandbox.Int32OrFloat32.Int32(2)) +process_my_union(sandbox.Int32OrFloat32.Float32(7.9)) +``` + +### Union Tag Names + +The type case name used in union classes (`Int32` and `Float32` in the example +above) is derived from the name of the type of each case. This means that you +will get an error when attempting to use a type in a union that is made up of +symbols that are not valid in an identifier. For example: + +```yaml +Rec: !record + fields: + floatArrayOrDoubleArray: + - float[] # Error! // [!code error] + - double[] # Error! // [!code error] +``` + +There are two simple solutions to this problem. The first is to give explicit +tag names to each union case using the expanded `!union` syntax: + +```yaml +Rec: !record + fields: + floatArrayOrDoubleArray: !union + floatArray: float[] + doubleArray: double[] +``` + +The second option is to create [aliases](#type-aliases) for the types: + +```yaml + +FloatArray: float[] +DoubleArray: double[] + +Rec: !record + fields: + floatArrayOrDoubleArray: + - FloatArray + - DoubleArray +``` + +The first option is usually preferred, unless the type alias is going to be used +elsewhere. In both cases, the union type will be `FloatArrayOrDoubleArray` and +the cases `FloatArray` and `DoubleArray`. + +If you don't like the generated name you can give the union an +[alias](#type-aliases): + +```yaml +ArrayUnion: !union + floatArray: float[] + doubleArray: double[] + +Rec: !record + fields: + arrayUnion: ArrayUnion +``` + +Now the union class is `ArrayUnion` with case types `FloatArray` and `DoubleArray`. + +## Enums + +Enums can be defined as a list of values: + +```yaml +Fruits: !enum + values: + - apple + - banana + - pear +``` + +Enums are generated as custom MATLAB class definitions, *not* using MATLAB's `enumeration` support, which doesn't allow integer values that are not explicitly defined in the enum definition. + +In MATLAB, use the enum constructor to create new values, or the generated static methods for predefined values: + +```matlab +fruit1 = sandbox.Fruits.APPLE; +fruit2 = sandbox.Fruits.BANANA; +newFruit = sandbox.Fruits(42); +``` + +You can optionally specify the underlying type of the enum and give each symbol +an integer value: + +```yaml +UInt64Enum: !enum + base: uint64 + values: + a: 0x1 + b: 0x2 + c: 20 +``` + +Any integer values that are left blank will be: + +- 0 if the first value +- 1 greater than the previous value if positive +- 1 less that the previous value if negative. + +## Flags + +Flags are similar to enums but are meant to represent a bit field, meaning +multiple values can be set at once. + +They can be defined with automatic values: + +```yaml +Permissions: !flags + values: + - read + - write + - execute +``` + +Or with explicit values and an optional base type: + +```yaml +Permissions: !flags + base: uint8 + values: + read: 1 + write: 2 + execute: +``` + +Any value without an integer value will have the next power of two bit set that +is greater than the previous value. In the example above, `execute` would have +the value 4. + +Like Enums, Flags are generated as custom MATLAB class definitions. + +Example usage: + +```matlab +permissions = bitor(sandbox.Permissions.READ, sandbox.Permissions.EXECUTE); +% Or +permissions = sandbox.Permissions.READ.with_flag(sandbox.Permissions.EXECUTE); +% ... +if bitand(sandbox.Permissions.READ, permissions) + % ... +end +% Or +if permissions.has_flags(sandbox.Permissions.READ) + % ... +end +``` + +## Maps + +Maps, also known as dictionaries or associative arrays, are an unordered +collection of key-value pairs. + +They can be declared like this: + +```yaml +MyMap: string->int +``` + +Or declared with the expanded syntax: + +```yaml +MyMap: !map + keys: string + values: int +``` + +Keys are required to be scalar primitive types. + +These map to the MATLAB `dictionary` type. + +:::info Note + +MATLAB's `dictionary` type was introduced in MATLAB r2022b, effectively replacing +the `containers.Map` type. The `containers.Map` does not provide sufficient +support for yardl types (including primitive strings) as keys or values. + +::: + + +## Vectors + +Vectors are one-dimensional lists. They can optionally have a fixed length. The +simple syntax for vectors is `*[length]`. + +For example: + +```yaml +MyRec: !record + fields: + vec1: int* + vec2: int*10 +``` + +In the example above, `vec1` is a vector of integers of unknown length and +`vec2` has length 10. The expanded syntax for vectors is: + +```yaml +MyRec: !record + fields: + vec1: !vector + items: int + vec2: !vector + items: int + length: 10 +``` + +Both flavors of vectors are generated as MATLAB arrays. +The generated protocol readers/writers also support cell arrays as vectors. +When working with vectors of vectors, the last dimension represents the outer vector: + +```matlab +% Create a vector of integers +vs = [1, 2, 3, 4]; + +% Create a vector of 3 vectors, each of length 4 +vs = [[1; 2; 3; 4], [5; 6; 7; 8], [9; 10; 11; 12]]; + +% Create a vector of 3 vectors, each of varying length +vs = { [1, 2, 3], [4, 5], [7] }; +``` + +## Arrays + +Arrays are multidimensional and map to MATLAB arrays. Like vectors, there is a simple +syntax and an expanded syntax for declaring them. Both syntaxes are shown in the +examples below. + +There are three kinds of arrays. They can be of a fixed size: + +```yaml +MyRec: !record + fields: + fixedNdArray: float[3, 4] + fixedNdArrayExpandedSyntax: !array + items: float + dimensions: [3, 4] +``` + +Or the size might not be fixed but the number of dimensions is known: + +```yaml +MyRec: !record + fields: + ndArray: float[,] + ndArrayExpandedSyntax: !array + items: float + dimensions: 2 +``` + +Or finally, the number of dimensions may be unknown as well: + +```yaml +MyRec: !record + fields: + dynamicNdArray: float[] + dynamicNdArrayExpandedSyntax: !array + items: float +``` + +Dimensions can be given names, which can be used in [computed +field](#computed-fields) expressions. + +```yaml +MyRec: !record + fields: + fixedNdArray: float[x:3, y:4] + fixedNdArrayExpandedSyntax: !array + items: float + dimensions: + x: 3 + y: 4 + ndArray: !array + items: float + dimensions: [x, y] + ndArrayExpandedSyntax: !array + items: float + dimensions: [x, y] + ndArrayExpandedSyntaxAlternate: !array + items: float + dimensions: + x: + y: +``` + +In the simple syntax, `int[]` means an int array with an unknown number of +dimensions, and `int[,]` means an int array with two dimensions. To declare an +array with 1 dimension of unknown length, you can either give the dimension a +name (`int[x]`) or use parentheses to disambiguate from an empty set of +dimensions: `int[()]`. + +### MATLAB Arrays + +In MATLAB, arrays are always created with dimensions reversed with respect to the model definition. +This means that an array defined as `Image: double[x, y, z]` has the shape `[z, y, x]` in MATLAB. + +Yardl currently supports serializing multi-dimensional arrays only in +C-continguous order, where the last dimension increases most rapidly. +MATLAB, however, uses Fortran-order to store and serialize multi-dimensional +arrays, where the first dimension increases most rapidly. + +By reversing MATLAB array dimensions, yardl maintains consistency with MATLAB's +support for multi-dimensional array indexing, and provides optimal serialization performance. + +As a side effect, if you define a *matrix* in yardl as `matrix: double[row, col]`, +you will need to transpose the array in MATLAB. + +Example: + +```yaml +MyProtocol: !protocol + sequence: + fixedArray: double[x:2, y:4] +``` + +```matlab +>> r = sandbox.binary.MyProtocolReader(filename); +>> image = r.read_image(); +>> size(image) + +ans = + + 4 2 + +``` + +To create an array with more than two dimensions, use MATLAB pages: + +```yaml +ndarray: double[2, 3, 4] +``` + +```matlab +>> ndarray(:, :, 1) = [[ 1; 2; 3; 4], [ 5; 6; 7; 8], [ 9; 10; 11; 12]]; +>> ndarray(:, :, 2) = [[13; 14; 15; 16], [17; 18; 19; 20], [21; 22; 23; 24]]; +>> size(ndarray) + +ans = + + 4 3 2 + +``` + +## Type Aliases + +Any type can be given one or more aliases: + +```yaml +FloatArray: float[] + +SignedInteger: [int8, int16, int32, int64] + +Id: string +Name: string +``` + +This simply gives another name to a type, so the `Name` type above is no +different from the `string` type. + +In MATLAB, aliases are generated in one of three forms: +1. Union class definition for union types +2. Function wrapper for optionals/vectors/arrays +3. Subclass definitions for all other types + +In all cases, you can use the generated syntax to construct the aliased type. + +## Computed Fields + +In addition to fields, records can contain computed fields. These are simple expressions +over the record's other (computed) fields. + +```yaml +MyRec: !record + fields: + arrayField: int[x,y] + computedFields: + accessArray: arrayField + accessArrayElement: arrayField[0, 1] + accessArrayElementByName: arrayField[x:0, y:1] + accessArrayElementAndConvert: arrayField[0, 1] as int + sizeOfArrayField: size(arrayField) + sizeOfFirstDimension: size(arrayField, 0) + sizeOfXDimension: size(arrayField, 'x') + basicArithmentic: arrayField[0, 1] * 2 +``` + +The following expression types are supported: +- Numeric literals, such as `1`, `-1`, `0xF`, `3.4`, and `-2e-3`. +- String literals, such as `"abc"` and `'abc'`. +- Simple arithmethic expresions, such as `1 + 2`, `2.0 * 3`, and `2 ** 3` (`**` + is the power operator and yields a `float64`). +- Type conversions using the `as` operator, such as `1 as float64`. +- Field accesses, such as `myField`. You can access a field on another field + using the `.` operator, such as `myField.anotherField`. +- Array and vector element access, such as `arrayField[0, 1]` or + `arrayField[x:0, y:1]` to identify the dimensions by name. +- Function calls: + - `size(vector)`: returns the size (length) of the vector. + - `size(array)`: returns the total size of the array. + - `size(array, integer)`: returns the size of the array's dimension at the given + index. + - `size(array, string)`: returns the size of the array's dimension with the + given name. + - `dimensionIndex(array, string)` returns the index of the dimension with the + given name. + - `dimensionCount(array)` returns the dimension count of the array. + +To work with union or optional types, you need to use a switch expression with type pattern +matching: + +```yaml +NamedArray: int[x, y] + +MyRec: !record + fields: + myUnion: [null, int, NamedArray] + computedFields: + myUnionSize: + !switch myUnion: + int: 1 # if the union holds an int + NamedArray arr: size(arr) # if it's a NamedArray. Note the variable declaration. + _: 0 # all other cases (here it's just null) +``` + +Computed fields become parameterless methods on the generated Python class. Here +is an example of invoking the field from the preceding Yardl definition: + +```matlab +>> rec = sandbox.MyRec(my_union=sandbox.Int32OrNamedArray.Int32(4)); +>> rec.my_union_size() + +ans = + + 1 + +>> arr = sandbox.NamedArray(int32(ones(7))); +>> rec = sandbox.MyRec(my_union=sandbox.Int32OrNamedArray.NamedArray(arr)); +>> rec.my_union_size() + +ans = + + 49 + +>> rec = sandbox.MyRec(my_union=yardl.None); +>> rec.my_union_size() + +ans = + + 0 + +``` + +## Generics + +Yardl supports generic types. + +```yaml +Point: !record + fields: + x: T + y: T + +MyProtocol: !protocol + sequence: + point: Point +``` + +Here `Point` is a generic type with one type parameter `T`, while `MyProtocol` +references `Point` with `int` as its type argument. + +Records and type aliases can be generic, but enums, flags, and protocols cannot. + +In MATLAB, generics are treated as open types. +Type validation occurs when values are written using a ProtocolWriter. + +```matlab +p = sandbox.Point(1, 2); + +w = sandbox.binary.MyProtocolWriter("sandbox.bin"); +w.write_point(p); +w.close(); + +p = sandbox.Point(x="a", y="b"); +w = sandbox.binary.MyProtocolWriter("sandbox.bin"); +w.write_point(p); % Error: ...Value must be of type int32 or be convertible to int32. // [!code error] +w.close(); +``` + +## Imported Types + +Types can be imported from other packages (see [Packages](packages)) and referenced +through their respective yardl namespace: + +```yaml +MyTuple: BasicTypes.Tuple +``` + +Imported types are likewise namespaced in MATLAB packages: + +```matlab +t1 = basic_types.Tuple(v1="John Smith", v2=42); +t2 = sandbox.MyTuple(v1="John Smith", v2=42); +assert(t1 == t2); +``` + +Note that yardl ignores protocols defined in imported packages. diff --git a/docs/matlab/packages.md b/docs/matlab/packages.md new file mode 100644 index 00000000..ee39bceb --- /dev/null +++ b/docs/matlab/packages.md @@ -0,0 +1 @@ + diff --git a/docs/matlab/quickstart.md b/docs/matlab/quickstart.md new file mode 100644 index 00000000..2c17595d --- /dev/null +++ b/docs/matlab/quickstart.md @@ -0,0 +1,178 @@ +# Quick Start + +## Installation + + + +### Dependencies + +The generated MATLAB code requires MATLAB R2022b or newer. + +## Getting our Feet Wet + +::: info Note +Yardl is currently based on YAML. If you are new to YAML, you can get an +overview [here](https://learnxinyminutes.com/docs/yaml/). +::: + +To get started, create a new empty directory and `cd` into it. Then run: + +``` bash +yardl init playground +``` + +This creates the initial structure and files for our project: + +```txt +$ tree . +. +└── model + ├── model.yml + └── _package.yml +``` + +The Yardl model package is in the `model` directory. + +`_package.yml` is the package's manifest. + +``` yaml +namespace: Playground + +cpp: + sourcesOutputDir: ../cpp/generated + +python: + outputDir: ../python + +matlab: + outputDir: ../matlab +``` + +It specifies the package's namespace along with code generation settings. The +`matlab.outputDir` property specifies where the generated MATLAB package should +go. If you are not interested in generating Python or C++ code, you can remove +the corresponding property from the file: + +``` yaml +namespace: Playground + +cpp: // [!code --] + sourcesOutputDir: ../cpp/generated // [!code --] + +python: // [!code --] + outputDir: ../python // [!code --] + +matlab: + outputDir: ../matlab +``` + +All other `.yml` and `.yaml` files in the directory are assumed to be yardl +model files. The contents of `model.yml` look like this: + +```yaml +# This is an example protocol, which is defined as a Header value +# followed by a stream of zero or more Sample values +MyProtocol: !protocol + sequence: + + # A Header value + header: Header + + # A stream of Samples + samples: !stream + items: Sample + +# Header is a record with a single string field +Header: !record + fields: + subject: string + +# Sample is a record made up of a datetime and +# a vector of integers +Sample: !record + fields: + + # The time the sample was taken + timestamp: datetime + + # A vector of integers + data: int* +``` + +`!protocol`, `!stream` and `!record` are custom YAML tags, which describe the +type of the YAML node that follows. + +`MyProtocol` is a protocol, which is a defined sequence of values that can be +written to or read from a file or binary stream (e.g. over a network +connection). This example protocol says that there will be one `Header` value +followed by an unknown number of `Sample`s. `Header` and `Sample` are records. + +To generate MATLAB code for this model, `cd` into the `model` directory and run: + +```bash +yardl generate +``` + +This will generate a MATLAB package in the `outputDir` directory: + +```txt +$ tree . +. +├── +playground +│ ├── +binary +│ │ ├── HeaderSerializer.m +│ │ ├── MyProtocolReader.m +│ │ ├── MyProtocolWriter.m +│ │ └── SampleSerializer.m +│ ├── Header.m +│ ├── MyProtocolReaderBase.m +│ ├── MyProtocolWriterBase.m +│ └── Sample.m +└── +yardl + ├── +binary + │ └── ... + └── ... +``` + +The top-level package, e.g. `+playground`, contains the class definitions for (1) the non-protocol types defined in our model (in this case, `Header.m` and `Sample.m`), and (2) the abstract protocol reader and writer classes, from which concrete implementations inherit from (e.g. in the `+binary` subpackage). + +The adjacent `+yardl` package contains definitions for primitive types, error handling, and serializers. + +To use these packages from outside of the `matlab` directory, use MATLAB's `addpath` function, e.g. `addpath("../path/to/parent/directory");`. + +Ok, let's write some code! In our `matlab` directory (containing the generated +`+playground` package), create `run_playground.m` that looks like this: + +```matlab +Sample = @playground.Sample; +samples = [Sample(yardl.DateTime.now(), [1, 2, 3]), Sample(yardl.DateTime.now(), [4, 5, 6])]; + +path = "playground.bin"; + +w = playground.binary.MyProtocolWriter(path); +w.write_header(playground.Header("Me")); +w.write_samples(samples); +w.end_samples(); +w.close(); + +r = playground.binary.MyProtocolReader(path); +disp(r.read_header()); +while r.has_samples() + sample = r.read_samples(); + disp(sample.timestamp.to_datetime()); + disp(sample.data); +end +r.close(); +``` + +Run this directly in MATLAB, e.g. `run_playground`, or on the command-line with `matlab -batch run_playground`. + +You can inspect the binary file our code produced with: + +```bash +hexdump -C playground.bin +``` + +Note that the binary file contains a JSON representation of the protocol's +schema. This allows code that was not previously aware of this protocol to +deserialize the contents. diff --git a/docs/parts/intro-core.md b/docs/parts/intro-core.md index be217adf..19b2f044 100644 --- a/docs/parts/intro-core.md +++ b/docs/parts/intro-core.md @@ -33,9 +33,6 @@ expect to introduce breaking changes until the project reaches V1. We currently support C++ and Python codegen. Other planned features include: -- Reading data with a different schema version -- MATLAB support -- References between packages -- Validating schema evolution is non-breaking +- Python and MATLAB support for reading data with a different schema version - Constraints - Improvements to the language and editing experience diff --git a/docs/python/language.md b/docs/python/language.md index cad6b1a1..33302c0e 100644 --- a/docs/python/language.md +++ b/docs/python/language.md @@ -133,7 +133,7 @@ Yardl has the following primitive types: | `int32` | | `yardl.Int32` | `int` | | `int` | Alias of `int32` | | | | `uint32` | | `yardl.UInt32` | `int` | -| `uint` | Alias of `unit32` | | | +| `uint` | Alias of `uint32` | | | | `int64` | | `yardl.Int64` | `int` | | `long` | Alias of `int64` | | | | `uint64` | | `yardl.UInt64` | `int` | @@ -391,7 +391,7 @@ Or with explicit values and an optional base type: ```yaml Permissions: !flags - base: unit8 + base: uint8 values: read: 1 write: 2 diff --git a/justfile b/justfile index bcbacff4..f222e2e2 100644 --- a/justfile +++ b/justfile @@ -2,6 +2,12 @@ set shell := ['bash', '-ceuo', 'pipefail'] cpp_version := "17" +matlab := "disabled" +matlab-test-cmd := if matlab != "disabled" { "run-matlab-command run_tests" } else { "echo Skipping Matlab tests..." } +matlab-sandbox-cmd := if matlab != "disabled" { "run-matlab-command run_sandbox" } else { "echo Skipping Matlab sandbox..." } +benchmark-cmd := if matlab != "disabled" { "python python/benchmark.py --include-matlab" } else { "python python/benchmark.py" } + + @default: validate echo $'\n\e[1;34mNote: you can run \'just test\' to a run an inner-loop subset of the complete validation' @@ -42,9 +48,17 @@ cpp_version := "17" @run-sandbox-python: generate-sandbox python python/run_sandbox.py -@run-sandbox-python-quiet: build-sandbox +@run-sandbox-python-quiet: generate-sandbox python python/run_sandbox.py > /dev/null +@run-sandbox-matlab: generate-sandbox + cd matlab; \ + {{ matlab-sandbox-cmd }} + +@run-sandbox-matlab-quiet: generate-sandbox + cd matlab; \ + {{ matlab-sandbox-cmd }} > /dev/null + @build-all: generate generate-sandbox generate-remote-import generate-evolution configure cd cpp/build && ninja @@ -69,18 +83,22 @@ cpp_version := "17" ninja tests; \ ./tests --gtest_brief=1 +@matlab-test: generate build-translator + cd matlab/test; \ + {{ matlab-test-cmd }} + @evolution-test: generate-evolution ensure-build-dir cd cpp/build; \ ninja evolution/all; \ python ../evolution/test-evolution.py -@test: tooling-test cpp-test python-test evolution-test +@test: tooling-test cpp-test python-test matlab-test evolution-test @benchmark: generate ensure-build-dir cd cpp/build; \ ninja benchmark; \ cd ../..; \ - python python/benchmark.py + {{ benchmark-cmd }} @watch-generate-test: install watchexec -r -c -w tooling/ -- "just install && cd models/test && yardl generate --watch" @@ -101,7 +119,7 @@ type-check: generate generate-sandbox cd python pyright . -@validate: build-all test type-check run-sandbox-quiet run-sandbox-python-quiet benchmark +@validate: build-all test type-check run-sandbox-quiet run-sandbox-python-quiet run-sandbox-matlab-quiet benchmark validate-with-no-changes: validate #!/usr/bin/env bash diff --git a/matlab/.gitignore b/matlab/.gitignore new file mode 100644 index 00000000..6316f0cf --- /dev/null +++ b/matlab/.gitignore @@ -0,0 +1 @@ +generated/+yardl diff --git a/matlab/generated/+basic_types/+binary/GenericRecordWithComputedFieldsSerializer.m b/matlab/generated/+basic_types/+binary/GenericRecordWithComputedFieldsSerializer.m new file mode 100644 index 00000000..779a5551 --- /dev/null +++ b/matlab/generated/+basic_types/+binary/GenericRecordWithComputedFieldsSerializer.m @@ -0,0 +1,24 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef GenericRecordWithComputedFieldsSerializer < yardl.binary.RecordSerializer + methods + function self = GenericRecordWithComputedFieldsSerializer(t0_serializer, t1_serializer) + field_serializers{1} = yardl.binary.UnionSerializer('basic_types.T0OrT1', {t0_serializer, t1_serializer}, {@basic_types.T0OrT1.T0, @basic_types.T0OrT1.T1}); + self@yardl.binary.RecordSerializer('basic_types.GenericRecordWithComputedFields', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) basic_types.GenericRecordWithComputedFields + end + self.write_(outstream, value.f1); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = basic_types.GenericRecordWithComputedFields(f1=fields{1}); + end + end +end diff --git a/matlab/generated/+basic_types/+binary/RecordWithUnionsSerializer.m b/matlab/generated/+basic_types/+binary/RecordWithUnionsSerializer.m new file mode 100644 index 00000000..9ca1bfa1 --- /dev/null +++ b/matlab/generated/+basic_types/+binary/RecordWithUnionsSerializer.m @@ -0,0 +1,26 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithUnionsSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithUnionsSerializer() + field_serializers{1} = yardl.binary.UnionSerializer('basic_types.Int32OrString', {yardl.binary.NoneSerializer, yardl.binary.Int32Serializer, yardl.binary.StringSerializer}, {yardl.None, @basic_types.Int32OrString.Int32, @basic_types.Int32OrString.String}); + field_serializers{2} = yardl.binary.UnionSerializer('basic_types.TimeOrDatetime', {yardl.binary.TimeSerializer, yardl.binary.DatetimeSerializer}, {@basic_types.TimeOrDatetime.Time, @basic_types.TimeOrDatetime.Datetime}); + field_serializers{3} = yardl.binary.UnionSerializer('basic_types.GenericNullableUnion2', {yardl.binary.NoneSerializer, yardl.binary.EnumSerializer('basic_types.Fruits', @basic_types.Fruits, yardl.binary.Int32Serializer), yardl.binary.EnumSerializer('basic_types.DaysOfWeek', @basic_types.DaysOfWeek, yardl.binary.Int32Serializer)}, {yardl.None, @basic_types.GenericNullableUnion2.T1, @basic_types.GenericNullableUnion2.T2}); + self@yardl.binary.RecordSerializer('basic_types.RecordWithUnions', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) basic_types.RecordWithUnions + end + self.write_(outstream, value.null_or_int_or_string, value.date_or_datetime, value.null_or_fruits_or_days_of_week); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = basic_types.RecordWithUnions(null_or_int_or_string=fields{1}, date_or_datetime=fields{2}, null_or_fruits_or_days_of_week=fields{3}); + end + end +end diff --git a/matlab/generated/+basic_types/AliasedMap.m b/matlab/generated/+basic_types/AliasedMap.m new file mode 100644 index 00000000..c594a04e --- /dev/null +++ b/matlab/generated/+basic_types/AliasedMap.m @@ -0,0 +1,5 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function m = AliasedMap(varargin) + m = dictionary(varargin{:}); +end diff --git a/matlab/generated/+basic_types/DaysOfWeek.m b/matlab/generated/+basic_types/DaysOfWeek.m new file mode 100644 index 00000000..f017a5d5 --- /dev/null +++ b/matlab/generated/+basic_types/DaysOfWeek.m @@ -0,0 +1,68 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef DaysOfWeek < uint64 + methods (Static) + function v = MONDAY + v = basic_types.DaysOfWeek(1); + end + function v = TUESDAY + v = basic_types.DaysOfWeek(2); + end + function v = WEDNESDAY + v = basic_types.DaysOfWeek(4); + end + function v = THURSDAY + v = basic_types.DaysOfWeek(8); + end + function v = FRIDAY + v = basic_types.DaysOfWeek(16); + end + function v = SATURDAY + v = basic_types.DaysOfWeek(32); + end + function v = SUNDAY + v = basic_types.DaysOfWeek(64); + end + + function z = zeros(varargin) + elem = basic_types.DaysOfWeek(0); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function self = DaysOfWeek(varargin) + if nargin == 0 + value = 0; + elseif nargin == 1 + value = varargin{1}; + else + value = 0; + for i = 1:nargin + value = bitor(value, varargin{i}); + end + end + self@uint64(value); + end + + function res = has_flags(self, flag) + res = bitand(self, flag) == flag; + end + + function res = with_flags(self, flag) + res = basic_types.DaysOfWeek(bitor(self, flag)); + end + + function res = without_flags(self, flag) + res = basic_types.DaysOfWeek(bitand(self, bitcmp(flag))); + end + end +end diff --git a/matlab/generated/+basic_types/Fruits.m b/matlab/generated/+basic_types/Fruits.m new file mode 100644 index 00000000..684ff6a7 --- /dev/null +++ b/matlab/generated/+basic_types/Fruits.m @@ -0,0 +1,28 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef Fruits < uint64 + methods (Static) + function v = APPLE + v = basic_types.Fruits(0); + end + function v = BANANA + v = basic_types.Fruits(1); + end + function v = PEAR + v = basic_types.Fruits(2); + end + + function z = zeros(varargin) + elem = basic_types.Fruits(0); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+basic_types/GenericNullableUnion2.m b/matlab/generated/+basic_types/GenericNullableUnion2.m new file mode 100644 index 00000000..574e124a --- /dev/null +++ b/matlab/generated/+basic_types/GenericNullableUnion2.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef GenericNullableUnion2 < yardl.Union + methods (Static) + function res = T1(value) + res = basic_types.GenericNullableUnion2(1, value); + end + + function res = T2(value) + res = basic_types.GenericNullableUnion2(2, value); + end + + function z = zeros(varargin) + elem = basic_types.GenericNullableUnion2(0, yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function res = isT1(self) + res = self.index == 1; + end + + function res = isT2(self) + res = self.index == 2; + end + + function eq = eq(self, other) + eq = isa(other, "basic_types.GenericNullableUnion2") && isequal(self.index, other.index) && isequal(self.value, other.value); + end + + function ne = ne(self, other) + ne = ~self.eq(other); + end + + function t = tag(self) + tags_ = ["T1", "T2"]; + t = tags_(self.index_); + end + end +end diff --git a/matlab/generated/+basic_types/GenericRecordWithComputedFields.m b/matlab/generated/+basic_types/GenericRecordWithComputedFields.m new file mode 100644 index 00000000..c7781274 --- /dev/null +++ b/matlab/generated/+basic_types/GenericRecordWithComputedFields.m @@ -0,0 +1,44 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef GenericRecordWithComputedFields < handle + properties + f1 + end + + methods + function self = GenericRecordWithComputedFields(kwargs) + arguments + kwargs.f1; + end + if ~isfield(kwargs, "f1") + throw(yardl.TypeError("Missing required keyword argument 'f1'")) + end + self.f1 = kwargs.f1; + end + + function res = type_index(self) + var1 = self.f1; + if isa(var1, "basic_types.T0OrT1") && var1.index == 1 + res = 0; + return + end + if isa(var1, "basic_types.T0OrT1") && var1.index == 2 + res = 1; + return + end + throw(yardl.RuntimeError("Unexpected union case")) + end + + + function res = eq(self, other) + res = ... + isa(other, "basic_types.GenericRecordWithComputedFields") && ... + isequal(self.f1, other.f1); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + +end diff --git a/matlab/generated/+basic_types/GenericUnion2.m b/matlab/generated/+basic_types/GenericUnion2.m new file mode 100644 index 00000000..610b0703 --- /dev/null +++ b/matlab/generated/+basic_types/GenericUnion2.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef GenericUnion2 < yardl.Union + methods (Static) + function res = T1(value) + res = basic_types.GenericUnion2(1, value); + end + + function res = T2(value) + res = basic_types.GenericUnion2(2, value); + end + + function z = zeros(varargin) + elem = basic_types.GenericUnion2(0, yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function res = isT1(self) + res = self.index == 1; + end + + function res = isT2(self) + res = self.index == 2; + end + + function eq = eq(self, other) + eq = isa(other, "basic_types.GenericUnion2") && isequal(self.index, other.index) && isequal(self.value, other.value); + end + + function ne = ne(self, other) + ne = ~self.eq(other); + end + + function t = tag(self) + tags_ = ["T1", "T2"]; + t = tags_(self.index_); + end + end +end diff --git a/matlab/generated/+basic_types/GenericVector.m b/matlab/generated/+basic_types/GenericVector.m new file mode 100644 index 00000000..09d85a55 --- /dev/null +++ b/matlab/generated/+basic_types/GenericVector.m @@ -0,0 +1,5 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function a = GenericVector(array) + a = array; +end diff --git a/matlab/generated/+basic_types/Int32OrString.m b/matlab/generated/+basic_types/Int32OrString.m new file mode 100644 index 00000000..0afdbb22 --- /dev/null +++ b/matlab/generated/+basic_types/Int32OrString.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef Int32OrString < yardl.Union + methods (Static) + function res = Int32(value) + res = basic_types.Int32OrString(1, value); + end + + function res = String(value) + res = basic_types.Int32OrString(2, value); + end + + function z = zeros(varargin) + elem = basic_types.Int32OrString(0, yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function res = isInt32(self) + res = self.index == 1; + end + + function res = isString(self) + res = self.index == 2; + end + + function eq = eq(self, other) + eq = isa(other, "basic_types.Int32OrString") && isequal(self.index, other.index) && isequal(self.value, other.value); + end + + function ne = ne(self, other) + ne = ~self.eq(other); + end + + function t = tag(self) + tags_ = ["Int32", "String"]; + t = tags_(self.index_); + end + end +end diff --git a/matlab/generated/+basic_types/MyTuple.m b/matlab/generated/+basic_types/MyTuple.m new file mode 100644 index 00000000..2487c8c5 --- /dev/null +++ b/matlab/generated/+basic_types/MyTuple.m @@ -0,0 +1,5 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function c = MyTuple(varargin) + c = tuples.Tuple(varargin{:}); +end diff --git a/matlab/generated/+basic_types/RecordWithUnions.m b/matlab/generated/+basic_types/RecordWithUnions.m new file mode 100644 index 00000000..4dc6416e --- /dev/null +++ b/matlab/generated/+basic_types/RecordWithUnions.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithUnions < handle + properties + null_or_int_or_string + date_or_datetime + null_or_fruits_or_days_of_week + end + + methods + function self = RecordWithUnions(kwargs) + arguments + kwargs.null_or_int_or_string = yardl.None; + kwargs.date_or_datetime = basic_types.TimeOrDatetime.Time(yardl.Time()); + kwargs.null_or_fruits_or_days_of_week = yardl.None; + end + self.null_or_int_or_string = kwargs.null_or_int_or_string; + self.date_or_datetime = kwargs.date_or_datetime; + self.null_or_fruits_or_days_of_week = kwargs.null_or_fruits_or_days_of_week; + end + + function res = eq(self, other) + res = ... + isa(other, "basic_types.RecordWithUnions") && ... + isequal(self.null_or_int_or_string, other.null_or_int_or_string) && ... + isequal(self.date_or_datetime, other.date_or_datetime) && ... + isequal(self.null_or_fruits_or_days_of_week, other.null_or_fruits_or_days_of_week); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = basic_types.RecordWithUnions(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+basic_types/T0OrT1.m b/matlab/generated/+basic_types/T0OrT1.m new file mode 100644 index 00000000..6afa0b43 --- /dev/null +++ b/matlab/generated/+basic_types/T0OrT1.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef T0OrT1 < yardl.Union + methods (Static) + function res = T0(value) + res = basic_types.T0OrT1(1, value); + end + + function res = T1(value) + res = basic_types.T0OrT1(2, value); + end + + function z = zeros(varargin) + elem = basic_types.T0OrT1(0, yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function res = isT0(self) + res = self.index == 1; + end + + function res = isT1(self) + res = self.index == 2; + end + + function eq = eq(self, other) + eq = isa(other, "basic_types.T0OrT1") && isequal(self.index, other.index) && isequal(self.value, other.value); + end + + function ne = ne(self, other) + ne = ~self.eq(other); + end + + function t = tag(self) + tags_ = ["T0", "T1"]; + t = tags_(self.index_); + end + end +end diff --git a/matlab/generated/+basic_types/TextFormat.m b/matlab/generated/+basic_types/TextFormat.m new file mode 100644 index 00000000..526bad3d --- /dev/null +++ b/matlab/generated/+basic_types/TextFormat.m @@ -0,0 +1,62 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TextFormat < uint64 + methods (Static) + function v = REGULAR + v = basic_types.TextFormat(0); + end + function v = BOLD + v = basic_types.TextFormat(1); + end + function v = ITALIC + v = basic_types.TextFormat(2); + end + function v = UNDERLINE + v = basic_types.TextFormat(4); + end + function v = STRIKETHROUGH + v = basic_types.TextFormat(8); + end + + function z = zeros(varargin) + elem = basic_types.TextFormat(0); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function self = TextFormat(varargin) + if nargin == 0 + value = 0; + elseif nargin == 1 + value = varargin{1}; + else + value = 0; + for i = 1:nargin + value = bitor(value, varargin{i}); + end + end + self@uint64(value); + end + + function res = has_flags(self, flag) + res = bitand(self, flag) == flag; + end + + function res = with_flags(self, flag) + res = basic_types.TextFormat(bitor(self, flag)); + end + + function res = without_flags(self, flag) + res = basic_types.TextFormat(bitand(self, bitcmp(flag))); + end + end +end diff --git a/matlab/generated/+basic_types/TimeOrDatetime.m b/matlab/generated/+basic_types/TimeOrDatetime.m new file mode 100644 index 00000000..d5d4ae72 --- /dev/null +++ b/matlab/generated/+basic_types/TimeOrDatetime.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TimeOrDatetime < yardl.Union + methods (Static) + function res = Time(value) + res = basic_types.TimeOrDatetime(1, value); + end + + function res = Datetime(value) + res = basic_types.TimeOrDatetime(2, value); + end + + function z = zeros(varargin) + elem = basic_types.TimeOrDatetime(0, yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function res = isTime(self) + res = self.index == 1; + end + + function res = isDatetime(self) + res = self.index == 2; + end + + function eq = eq(self, other) + eq = isa(other, "basic_types.TimeOrDatetime") && isequal(self.index, other.index) && isequal(self.value, other.value); + end + + function ne = ne(self, other) + ne = ~self.eq(other); + end + + function t = tag(self) + tags_ = ["Time", "Datetime"]; + t = tags_(self.index_); + end + end +end diff --git a/matlab/generated/+image/FloatImage.m b/matlab/generated/+image/FloatImage.m new file mode 100644 index 00000000..cf3837f1 --- /dev/null +++ b/matlab/generated/+image/FloatImage.m @@ -0,0 +1,8 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function a = FloatImage(array) + arguments + array single + end + a = array; +end diff --git a/matlab/generated/+image/Image.m b/matlab/generated/+image/Image.m new file mode 100644 index 00000000..0332777d --- /dev/null +++ b/matlab/generated/+image/Image.m @@ -0,0 +1,5 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function a = Image(array) + a = array; +end diff --git a/matlab/generated/+image/IntImage.m b/matlab/generated/+image/IntImage.m new file mode 100644 index 00000000..a229033a --- /dev/null +++ b/matlab/generated/+image/IntImage.m @@ -0,0 +1,8 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function a = IntImage(array) + arguments + array int32 + end + a = array; +end diff --git a/matlab/generated/+sandbox/+binary/HelloWorldReader.m b/matlab/generated/+sandbox/+binary/HelloWorldReader.m new file mode 100644 index 00000000..cdae14d9 --- /dev/null +++ b/matlab/generated/+sandbox/+binary/HelloWorldReader.m @@ -0,0 +1,26 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef HelloWorldReader < yardl.binary.BinaryProtocolReader & sandbox.HelloWorldReaderBase + % Binary reader for the HelloWorld protocol + properties (Access=protected) + data_serializer + end + + methods + function self = HelloWorldReader(filename) + self@sandbox.HelloWorldReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, sandbox.HelloWorldReaderBase.schema); + self.data_serializer = yardl.binary.StreamSerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Complexfloat64Serializer, [2])); + end + end + + methods (Access=protected) + function more = has_data_(self) + more = self.data_serializer.hasnext(self.stream_); + end + + function value = read_data_(self) + value = self.data_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+sandbox/+binary/HelloWorldWriter.m b/matlab/generated/+sandbox/+binary/HelloWorldWriter.m new file mode 100644 index 00000000..d613db98 --- /dev/null +++ b/matlab/generated/+sandbox/+binary/HelloWorldWriter.m @@ -0,0 +1,22 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef HelloWorldWriter < yardl.binary.BinaryProtocolWriter & sandbox.HelloWorldWriterBase + % Binary writer for the HelloWorld protocol + properties (Access=protected) + data_serializer + end + + methods + function self = HelloWorldWriter(filename) + self@sandbox.HelloWorldWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, sandbox.HelloWorldWriterBase.schema); + self.data_serializer = yardl.binary.StreamSerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Complexfloat64Serializer, [2])); + end + end + + methods (Access=protected) + function write_data_(self, value) + self.data_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+sandbox/HelloWorldReaderBase.m b/matlab/generated/+sandbox/HelloWorldReaderBase.m new file mode 100644 index 00000000..112df588 --- /dev/null +++ b/matlab/generated/+sandbox/HelloWorldReaderBase.m @@ -0,0 +1,78 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef HelloWorldReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = HelloWorldReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 1 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function more = has_data(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + more = self.has_data_(); + if ~more + self.state_ = 1; + end + end + + function value = read_data(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_data_(); + end + + function copy_to(self, writer) + while self.has_data() + item = self.read_data(); + writer.write_data({item}); + end + writer.end_data(); + end + end + + methods (Static) + function res = schema() + res = sandbox.HelloWorldWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + has_data_(self) + read_data_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_data"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+sandbox/HelloWorldWriterBase.m b/matlab/generated/+sandbox/HelloWorldWriterBase.m new file mode 100644 index 00000000..eba0473b --- /dev/null +++ b/matlab/generated/+sandbox/HelloWorldWriterBase.m @@ -0,0 +1,69 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol HelloWorld +classdef (Abstract) HelloWorldWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = HelloWorldWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 1 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_data(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_data_(value); + end + + function end_data(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.end_stream_(); + self.state_ = 1; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"HelloWorld","sequence":[{"name":"data","type":{"stream":{"items":{"array":{"items":"complexfloat64","dimensions":[{"length":2}]}}}}}]},"types":null}'); + end + end + + methods (Abstract, Access=protected) + write_data_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_data or end_data"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/+binary/AdvancedGenericsReader.m b/matlab/generated/+test_model/+binary/AdvancedGenericsReader.m new file mode 100644 index 00000000..ecc960ca --- /dev/null +++ b/matlab/generated/+test_model/+binary/AdvancedGenericsReader.m @@ -0,0 +1,46 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef AdvancedGenericsReader < yardl.binary.BinaryProtocolReader & test_model.AdvancedGenericsReaderBase + % Binary reader for the AdvancedGenerics protocol + properties (Access=protected) + float_image_image_serializer + generic_record_1_serializer + tuple_of_optionals_serializer + tuple_of_optionals_alternate_syntax_serializer + tuple_of_vectors_serializer + end + + methods + function self = AdvancedGenericsReader(filename) + self@test_model.AdvancedGenericsReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.AdvancedGenericsReaderBase.schema); + self.float_image_image_serializer = yardl.binary.NDArraySerializer(yardl.binary.NDArraySerializer(yardl.binary.Float32Serializer, 2), 2); + self.generic_record_1_serializer = test_model.binary.GenericRecordSerializer(yardl.binary.Int32Serializer, yardl.binary.StringSerializer); + self.tuple_of_optionals_serializer = tuples.binary.TupleSerializer(yardl.binary.OptionalSerializer(yardl.binary.Int32Serializer), yardl.binary.OptionalSerializer(yardl.binary.StringSerializer)); + self.tuple_of_optionals_alternate_syntax_serializer = tuples.binary.TupleSerializer(yardl.binary.OptionalSerializer(yardl.binary.Int32Serializer), yardl.binary.OptionalSerializer(yardl.binary.StringSerializer)); + self.tuple_of_vectors_serializer = tuples.binary.TupleSerializer(yardl.binary.VectorSerializer(yardl.binary.Int32Serializer), yardl.binary.VectorSerializer(yardl.binary.Float32Serializer)); + end + end + + methods (Access=protected) + function value = read_float_image_image_(self) + value = self.float_image_image_serializer.read(self.stream_); + end + + function value = read_generic_record_1_(self) + value = self.generic_record_1_serializer.read(self.stream_); + end + + function value = read_tuple_of_optionals_(self) + value = self.tuple_of_optionals_serializer.read(self.stream_); + end + + function value = read_tuple_of_optionals_alternate_syntax_(self) + value = self.tuple_of_optionals_alternate_syntax_serializer.read(self.stream_); + end + + function value = read_tuple_of_vectors_(self) + value = self.tuple_of_vectors_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/AdvancedGenericsWriter.m b/matlab/generated/+test_model/+binary/AdvancedGenericsWriter.m new file mode 100644 index 00000000..13d882ab --- /dev/null +++ b/matlab/generated/+test_model/+binary/AdvancedGenericsWriter.m @@ -0,0 +1,46 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef AdvancedGenericsWriter < yardl.binary.BinaryProtocolWriter & test_model.AdvancedGenericsWriterBase + % Binary writer for the AdvancedGenerics protocol + properties (Access=protected) + float_image_image_serializer + generic_record_1_serializer + tuple_of_optionals_serializer + tuple_of_optionals_alternate_syntax_serializer + tuple_of_vectors_serializer + end + + methods + function self = AdvancedGenericsWriter(filename) + self@test_model.AdvancedGenericsWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.AdvancedGenericsWriterBase.schema); + self.float_image_image_serializer = yardl.binary.NDArraySerializer(yardl.binary.NDArraySerializer(yardl.binary.Float32Serializer, 2), 2); + self.generic_record_1_serializer = test_model.binary.GenericRecordSerializer(yardl.binary.Int32Serializer, yardl.binary.StringSerializer); + self.tuple_of_optionals_serializer = tuples.binary.TupleSerializer(yardl.binary.OptionalSerializer(yardl.binary.Int32Serializer), yardl.binary.OptionalSerializer(yardl.binary.StringSerializer)); + self.tuple_of_optionals_alternate_syntax_serializer = tuples.binary.TupleSerializer(yardl.binary.OptionalSerializer(yardl.binary.Int32Serializer), yardl.binary.OptionalSerializer(yardl.binary.StringSerializer)); + self.tuple_of_vectors_serializer = tuples.binary.TupleSerializer(yardl.binary.VectorSerializer(yardl.binary.Int32Serializer), yardl.binary.VectorSerializer(yardl.binary.Float32Serializer)); + end + end + + methods (Access=protected) + function write_float_image_image_(self, value) + self.float_image_image_serializer.write(self.stream_, value); + end + + function write_generic_record_1_(self, value) + self.generic_record_1_serializer.write(self.stream_, value); + end + + function write_tuple_of_optionals_(self, value) + self.tuple_of_optionals_serializer.write(self.stream_, value); + end + + function write_tuple_of_optionals_alternate_syntax_(self, value) + self.tuple_of_optionals_alternate_syntax_serializer.write(self.stream_, value); + end + + function write_tuple_of_vectors_(self, value) + self.tuple_of_vectors_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/AliasesReader.m b/matlab/generated/+test_model/+binary/AliasesReader.m new file mode 100644 index 00000000..2edb8961 --- /dev/null +++ b/matlab/generated/+test_model/+binary/AliasesReader.m @@ -0,0 +1,80 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef AliasesReader < yardl.binary.BinaryProtocolReader & test_model.AliasesReaderBase + % Binary reader for the Aliases protocol + properties (Access=protected) + aliased_string_serializer + aliased_enum_serializer + aliased_open_generic_serializer + aliased_closed_generic_serializer + aliased_optional_serializer + aliased_generic_optional_serializer + aliased_generic_union_2_serializer + aliased_generic_vector_serializer + aliased_generic_fixed_vector_serializer + stream_of_aliased_generic_union_2_serializer + end + + methods + function self = AliasesReader(filename) + self@test_model.AliasesReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.AliasesReaderBase.schema); + self.aliased_string_serializer = yardl.binary.StringSerializer; + self.aliased_enum_serializer = yardl.binary.EnumSerializer('basic_types.Fruits', @basic_types.Fruits, yardl.binary.Int32Serializer); + self.aliased_open_generic_serializer = tuples.binary.TupleSerializer(yardl.binary.StringSerializer, yardl.binary.EnumSerializer('basic_types.Fruits', @basic_types.Fruits, yardl.binary.Int32Serializer)); + self.aliased_closed_generic_serializer = tuples.binary.TupleSerializer(yardl.binary.StringSerializer, yardl.binary.EnumSerializer('basic_types.Fruits', @basic_types.Fruits, yardl.binary.Int32Serializer)); + self.aliased_optional_serializer = yardl.binary.OptionalSerializer(yardl.binary.Int32Serializer); + self.aliased_generic_optional_serializer = yardl.binary.OptionalSerializer(yardl.binary.Float32Serializer); + self.aliased_generic_union_2_serializer = yardl.binary.UnionSerializer('basic_types.GenericUnion2', {yardl.binary.StringSerializer, yardl.binary.EnumSerializer('basic_types.Fruits', @basic_types.Fruits, yardl.binary.Int32Serializer)}, {@basic_types.GenericUnion2.T1, @basic_types.GenericUnion2.T2}); + self.aliased_generic_vector_serializer = yardl.binary.VectorSerializer(yardl.binary.Float32Serializer); + self.aliased_generic_fixed_vector_serializer = yardl.binary.FixedVectorSerializer(yardl.binary.Float32Serializer, 3); + self.stream_of_aliased_generic_union_2_serializer = yardl.binary.StreamSerializer(yardl.binary.UnionSerializer('basic_types.GenericUnion2', {yardl.binary.StringSerializer, yardl.binary.EnumSerializer('basic_types.Fruits', @basic_types.Fruits, yardl.binary.Int32Serializer)}, {@basic_types.GenericUnion2.T1, @basic_types.GenericUnion2.T2})); + end + end + + methods (Access=protected) + function value = read_aliased_string_(self) + value = self.aliased_string_serializer.read(self.stream_); + end + + function value = read_aliased_enum_(self) + value = self.aliased_enum_serializer.read(self.stream_); + end + + function value = read_aliased_open_generic_(self) + value = self.aliased_open_generic_serializer.read(self.stream_); + end + + function value = read_aliased_closed_generic_(self) + value = self.aliased_closed_generic_serializer.read(self.stream_); + end + + function value = read_aliased_optional_(self) + value = self.aliased_optional_serializer.read(self.stream_); + end + + function value = read_aliased_generic_optional_(self) + value = self.aliased_generic_optional_serializer.read(self.stream_); + end + + function value = read_aliased_generic_union_2_(self) + value = self.aliased_generic_union_2_serializer.read(self.stream_); + end + + function value = read_aliased_generic_vector_(self) + value = self.aliased_generic_vector_serializer.read(self.stream_); + end + + function value = read_aliased_generic_fixed_vector_(self) + value = self.aliased_generic_fixed_vector_serializer.read(self.stream_); + end + + function more = has_stream_of_aliased_generic_union_2_(self) + more = self.stream_of_aliased_generic_union_2_serializer.hasnext(self.stream_); + end + + function value = read_stream_of_aliased_generic_union_2_(self) + value = self.stream_of_aliased_generic_union_2_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/AliasesWriter.m b/matlab/generated/+test_model/+binary/AliasesWriter.m new file mode 100644 index 00000000..543dd046 --- /dev/null +++ b/matlab/generated/+test_model/+binary/AliasesWriter.m @@ -0,0 +1,76 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef AliasesWriter < yardl.binary.BinaryProtocolWriter & test_model.AliasesWriterBase + % Binary writer for the Aliases protocol + properties (Access=protected) + aliased_string_serializer + aliased_enum_serializer + aliased_open_generic_serializer + aliased_closed_generic_serializer + aliased_optional_serializer + aliased_generic_optional_serializer + aliased_generic_union_2_serializer + aliased_generic_vector_serializer + aliased_generic_fixed_vector_serializer + stream_of_aliased_generic_union_2_serializer + end + + methods + function self = AliasesWriter(filename) + self@test_model.AliasesWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.AliasesWriterBase.schema); + self.aliased_string_serializer = yardl.binary.StringSerializer; + self.aliased_enum_serializer = yardl.binary.EnumSerializer('basic_types.Fruits', @basic_types.Fruits, yardl.binary.Int32Serializer); + self.aliased_open_generic_serializer = tuples.binary.TupleSerializer(yardl.binary.StringSerializer, yardl.binary.EnumSerializer('basic_types.Fruits', @basic_types.Fruits, yardl.binary.Int32Serializer)); + self.aliased_closed_generic_serializer = tuples.binary.TupleSerializer(yardl.binary.StringSerializer, yardl.binary.EnumSerializer('basic_types.Fruits', @basic_types.Fruits, yardl.binary.Int32Serializer)); + self.aliased_optional_serializer = yardl.binary.OptionalSerializer(yardl.binary.Int32Serializer); + self.aliased_generic_optional_serializer = yardl.binary.OptionalSerializer(yardl.binary.Float32Serializer); + self.aliased_generic_union_2_serializer = yardl.binary.UnionSerializer('basic_types.GenericUnion2', {yardl.binary.StringSerializer, yardl.binary.EnumSerializer('basic_types.Fruits', @basic_types.Fruits, yardl.binary.Int32Serializer)}, {@basic_types.GenericUnion2.T1, @basic_types.GenericUnion2.T2}); + self.aliased_generic_vector_serializer = yardl.binary.VectorSerializer(yardl.binary.Float32Serializer); + self.aliased_generic_fixed_vector_serializer = yardl.binary.FixedVectorSerializer(yardl.binary.Float32Serializer, 3); + self.stream_of_aliased_generic_union_2_serializer = yardl.binary.StreamSerializer(yardl.binary.UnionSerializer('basic_types.GenericUnion2', {yardl.binary.StringSerializer, yardl.binary.EnumSerializer('basic_types.Fruits', @basic_types.Fruits, yardl.binary.Int32Serializer)}, {@basic_types.GenericUnion2.T1, @basic_types.GenericUnion2.T2})); + end + end + + methods (Access=protected) + function write_aliased_string_(self, value) + self.aliased_string_serializer.write(self.stream_, value); + end + + function write_aliased_enum_(self, value) + self.aliased_enum_serializer.write(self.stream_, value); + end + + function write_aliased_open_generic_(self, value) + self.aliased_open_generic_serializer.write(self.stream_, value); + end + + function write_aliased_closed_generic_(self, value) + self.aliased_closed_generic_serializer.write(self.stream_, value); + end + + function write_aliased_optional_(self, value) + self.aliased_optional_serializer.write(self.stream_, value); + end + + function write_aliased_generic_optional_(self, value) + self.aliased_generic_optional_serializer.write(self.stream_, value); + end + + function write_aliased_generic_union_2_(self, value) + self.aliased_generic_union_2_serializer.write(self.stream_, value); + end + + function write_aliased_generic_vector_(self, value) + self.aliased_generic_vector_serializer.write(self.stream_, value); + end + + function write_aliased_generic_fixed_vector_(self, value) + self.aliased_generic_fixed_vector_serializer.write(self.stream_, value); + end + + function write_stream_of_aliased_generic_union_2_(self, value) + self.stream_of_aliased_generic_union_2_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/BenchmarkFloat256x256Reader.m b/matlab/generated/+test_model/+binary/BenchmarkFloat256x256Reader.m new file mode 100644 index 00000000..ca6e86eb --- /dev/null +++ b/matlab/generated/+test_model/+binary/BenchmarkFloat256x256Reader.m @@ -0,0 +1,26 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef BenchmarkFloat256x256Reader < yardl.binary.BinaryProtocolReader & test_model.BenchmarkFloat256x256ReaderBase + % Binary reader for the BenchmarkFloat256x256 protocol + properties (Access=protected) + float256x256_serializer + end + + methods + function self = BenchmarkFloat256x256Reader(filename) + self@test_model.BenchmarkFloat256x256ReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.BenchmarkFloat256x256ReaderBase.schema); + self.float256x256_serializer = yardl.binary.StreamSerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Float32Serializer, [256, 256])); + end + end + + methods (Access=protected) + function more = has_float256x256_(self) + more = self.float256x256_serializer.hasnext(self.stream_); + end + + function value = read_float256x256_(self) + value = self.float256x256_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/BenchmarkFloat256x256Writer.m b/matlab/generated/+test_model/+binary/BenchmarkFloat256x256Writer.m new file mode 100644 index 00000000..df30b7d2 --- /dev/null +++ b/matlab/generated/+test_model/+binary/BenchmarkFloat256x256Writer.m @@ -0,0 +1,22 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef BenchmarkFloat256x256Writer < yardl.binary.BinaryProtocolWriter & test_model.BenchmarkFloat256x256WriterBase + % Binary writer for the BenchmarkFloat256x256 protocol + properties (Access=protected) + float256x256_serializer + end + + methods + function self = BenchmarkFloat256x256Writer(filename) + self@test_model.BenchmarkFloat256x256WriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.BenchmarkFloat256x256WriterBase.schema); + self.float256x256_serializer = yardl.binary.StreamSerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Float32Serializer, [256, 256])); + end + end + + methods (Access=protected) + function write_float256x256_(self, value) + self.float256x256_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/BenchmarkFloatVlenReader.m b/matlab/generated/+test_model/+binary/BenchmarkFloatVlenReader.m new file mode 100644 index 00000000..2dad1ad5 --- /dev/null +++ b/matlab/generated/+test_model/+binary/BenchmarkFloatVlenReader.m @@ -0,0 +1,26 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef BenchmarkFloatVlenReader < yardl.binary.BinaryProtocolReader & test_model.BenchmarkFloatVlenReaderBase + % Binary reader for the BenchmarkFloatVlen protocol + properties (Access=protected) + float_array_serializer + end + + methods + function self = BenchmarkFloatVlenReader(filename) + self@test_model.BenchmarkFloatVlenReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.BenchmarkFloatVlenReaderBase.schema); + self.float_array_serializer = yardl.binary.StreamSerializer(yardl.binary.NDArraySerializer(yardl.binary.Float32Serializer, 2)); + end + end + + methods (Access=protected) + function more = has_float_array_(self) + more = self.float_array_serializer.hasnext(self.stream_); + end + + function value = read_float_array_(self) + value = self.float_array_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/BenchmarkFloatVlenWriter.m b/matlab/generated/+test_model/+binary/BenchmarkFloatVlenWriter.m new file mode 100644 index 00000000..2c924fb5 --- /dev/null +++ b/matlab/generated/+test_model/+binary/BenchmarkFloatVlenWriter.m @@ -0,0 +1,22 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef BenchmarkFloatVlenWriter < yardl.binary.BinaryProtocolWriter & test_model.BenchmarkFloatVlenWriterBase + % Binary writer for the BenchmarkFloatVlen protocol + properties (Access=protected) + float_array_serializer + end + + methods + function self = BenchmarkFloatVlenWriter(filename) + self@test_model.BenchmarkFloatVlenWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.BenchmarkFloatVlenWriterBase.schema); + self.float_array_serializer = yardl.binary.StreamSerializer(yardl.binary.NDArraySerializer(yardl.binary.Float32Serializer, 2)); + end + end + + methods (Access=protected) + function write_float_array_(self, value) + self.float_array_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/BenchmarkInt256x256Reader.m b/matlab/generated/+test_model/+binary/BenchmarkInt256x256Reader.m new file mode 100644 index 00000000..37b47ebb --- /dev/null +++ b/matlab/generated/+test_model/+binary/BenchmarkInt256x256Reader.m @@ -0,0 +1,26 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef BenchmarkInt256x256Reader < yardl.binary.BinaryProtocolReader & test_model.BenchmarkInt256x256ReaderBase + % Binary reader for the BenchmarkInt256x256 protocol + properties (Access=protected) + int256x256_serializer + end + + methods + function self = BenchmarkInt256x256Reader(filename) + self@test_model.BenchmarkInt256x256ReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.BenchmarkInt256x256ReaderBase.schema); + self.int256x256_serializer = yardl.binary.StreamSerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [256, 256])); + end + end + + methods (Access=protected) + function more = has_int256x256_(self) + more = self.int256x256_serializer.hasnext(self.stream_); + end + + function value = read_int256x256_(self) + value = self.int256x256_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/BenchmarkInt256x256Writer.m b/matlab/generated/+test_model/+binary/BenchmarkInt256x256Writer.m new file mode 100644 index 00000000..1d32f216 --- /dev/null +++ b/matlab/generated/+test_model/+binary/BenchmarkInt256x256Writer.m @@ -0,0 +1,22 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef BenchmarkInt256x256Writer < yardl.binary.BinaryProtocolWriter & test_model.BenchmarkInt256x256WriterBase + % Binary writer for the BenchmarkInt256x256 protocol + properties (Access=protected) + int256x256_serializer + end + + methods + function self = BenchmarkInt256x256Writer(filename) + self@test_model.BenchmarkInt256x256WriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.BenchmarkInt256x256WriterBase.schema); + self.int256x256_serializer = yardl.binary.StreamSerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [256, 256])); + end + end + + methods (Access=protected) + function write_int256x256_(self, value) + self.int256x256_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/BenchmarkSimpleMrdReader.m b/matlab/generated/+test_model/+binary/BenchmarkSimpleMrdReader.m new file mode 100644 index 00000000..51d36e82 --- /dev/null +++ b/matlab/generated/+test_model/+binary/BenchmarkSimpleMrdReader.m @@ -0,0 +1,26 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef BenchmarkSimpleMrdReader < yardl.binary.BinaryProtocolReader & test_model.BenchmarkSimpleMrdReaderBase + % Binary reader for the BenchmarkSimpleMrd protocol + properties (Access=protected) + data_serializer + end + + methods + function self = BenchmarkSimpleMrdReader(filename) + self@test_model.BenchmarkSimpleMrdReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.BenchmarkSimpleMrdReaderBase.schema); + self.data_serializer = yardl.binary.StreamSerializer(yardl.binary.UnionSerializer('test_model.AcquisitionOrImage', {test_model.binary.SimpleAcquisitionSerializer(), yardl.binary.NDArraySerializer(yardl.binary.Float32Serializer, 2)}, {@test_model.AcquisitionOrImage.Acquisition, @test_model.AcquisitionOrImage.Image})); + end + end + + methods (Access=protected) + function more = has_data_(self) + more = self.data_serializer.hasnext(self.stream_); + end + + function value = read_data_(self) + value = self.data_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/BenchmarkSimpleMrdWriter.m b/matlab/generated/+test_model/+binary/BenchmarkSimpleMrdWriter.m new file mode 100644 index 00000000..04bafb53 --- /dev/null +++ b/matlab/generated/+test_model/+binary/BenchmarkSimpleMrdWriter.m @@ -0,0 +1,22 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef BenchmarkSimpleMrdWriter < yardl.binary.BinaryProtocolWriter & test_model.BenchmarkSimpleMrdWriterBase + % Binary writer for the BenchmarkSimpleMrd protocol + properties (Access=protected) + data_serializer + end + + methods + function self = BenchmarkSimpleMrdWriter(filename) + self@test_model.BenchmarkSimpleMrdWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.BenchmarkSimpleMrdWriterBase.schema); + self.data_serializer = yardl.binary.StreamSerializer(yardl.binary.UnionSerializer('test_model.AcquisitionOrImage', {test_model.binary.SimpleAcquisitionSerializer(), yardl.binary.NDArraySerializer(yardl.binary.Float32Serializer, 2)}, {@test_model.AcquisitionOrImage.Acquisition, @test_model.AcquisitionOrImage.Image})); + end + end + + methods (Access=protected) + function write_data_(self, value) + self.data_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/BenchmarkSmallRecordReader.m b/matlab/generated/+test_model/+binary/BenchmarkSmallRecordReader.m new file mode 100644 index 00000000..64114ba3 --- /dev/null +++ b/matlab/generated/+test_model/+binary/BenchmarkSmallRecordReader.m @@ -0,0 +1,26 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef BenchmarkSmallRecordReader < yardl.binary.BinaryProtocolReader & test_model.BenchmarkSmallRecordReaderBase + % Binary reader for the BenchmarkSmallRecord protocol + properties (Access=protected) + small_record_serializer + end + + methods + function self = BenchmarkSmallRecordReader(filename) + self@test_model.BenchmarkSmallRecordReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.BenchmarkSmallRecordReaderBase.schema); + self.small_record_serializer = yardl.binary.StreamSerializer(test_model.binary.SmallBenchmarkRecordSerializer()); + end + end + + methods (Access=protected) + function more = has_small_record_(self) + more = self.small_record_serializer.hasnext(self.stream_); + end + + function value = read_small_record_(self) + value = self.small_record_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/BenchmarkSmallRecordWithOptionalsReader.m b/matlab/generated/+test_model/+binary/BenchmarkSmallRecordWithOptionalsReader.m new file mode 100644 index 00000000..cccf0c7d --- /dev/null +++ b/matlab/generated/+test_model/+binary/BenchmarkSmallRecordWithOptionalsReader.m @@ -0,0 +1,26 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef BenchmarkSmallRecordWithOptionalsReader < yardl.binary.BinaryProtocolReader & test_model.BenchmarkSmallRecordWithOptionalsReaderBase + % Binary reader for the BenchmarkSmallRecordWithOptionals protocol + properties (Access=protected) + small_record_serializer + end + + methods + function self = BenchmarkSmallRecordWithOptionalsReader(filename) + self@test_model.BenchmarkSmallRecordWithOptionalsReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.BenchmarkSmallRecordWithOptionalsReaderBase.schema); + self.small_record_serializer = yardl.binary.StreamSerializer(test_model.binary.SimpleEncodingCountersSerializer()); + end + end + + methods (Access=protected) + function more = has_small_record_(self) + more = self.small_record_serializer.hasnext(self.stream_); + end + + function value = read_small_record_(self) + value = self.small_record_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/BenchmarkSmallRecordWithOptionalsWriter.m b/matlab/generated/+test_model/+binary/BenchmarkSmallRecordWithOptionalsWriter.m new file mode 100644 index 00000000..f01d0dfd --- /dev/null +++ b/matlab/generated/+test_model/+binary/BenchmarkSmallRecordWithOptionalsWriter.m @@ -0,0 +1,22 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef BenchmarkSmallRecordWithOptionalsWriter < yardl.binary.BinaryProtocolWriter & test_model.BenchmarkSmallRecordWithOptionalsWriterBase + % Binary writer for the BenchmarkSmallRecordWithOptionals protocol + properties (Access=protected) + small_record_serializer + end + + methods + function self = BenchmarkSmallRecordWithOptionalsWriter(filename) + self@test_model.BenchmarkSmallRecordWithOptionalsWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.BenchmarkSmallRecordWithOptionalsWriterBase.schema); + self.small_record_serializer = yardl.binary.StreamSerializer(test_model.binary.SimpleEncodingCountersSerializer()); + end + end + + methods (Access=protected) + function write_small_record_(self, value) + self.small_record_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/BenchmarkSmallRecordWriter.m b/matlab/generated/+test_model/+binary/BenchmarkSmallRecordWriter.m new file mode 100644 index 00000000..f315e263 --- /dev/null +++ b/matlab/generated/+test_model/+binary/BenchmarkSmallRecordWriter.m @@ -0,0 +1,22 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef BenchmarkSmallRecordWriter < yardl.binary.BinaryProtocolWriter & test_model.BenchmarkSmallRecordWriterBase + % Binary writer for the BenchmarkSmallRecord protocol + properties (Access=protected) + small_record_serializer + end + + methods + function self = BenchmarkSmallRecordWriter(filename) + self@test_model.BenchmarkSmallRecordWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.BenchmarkSmallRecordWriterBase.schema); + self.small_record_serializer = yardl.binary.StreamSerializer(test_model.binary.SmallBenchmarkRecordSerializer()); + end + end + + methods (Access=protected) + function write_small_record_(self, value) + self.small_record_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/DynamicNDArraysReader.m b/matlab/generated/+test_model/+binary/DynamicNDArraysReader.m new file mode 100644 index 00000000..b3ce728c --- /dev/null +++ b/matlab/generated/+test_model/+binary/DynamicNDArraysReader.m @@ -0,0 +1,40 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef DynamicNDArraysReader < yardl.binary.BinaryProtocolReader & test_model.DynamicNDArraysReaderBase + % Binary reader for the DynamicNDArrays protocol + properties (Access=protected) + ints_serializer + simple_record_array_serializer + record_with_vlens_array_serializer + record_with_dynamic_nd_arrays_serializer + end + + methods + function self = DynamicNDArraysReader(filename) + self@test_model.DynamicNDArraysReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.DynamicNDArraysReaderBase.schema); + self.ints_serializer = yardl.binary.DynamicNDArraySerializer(yardl.binary.Int32Serializer); + self.simple_record_array_serializer = yardl.binary.DynamicNDArraySerializer(test_model.binary.SimpleRecordSerializer()); + self.record_with_vlens_array_serializer = yardl.binary.DynamicNDArraySerializer(test_model.binary.RecordWithVlensSerializer()); + self.record_with_dynamic_nd_arrays_serializer = test_model.binary.RecordWithDynamicNDArraysSerializer(); + end + end + + methods (Access=protected) + function value = read_ints_(self) + value = self.ints_serializer.read(self.stream_); + end + + function value = read_simple_record_array_(self) + value = self.simple_record_array_serializer.read(self.stream_); + end + + function value = read_record_with_vlens_array_(self) + value = self.record_with_vlens_array_serializer.read(self.stream_); + end + + function value = read_record_with_dynamic_nd_arrays_(self) + value = self.record_with_dynamic_nd_arrays_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/DynamicNDArraysWriter.m b/matlab/generated/+test_model/+binary/DynamicNDArraysWriter.m new file mode 100644 index 00000000..b50763f2 --- /dev/null +++ b/matlab/generated/+test_model/+binary/DynamicNDArraysWriter.m @@ -0,0 +1,40 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef DynamicNDArraysWriter < yardl.binary.BinaryProtocolWriter & test_model.DynamicNDArraysWriterBase + % Binary writer for the DynamicNDArrays protocol + properties (Access=protected) + ints_serializer + simple_record_array_serializer + record_with_vlens_array_serializer + record_with_dynamic_nd_arrays_serializer + end + + methods + function self = DynamicNDArraysWriter(filename) + self@test_model.DynamicNDArraysWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.DynamicNDArraysWriterBase.schema); + self.ints_serializer = yardl.binary.DynamicNDArraySerializer(yardl.binary.Int32Serializer); + self.simple_record_array_serializer = yardl.binary.DynamicNDArraySerializer(test_model.binary.SimpleRecordSerializer()); + self.record_with_vlens_array_serializer = yardl.binary.DynamicNDArraySerializer(test_model.binary.RecordWithVlensSerializer()); + self.record_with_dynamic_nd_arrays_serializer = test_model.binary.RecordWithDynamicNDArraysSerializer(); + end + end + + methods (Access=protected) + function write_ints_(self, value) + self.ints_serializer.write(self.stream_, value); + end + + function write_simple_record_array_(self, value) + self.simple_record_array_serializer.write(self.stream_, value); + end + + function write_record_with_vlens_array_(self, value) + self.record_with_vlens_array_serializer.write(self.stream_, value); + end + + function write_record_with_dynamic_nd_arrays_(self, value) + self.record_with_dynamic_nd_arrays_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/EnumsReader.m b/matlab/generated/+test_model/+binary/EnumsReader.m new file mode 100644 index 00000000..fd458581 --- /dev/null +++ b/matlab/generated/+test_model/+binary/EnumsReader.m @@ -0,0 +1,34 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef EnumsReader < yardl.binary.BinaryProtocolReader & test_model.EnumsReaderBase + % Binary reader for the Enums protocol + properties (Access=protected) + single_serializer + vec_serializer + size_serializer + end + + methods + function self = EnumsReader(filename) + self@test_model.EnumsReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.EnumsReaderBase.schema); + self.single_serializer = yardl.binary.EnumSerializer('basic_types.Fruits', @basic_types.Fruits, yardl.binary.Int32Serializer); + self.vec_serializer = yardl.binary.VectorSerializer(yardl.binary.EnumSerializer('basic_types.Fruits', @basic_types.Fruits, yardl.binary.Int32Serializer)); + self.size_serializer = yardl.binary.EnumSerializer('test_model.SizeBasedEnum', @test_model.SizeBasedEnum, yardl.binary.SizeSerializer); + end + end + + methods (Access=protected) + function value = read_single_(self) + value = self.single_serializer.read(self.stream_); + end + + function value = read_vec_(self) + value = self.vec_serializer.read(self.stream_); + end + + function value = read_size_(self) + value = self.size_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/EnumsWriter.m b/matlab/generated/+test_model/+binary/EnumsWriter.m new file mode 100644 index 00000000..1cd61c9f --- /dev/null +++ b/matlab/generated/+test_model/+binary/EnumsWriter.m @@ -0,0 +1,34 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef EnumsWriter < yardl.binary.BinaryProtocolWriter & test_model.EnumsWriterBase + % Binary writer for the Enums protocol + properties (Access=protected) + single_serializer + vec_serializer + size_serializer + end + + methods + function self = EnumsWriter(filename) + self@test_model.EnumsWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.EnumsWriterBase.schema); + self.single_serializer = yardl.binary.EnumSerializer('basic_types.Fruits', @basic_types.Fruits, yardl.binary.Int32Serializer); + self.vec_serializer = yardl.binary.VectorSerializer(yardl.binary.EnumSerializer('basic_types.Fruits', @basic_types.Fruits, yardl.binary.Int32Serializer)); + self.size_serializer = yardl.binary.EnumSerializer('test_model.SizeBasedEnum', @test_model.SizeBasedEnum, yardl.binary.SizeSerializer); + end + end + + methods (Access=protected) + function write_single_(self, value) + self.single_serializer.write(self.stream_, value); + end + + function write_vec_(self, value) + self.vec_serializer.write(self.stream_, value); + end + + function write_size_(self, value) + self.size_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/FixedArraysReader.m b/matlab/generated/+test_model/+binary/FixedArraysReader.m new file mode 100644 index 00000000..5e265d3c --- /dev/null +++ b/matlab/generated/+test_model/+binary/FixedArraysReader.m @@ -0,0 +1,46 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef FixedArraysReader < yardl.binary.BinaryProtocolReader & test_model.FixedArraysReaderBase + % Binary reader for the FixedArrays protocol + properties (Access=protected) + ints_serializer + fixed_simple_record_array_serializer + fixed_record_with_vlens_array_serializer + record_with_fixed_arrays_serializer + named_array_serializer + end + + methods + function self = FixedArraysReader(filename) + self@test_model.FixedArraysReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.FixedArraysReaderBase.schema); + self.ints_serializer = yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [3, 2]); + self.fixed_simple_record_array_serializer = yardl.binary.FixedNDArraySerializer(test_model.binary.SimpleRecordSerializer(), [2, 3]); + self.fixed_record_with_vlens_array_serializer = yardl.binary.FixedNDArraySerializer(test_model.binary.RecordWithVlensSerializer(), [2, 2]); + self.record_with_fixed_arrays_serializer = test_model.binary.RecordWithFixedArraysSerializer(); + self.named_array_serializer = yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [4, 2]); + end + end + + methods (Access=protected) + function value = read_ints_(self) + value = self.ints_serializer.read(self.stream_); + end + + function value = read_fixed_simple_record_array_(self) + value = self.fixed_simple_record_array_serializer.read(self.stream_); + end + + function value = read_fixed_record_with_vlens_array_(self) + value = self.fixed_record_with_vlens_array_serializer.read(self.stream_); + end + + function value = read_record_with_fixed_arrays_(self) + value = self.record_with_fixed_arrays_serializer.read(self.stream_); + end + + function value = read_named_array_(self) + value = self.named_array_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/FixedArraysWriter.m b/matlab/generated/+test_model/+binary/FixedArraysWriter.m new file mode 100644 index 00000000..65831e55 --- /dev/null +++ b/matlab/generated/+test_model/+binary/FixedArraysWriter.m @@ -0,0 +1,46 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef FixedArraysWriter < yardl.binary.BinaryProtocolWriter & test_model.FixedArraysWriterBase + % Binary writer for the FixedArrays protocol + properties (Access=protected) + ints_serializer + fixed_simple_record_array_serializer + fixed_record_with_vlens_array_serializer + record_with_fixed_arrays_serializer + named_array_serializer + end + + methods + function self = FixedArraysWriter(filename) + self@test_model.FixedArraysWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.FixedArraysWriterBase.schema); + self.ints_serializer = yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [3, 2]); + self.fixed_simple_record_array_serializer = yardl.binary.FixedNDArraySerializer(test_model.binary.SimpleRecordSerializer(), [2, 3]); + self.fixed_record_with_vlens_array_serializer = yardl.binary.FixedNDArraySerializer(test_model.binary.RecordWithVlensSerializer(), [2, 2]); + self.record_with_fixed_arrays_serializer = test_model.binary.RecordWithFixedArraysSerializer(); + self.named_array_serializer = yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [4, 2]); + end + end + + methods (Access=protected) + function write_ints_(self, value) + self.ints_serializer.write(self.stream_, value); + end + + function write_fixed_simple_record_array_(self, value) + self.fixed_simple_record_array_serializer.write(self.stream_, value); + end + + function write_fixed_record_with_vlens_array_(self, value) + self.fixed_record_with_vlens_array_serializer.write(self.stream_, value); + end + + function write_record_with_fixed_arrays_(self, value) + self.record_with_fixed_arrays_serializer.write(self.stream_, value); + end + + function write_named_array_(self, value) + self.named_array_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/FixedVectorsReader.m b/matlab/generated/+test_model/+binary/FixedVectorsReader.m new file mode 100644 index 00000000..8584d603 --- /dev/null +++ b/matlab/generated/+test_model/+binary/FixedVectorsReader.m @@ -0,0 +1,40 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef FixedVectorsReader < yardl.binary.BinaryProtocolReader & test_model.FixedVectorsReaderBase + % Binary reader for the FixedVectors protocol + properties (Access=protected) + fixed_int_vector_serializer + fixed_simple_record_vector_serializer + fixed_record_with_vlens_vector_serializer + record_with_fixed_vectors_serializer + end + + methods + function self = FixedVectorsReader(filename) + self@test_model.FixedVectorsReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.FixedVectorsReaderBase.schema); + self.fixed_int_vector_serializer = yardl.binary.FixedVectorSerializer(yardl.binary.Int32Serializer, 5); + self.fixed_simple_record_vector_serializer = yardl.binary.FixedVectorSerializer(test_model.binary.SimpleRecordSerializer(), 3); + self.fixed_record_with_vlens_vector_serializer = yardl.binary.FixedVectorSerializer(test_model.binary.RecordWithVlensSerializer(), 2); + self.record_with_fixed_vectors_serializer = test_model.binary.RecordWithFixedVectorsSerializer(); + end + end + + methods (Access=protected) + function value = read_fixed_int_vector_(self) + value = self.fixed_int_vector_serializer.read(self.stream_); + end + + function value = read_fixed_simple_record_vector_(self) + value = self.fixed_simple_record_vector_serializer.read(self.stream_); + end + + function value = read_fixed_record_with_vlens_vector_(self) + value = self.fixed_record_with_vlens_vector_serializer.read(self.stream_); + end + + function value = read_record_with_fixed_vectors_(self) + value = self.record_with_fixed_vectors_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/FixedVectorsWriter.m b/matlab/generated/+test_model/+binary/FixedVectorsWriter.m new file mode 100644 index 00000000..bd569036 --- /dev/null +++ b/matlab/generated/+test_model/+binary/FixedVectorsWriter.m @@ -0,0 +1,40 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef FixedVectorsWriter < yardl.binary.BinaryProtocolWriter & test_model.FixedVectorsWriterBase + % Binary writer for the FixedVectors protocol + properties (Access=protected) + fixed_int_vector_serializer + fixed_simple_record_vector_serializer + fixed_record_with_vlens_vector_serializer + record_with_fixed_vectors_serializer + end + + methods + function self = FixedVectorsWriter(filename) + self@test_model.FixedVectorsWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.FixedVectorsWriterBase.schema); + self.fixed_int_vector_serializer = yardl.binary.FixedVectorSerializer(yardl.binary.Int32Serializer, 5); + self.fixed_simple_record_vector_serializer = yardl.binary.FixedVectorSerializer(test_model.binary.SimpleRecordSerializer(), 3); + self.fixed_record_with_vlens_vector_serializer = yardl.binary.FixedVectorSerializer(test_model.binary.RecordWithVlensSerializer(), 2); + self.record_with_fixed_vectors_serializer = test_model.binary.RecordWithFixedVectorsSerializer(); + end + end + + methods (Access=protected) + function write_fixed_int_vector_(self, value) + self.fixed_int_vector_serializer.write(self.stream_, value); + end + + function write_fixed_simple_record_vector_(self, value) + self.fixed_simple_record_vector_serializer.write(self.stream_, value); + end + + function write_fixed_record_with_vlens_vector_(self, value) + self.fixed_record_with_vlens_vector_serializer.write(self.stream_, value); + end + + function write_record_with_fixed_vectors_(self, value) + self.record_with_fixed_vectors_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/FlagsReader.m b/matlab/generated/+test_model/+binary/FlagsReader.m new file mode 100644 index 00000000..3afa6e20 --- /dev/null +++ b/matlab/generated/+test_model/+binary/FlagsReader.m @@ -0,0 +1,36 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef FlagsReader < yardl.binary.BinaryProtocolReader & test_model.FlagsReaderBase + % Binary reader for the Flags protocol + properties (Access=protected) + days_serializer + formats_serializer + end + + methods + function self = FlagsReader(filename) + self@test_model.FlagsReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.FlagsReaderBase.schema); + self.days_serializer = yardl.binary.StreamSerializer(yardl.binary.EnumSerializer('basic_types.DaysOfWeek', @basic_types.DaysOfWeek, yardl.binary.Int32Serializer)); + self.formats_serializer = yardl.binary.StreamSerializer(yardl.binary.EnumSerializer('basic_types.TextFormat', @basic_types.TextFormat, yardl.binary.Uint64Serializer)); + end + end + + methods (Access=protected) + function more = has_days_(self) + more = self.days_serializer.hasnext(self.stream_); + end + + function value = read_days_(self) + value = self.days_serializer.read(self.stream_); + end + + function more = has_formats_(self) + more = self.formats_serializer.hasnext(self.stream_); + end + + function value = read_formats_(self) + value = self.formats_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/FlagsWriter.m b/matlab/generated/+test_model/+binary/FlagsWriter.m new file mode 100644 index 00000000..887d0d3c --- /dev/null +++ b/matlab/generated/+test_model/+binary/FlagsWriter.m @@ -0,0 +1,28 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef FlagsWriter < yardl.binary.BinaryProtocolWriter & test_model.FlagsWriterBase + % Binary writer for the Flags protocol + properties (Access=protected) + days_serializer + formats_serializer + end + + methods + function self = FlagsWriter(filename) + self@test_model.FlagsWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.FlagsWriterBase.schema); + self.days_serializer = yardl.binary.StreamSerializer(yardl.binary.EnumSerializer('basic_types.DaysOfWeek', @basic_types.DaysOfWeek, yardl.binary.Int32Serializer)); + self.formats_serializer = yardl.binary.StreamSerializer(yardl.binary.EnumSerializer('basic_types.TextFormat', @basic_types.TextFormat, yardl.binary.Uint64Serializer)); + end + end + + methods (Access=protected) + function write_days_(self, value) + self.days_serializer.write(self.stream_, value); + end + + function write_formats_(self, value) + self.formats_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/GenericRecordSerializer.m b/matlab/generated/+test_model/+binary/GenericRecordSerializer.m new file mode 100644 index 00000000..b32ebc52 --- /dev/null +++ b/matlab/generated/+test_model/+binary/GenericRecordSerializer.m @@ -0,0 +1,27 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef GenericRecordSerializer < yardl.binary.RecordSerializer + methods + function self = GenericRecordSerializer(t1_serializer, t2_serializer) + field_serializers{1} = t1_serializer; + field_serializers{2} = t2_serializer; + field_serializers{3} = yardl.binary.VectorSerializer(t1_serializer); + field_serializers{4} = yardl.binary.NDArraySerializer(t2_serializer, 2); + self@yardl.binary.RecordSerializer('test_model.GenericRecord', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.GenericRecord + end + self.write_(outstream, value.scalar_1, value.scalar_2, value.vector_1, value.image_2); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.GenericRecord(scalar_1=fields{1}, scalar_2=fields{2}, vector_1=fields{3}, image_2=fields{4}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/MapsReader.m b/matlab/generated/+test_model/+binary/MapsReader.m new file mode 100644 index 00000000..b702f3db --- /dev/null +++ b/matlab/generated/+test_model/+binary/MapsReader.m @@ -0,0 +1,40 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MapsReader < yardl.binary.BinaryProtocolReader & test_model.MapsReaderBase + % Binary reader for the Maps protocol + properties (Access=protected) + string_to_int_serializer + int_to_string_serializer + string_to_union_serializer + aliased_generic_serializer + end + + methods + function self = MapsReader(filename) + self@test_model.MapsReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.MapsReaderBase.schema); + self.string_to_int_serializer = yardl.binary.MapSerializer(yardl.binary.StringSerializer, yardl.binary.Int32Serializer); + self.int_to_string_serializer = yardl.binary.MapSerializer(yardl.binary.Int32Serializer, yardl.binary.StringSerializer); + self.string_to_union_serializer = yardl.binary.MapSerializer(yardl.binary.StringSerializer, yardl.binary.UnionSerializer('test_model.StringOrInt32', {yardl.binary.StringSerializer, yardl.binary.Int32Serializer}, {@test_model.StringOrInt32.String, @test_model.StringOrInt32.Int32})); + self.aliased_generic_serializer = yardl.binary.MapSerializer(yardl.binary.StringSerializer, yardl.binary.Int32Serializer); + end + end + + methods (Access=protected) + function value = read_string_to_int_(self) + value = self.string_to_int_serializer.read(self.stream_); + end + + function value = read_int_to_string_(self) + value = self.int_to_string_serializer.read(self.stream_); + end + + function value = read_string_to_union_(self) + value = self.string_to_union_serializer.read(self.stream_); + end + + function value = read_aliased_generic_(self) + value = self.aliased_generic_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/MapsWriter.m b/matlab/generated/+test_model/+binary/MapsWriter.m new file mode 100644 index 00000000..eaff4c19 --- /dev/null +++ b/matlab/generated/+test_model/+binary/MapsWriter.m @@ -0,0 +1,40 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MapsWriter < yardl.binary.BinaryProtocolWriter & test_model.MapsWriterBase + % Binary writer for the Maps protocol + properties (Access=protected) + string_to_int_serializer + int_to_string_serializer + string_to_union_serializer + aliased_generic_serializer + end + + methods + function self = MapsWriter(filename) + self@test_model.MapsWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.MapsWriterBase.schema); + self.string_to_int_serializer = yardl.binary.MapSerializer(yardl.binary.StringSerializer, yardl.binary.Int32Serializer); + self.int_to_string_serializer = yardl.binary.MapSerializer(yardl.binary.Int32Serializer, yardl.binary.StringSerializer); + self.string_to_union_serializer = yardl.binary.MapSerializer(yardl.binary.StringSerializer, yardl.binary.UnionSerializer('test_model.StringOrInt32', {yardl.binary.StringSerializer, yardl.binary.Int32Serializer}, {@test_model.StringOrInt32.String, @test_model.StringOrInt32.Int32})); + self.aliased_generic_serializer = yardl.binary.MapSerializer(yardl.binary.StringSerializer, yardl.binary.Int32Serializer); + end + end + + methods (Access=protected) + function write_string_to_int_(self, value) + self.string_to_int_serializer.write(self.stream_, value); + end + + function write_int_to_string_(self, value) + self.int_to_string_serializer.write(self.stream_, value); + end + + function write_string_to_union_(self, value) + self.string_to_union_serializer.write(self.stream_, value); + end + + function write_aliased_generic_(self, value) + self.aliased_generic_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/MultiDArraysReader.m b/matlab/generated/+test_model/+binary/MultiDArraysReader.m new file mode 100644 index 00000000..0bbb3409 --- /dev/null +++ b/matlab/generated/+test_model/+binary/MultiDArraysReader.m @@ -0,0 +1,36 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MultiDArraysReader < yardl.binary.BinaryProtocolReader & test_model.MultiDArraysReaderBase + % Binary reader for the MultiDArrays protocol + properties (Access=protected) + images_serializer + frames_serializer + end + + methods + function self = MultiDArraysReader(filename) + self@test_model.MultiDArraysReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.MultiDArraysReaderBase.schema); + self.images_serializer = yardl.binary.StreamSerializer(yardl.binary.NDArraySerializer(yardl.binary.Float32Serializer, 4)); + self.frames_serializer = yardl.binary.StreamSerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Float32Serializer, [32, 64, 1, 1])); + end + end + + methods (Access=protected) + function more = has_images_(self) + more = self.images_serializer.hasnext(self.stream_); + end + + function value = read_images_(self) + value = self.images_serializer.read(self.stream_); + end + + function more = has_frames_(self) + more = self.frames_serializer.hasnext(self.stream_); + end + + function value = read_frames_(self) + value = self.frames_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/MultiDArraysWriter.m b/matlab/generated/+test_model/+binary/MultiDArraysWriter.m new file mode 100644 index 00000000..40fd424e --- /dev/null +++ b/matlab/generated/+test_model/+binary/MultiDArraysWriter.m @@ -0,0 +1,28 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MultiDArraysWriter < yardl.binary.BinaryProtocolWriter & test_model.MultiDArraysWriterBase + % Binary writer for the MultiDArrays protocol + properties (Access=protected) + images_serializer + frames_serializer + end + + methods + function self = MultiDArraysWriter(filename) + self@test_model.MultiDArraysWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.MultiDArraysWriterBase.schema); + self.images_serializer = yardl.binary.StreamSerializer(yardl.binary.NDArraySerializer(yardl.binary.Float32Serializer, 4)); + self.frames_serializer = yardl.binary.StreamSerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Float32Serializer, [32, 64, 1, 1])); + end + end + + methods (Access=protected) + function write_images_(self, value) + self.images_serializer.write(self.stream_, value); + end + + function write_frames_(self, value) + self.frames_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/NDArraysReader.m b/matlab/generated/+test_model/+binary/NDArraysReader.m new file mode 100644 index 00000000..8314be45 --- /dev/null +++ b/matlab/generated/+test_model/+binary/NDArraysReader.m @@ -0,0 +1,46 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef NDArraysReader < yardl.binary.BinaryProtocolReader & test_model.NDArraysReaderBase + % Binary reader for the NDArrays protocol + properties (Access=protected) + ints_serializer + simple_record_array_serializer + record_with_vlens_array_serializer + record_with_nd_arrays_serializer + named_array_serializer + end + + methods + function self = NDArraysReader(filename) + self@test_model.NDArraysReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.NDArraysReaderBase.schema); + self.ints_serializer = yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2); + self.simple_record_array_serializer = yardl.binary.NDArraySerializer(test_model.binary.SimpleRecordSerializer(), 2); + self.record_with_vlens_array_serializer = yardl.binary.NDArraySerializer(test_model.binary.RecordWithVlensSerializer(), 2); + self.record_with_nd_arrays_serializer = test_model.binary.RecordWithNDArraysSerializer(); + self.named_array_serializer = yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2); + end + end + + methods (Access=protected) + function value = read_ints_(self) + value = self.ints_serializer.read(self.stream_); + end + + function value = read_simple_record_array_(self) + value = self.simple_record_array_serializer.read(self.stream_); + end + + function value = read_record_with_vlens_array_(self) + value = self.record_with_vlens_array_serializer.read(self.stream_); + end + + function value = read_record_with_nd_arrays_(self) + value = self.record_with_nd_arrays_serializer.read(self.stream_); + end + + function value = read_named_array_(self) + value = self.named_array_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/NDArraysSingleDimensionReader.m b/matlab/generated/+test_model/+binary/NDArraysSingleDimensionReader.m new file mode 100644 index 00000000..6073b3c5 --- /dev/null +++ b/matlab/generated/+test_model/+binary/NDArraysSingleDimensionReader.m @@ -0,0 +1,40 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef NDArraysSingleDimensionReader < yardl.binary.BinaryProtocolReader & test_model.NDArraysSingleDimensionReaderBase + % Binary reader for the NDArraysSingleDimension protocol + properties (Access=protected) + ints_serializer + simple_record_array_serializer + record_with_vlens_array_serializer + record_with_nd_arrays_serializer + end + + methods + function self = NDArraysSingleDimensionReader(filename) + self@test_model.NDArraysSingleDimensionReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.NDArraysSingleDimensionReaderBase.schema); + self.ints_serializer = yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 1); + self.simple_record_array_serializer = yardl.binary.NDArraySerializer(test_model.binary.SimpleRecordSerializer(), 1); + self.record_with_vlens_array_serializer = yardl.binary.NDArraySerializer(test_model.binary.RecordWithVlensSerializer(), 1); + self.record_with_nd_arrays_serializer = test_model.binary.RecordWithNDArraysSingleDimensionSerializer(); + end + end + + methods (Access=protected) + function value = read_ints_(self) + value = self.ints_serializer.read(self.stream_); + end + + function value = read_simple_record_array_(self) + value = self.simple_record_array_serializer.read(self.stream_); + end + + function value = read_record_with_vlens_array_(self) + value = self.record_with_vlens_array_serializer.read(self.stream_); + end + + function value = read_record_with_nd_arrays_(self) + value = self.record_with_nd_arrays_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/NDArraysSingleDimensionWriter.m b/matlab/generated/+test_model/+binary/NDArraysSingleDimensionWriter.m new file mode 100644 index 00000000..092ff0a5 --- /dev/null +++ b/matlab/generated/+test_model/+binary/NDArraysSingleDimensionWriter.m @@ -0,0 +1,40 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef NDArraysSingleDimensionWriter < yardl.binary.BinaryProtocolWriter & test_model.NDArraysSingleDimensionWriterBase + % Binary writer for the NDArraysSingleDimension protocol + properties (Access=protected) + ints_serializer + simple_record_array_serializer + record_with_vlens_array_serializer + record_with_nd_arrays_serializer + end + + methods + function self = NDArraysSingleDimensionWriter(filename) + self@test_model.NDArraysSingleDimensionWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.NDArraysSingleDimensionWriterBase.schema); + self.ints_serializer = yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 1); + self.simple_record_array_serializer = yardl.binary.NDArraySerializer(test_model.binary.SimpleRecordSerializer(), 1); + self.record_with_vlens_array_serializer = yardl.binary.NDArraySerializer(test_model.binary.RecordWithVlensSerializer(), 1); + self.record_with_nd_arrays_serializer = test_model.binary.RecordWithNDArraysSingleDimensionSerializer(); + end + end + + methods (Access=protected) + function write_ints_(self, value) + self.ints_serializer.write(self.stream_, value); + end + + function write_simple_record_array_(self, value) + self.simple_record_array_serializer.write(self.stream_, value); + end + + function write_record_with_vlens_array_(self, value) + self.record_with_vlens_array_serializer.write(self.stream_, value); + end + + function write_record_with_nd_arrays_(self, value) + self.record_with_nd_arrays_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/NDArraysWriter.m b/matlab/generated/+test_model/+binary/NDArraysWriter.m new file mode 100644 index 00000000..fa2014ea --- /dev/null +++ b/matlab/generated/+test_model/+binary/NDArraysWriter.m @@ -0,0 +1,46 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef NDArraysWriter < yardl.binary.BinaryProtocolWriter & test_model.NDArraysWriterBase + % Binary writer for the NDArrays protocol + properties (Access=protected) + ints_serializer + simple_record_array_serializer + record_with_vlens_array_serializer + record_with_nd_arrays_serializer + named_array_serializer + end + + methods + function self = NDArraysWriter(filename) + self@test_model.NDArraysWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.NDArraysWriterBase.schema); + self.ints_serializer = yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2); + self.simple_record_array_serializer = yardl.binary.NDArraySerializer(test_model.binary.SimpleRecordSerializer(), 2); + self.record_with_vlens_array_serializer = yardl.binary.NDArraySerializer(test_model.binary.RecordWithVlensSerializer(), 2); + self.record_with_nd_arrays_serializer = test_model.binary.RecordWithNDArraysSerializer(); + self.named_array_serializer = yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2); + end + end + + methods (Access=protected) + function write_ints_(self, value) + self.ints_serializer.write(self.stream_, value); + end + + function write_simple_record_array_(self, value) + self.simple_record_array_serializer.write(self.stream_, value); + end + + function write_record_with_vlens_array_(self, value) + self.record_with_vlens_array_serializer.write(self.stream_, value); + end + + function write_record_with_nd_arrays_(self, value) + self.record_with_nd_arrays_serializer.write(self.stream_, value); + end + + function write_named_array_(self, value) + self.named_array_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/NestedRecordsReader.m b/matlab/generated/+test_model/+binary/NestedRecordsReader.m new file mode 100644 index 00000000..6663bc64 --- /dev/null +++ b/matlab/generated/+test_model/+binary/NestedRecordsReader.m @@ -0,0 +1,22 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef NestedRecordsReader < yardl.binary.BinaryProtocolReader & test_model.NestedRecordsReaderBase + % Binary reader for the NestedRecords protocol + properties (Access=protected) + tuple_with_records_serializer + end + + methods + function self = NestedRecordsReader(filename) + self@test_model.NestedRecordsReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.NestedRecordsReaderBase.schema); + self.tuple_with_records_serializer = test_model.binary.TupleWithRecordsSerializer(); + end + end + + methods (Access=protected) + function value = read_tuple_with_records_(self) + value = self.tuple_with_records_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/NestedRecordsWriter.m b/matlab/generated/+test_model/+binary/NestedRecordsWriter.m new file mode 100644 index 00000000..f40653db --- /dev/null +++ b/matlab/generated/+test_model/+binary/NestedRecordsWriter.m @@ -0,0 +1,22 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef NestedRecordsWriter < yardl.binary.BinaryProtocolWriter & test_model.NestedRecordsWriterBase + % Binary writer for the NestedRecords protocol + properties (Access=protected) + tuple_with_records_serializer + end + + methods + function self = NestedRecordsWriter(filename) + self@test_model.NestedRecordsWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.NestedRecordsWriterBase.schema); + self.tuple_with_records_serializer = test_model.binary.TupleWithRecordsSerializer(); + end + end + + methods (Access=protected) + function write_tuple_with_records_(self, value) + self.tuple_with_records_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/OptionalVectorsReader.m b/matlab/generated/+test_model/+binary/OptionalVectorsReader.m new file mode 100644 index 00000000..463e4196 --- /dev/null +++ b/matlab/generated/+test_model/+binary/OptionalVectorsReader.m @@ -0,0 +1,22 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef OptionalVectorsReader < yardl.binary.BinaryProtocolReader & test_model.OptionalVectorsReaderBase + % Binary reader for the OptionalVectors protocol + properties (Access=protected) + record_with_optional_vector_serializer + end + + methods + function self = OptionalVectorsReader(filename) + self@test_model.OptionalVectorsReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.OptionalVectorsReaderBase.schema); + self.record_with_optional_vector_serializer = test_model.binary.RecordWithOptionalVectorSerializer(); + end + end + + methods (Access=protected) + function value = read_record_with_optional_vector_(self) + value = self.record_with_optional_vector_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/OptionalVectorsWriter.m b/matlab/generated/+test_model/+binary/OptionalVectorsWriter.m new file mode 100644 index 00000000..a30085b0 --- /dev/null +++ b/matlab/generated/+test_model/+binary/OptionalVectorsWriter.m @@ -0,0 +1,22 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef OptionalVectorsWriter < yardl.binary.BinaryProtocolWriter & test_model.OptionalVectorsWriterBase + % Binary writer for the OptionalVectors protocol + properties (Access=protected) + record_with_optional_vector_serializer + end + + methods + function self = OptionalVectorsWriter(filename) + self@test_model.OptionalVectorsWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.OptionalVectorsWriterBase.schema); + self.record_with_optional_vector_serializer = test_model.binary.RecordWithOptionalVectorSerializer(); + end + end + + methods (Access=protected) + function write_record_with_optional_vector_(self, value) + self.record_with_optional_vector_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/ProtocolWithComputedFieldsReader.m b/matlab/generated/+test_model/+binary/ProtocolWithComputedFieldsReader.m new file mode 100644 index 00000000..f79b4299 --- /dev/null +++ b/matlab/generated/+test_model/+binary/ProtocolWithComputedFieldsReader.m @@ -0,0 +1,22 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef ProtocolWithComputedFieldsReader < yardl.binary.BinaryProtocolReader & test_model.ProtocolWithComputedFieldsReaderBase + % Binary reader for the ProtocolWithComputedFields protocol + properties (Access=protected) + record_with_computed_fields_serializer + end + + methods + function self = ProtocolWithComputedFieldsReader(filename) + self@test_model.ProtocolWithComputedFieldsReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.ProtocolWithComputedFieldsReaderBase.schema); + self.record_with_computed_fields_serializer = test_model.binary.RecordWithComputedFieldsSerializer(); + end + end + + methods (Access=protected) + function value = read_record_with_computed_fields_(self) + value = self.record_with_computed_fields_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/ProtocolWithComputedFieldsWriter.m b/matlab/generated/+test_model/+binary/ProtocolWithComputedFieldsWriter.m new file mode 100644 index 00000000..494a6d78 --- /dev/null +++ b/matlab/generated/+test_model/+binary/ProtocolWithComputedFieldsWriter.m @@ -0,0 +1,22 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef ProtocolWithComputedFieldsWriter < yardl.binary.BinaryProtocolWriter & test_model.ProtocolWithComputedFieldsWriterBase + % Binary writer for the ProtocolWithComputedFields protocol + properties (Access=protected) + record_with_computed_fields_serializer + end + + methods + function self = ProtocolWithComputedFieldsWriter(filename) + self@test_model.ProtocolWithComputedFieldsWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.ProtocolWithComputedFieldsWriterBase.schema); + self.record_with_computed_fields_serializer = test_model.binary.RecordWithComputedFieldsSerializer(); + end + end + + methods (Access=protected) + function write_record_with_computed_fields_(self, value) + self.record_with_computed_fields_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/ProtocolWithKeywordStepsReader.m b/matlab/generated/+test_model/+binary/ProtocolWithKeywordStepsReader.m new file mode 100644 index 00000000..b6fc429e --- /dev/null +++ b/matlab/generated/+test_model/+binary/ProtocolWithKeywordStepsReader.m @@ -0,0 +1,32 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef ProtocolWithKeywordStepsReader < yardl.binary.BinaryProtocolReader & test_model.ProtocolWithKeywordStepsReaderBase + % Binary reader for the ProtocolWithKeywordSteps protocol + properties (Access=protected) + int_serializer + float_serializer + end + + methods + function self = ProtocolWithKeywordStepsReader(filename) + self@test_model.ProtocolWithKeywordStepsReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.ProtocolWithKeywordStepsReaderBase.schema); + self.int_serializer = yardl.binary.StreamSerializer(test_model.binary.RecordWithKeywordFieldsSerializer()); + self.float_serializer = yardl.binary.EnumSerializer('test_model.EnumWithKeywordSymbols', @test_model.EnumWithKeywordSymbols, yardl.binary.Int32Serializer); + end + end + + methods (Access=protected) + function more = has_int_(self) + more = self.int_serializer.hasnext(self.stream_); + end + + function value = read_int_(self) + value = self.int_serializer.read(self.stream_); + end + + function value = read_float_(self) + value = self.float_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/ProtocolWithKeywordStepsWriter.m b/matlab/generated/+test_model/+binary/ProtocolWithKeywordStepsWriter.m new file mode 100644 index 00000000..706de0bf --- /dev/null +++ b/matlab/generated/+test_model/+binary/ProtocolWithKeywordStepsWriter.m @@ -0,0 +1,28 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef ProtocolWithKeywordStepsWriter < yardl.binary.BinaryProtocolWriter & test_model.ProtocolWithKeywordStepsWriterBase + % Binary writer for the ProtocolWithKeywordSteps protocol + properties (Access=protected) + int_serializer + float_serializer + end + + methods + function self = ProtocolWithKeywordStepsWriter(filename) + self@test_model.ProtocolWithKeywordStepsWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.ProtocolWithKeywordStepsWriterBase.schema); + self.int_serializer = yardl.binary.StreamSerializer(test_model.binary.RecordWithKeywordFieldsSerializer()); + self.float_serializer = yardl.binary.EnumSerializer('test_model.EnumWithKeywordSymbols', @test_model.EnumWithKeywordSymbols, yardl.binary.Int32Serializer); + end + end + + methods (Access=protected) + function write_int_(self, value) + self.int_serializer.write(self.stream_, value); + end + + function write_float_(self, value) + self.float_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordContainingGenericRecordsSerializer.m b/matlab/generated/+test_model/+binary/RecordContainingGenericRecordsSerializer.m new file mode 100644 index 00000000..7410338e --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordContainingGenericRecordsSerializer.m @@ -0,0 +1,33 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordContainingGenericRecordsSerializer < yardl.binary.RecordSerializer + methods + function self = RecordContainingGenericRecordsSerializer(a_serializer, b_serializer) + field_serializers{1} = test_model.binary.RecordWithOptionalGenericFieldSerializer(a_serializer); + field_serializers{2} = test_model.binary.RecordWithAliasedOptionalGenericFieldSerializer(a_serializer); + field_serializers{3} = test_model.binary.RecordWithOptionalGenericUnionFieldSerializer(a_serializer, b_serializer); + field_serializers{4} = test_model.binary.RecordWithAliasedOptionalGenericUnionFieldSerializer(a_serializer, b_serializer); + field_serializers{5} = tuples.binary.TupleSerializer(a_serializer, b_serializer); + field_serializers{6} = tuples.binary.TupleSerializer(a_serializer, b_serializer); + field_serializers{7} = test_model.binary.RecordWithGenericVectorsSerializer(b_serializer); + field_serializers{8} = test_model.binary.RecordWithGenericFixedVectorsSerializer(b_serializer); + field_serializers{9} = test_model.binary.RecordWithGenericArraysSerializer(b_serializer); + field_serializers{10} = test_model.binary.RecordWithGenericMapsSerializer(a_serializer, b_serializer); + self@yardl.binary.RecordSerializer('test_model.RecordContainingGenericRecords', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordContainingGenericRecords + end + self.write_(outstream, value.g1, value.g1a, value.g2, value.g2a, value.g3, value.g3a, value.g4, value.g5, value.g6, value.g7); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordContainingGenericRecords(g1=fields{1}, g1a=fields{2}, g2=fields{3}, g2a=fields{4}, g3=fields{5}, g3a=fields{6}, g4=fields{7}, g5=fields{8}, g6=fields{9}, g7=fields{10}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordContainingNestedGenericRecordsSerializer.m b/matlab/generated/+test_model/+binary/RecordContainingNestedGenericRecordsSerializer.m new file mode 100644 index 00000000..802ead64 --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordContainingNestedGenericRecordsSerializer.m @@ -0,0 +1,28 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordContainingNestedGenericRecordsSerializer < yardl.binary.RecordSerializer + methods + function self = RecordContainingNestedGenericRecordsSerializer() + field_serializers{1} = test_model.binary.RecordWithOptionalGenericFieldSerializer(yardl.binary.StringSerializer); + field_serializers{2} = test_model.binary.RecordWithAliasedOptionalGenericFieldSerializer(yardl.binary.StringSerializer); + field_serializers{3} = test_model.binary.RecordWithOptionalGenericUnionFieldSerializer(yardl.binary.StringSerializer, yardl.binary.Int32Serializer); + field_serializers{4} = test_model.binary.RecordWithAliasedOptionalGenericUnionFieldSerializer(yardl.binary.StringSerializer, yardl.binary.Int32Serializer); + field_serializers{5} = test_model.binary.RecordContainingGenericRecordsSerializer(yardl.binary.StringSerializer, yardl.binary.Int32Serializer); + self@yardl.binary.RecordSerializer('test_model.RecordContainingNestedGenericRecords', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordContainingNestedGenericRecords + end + self.write_(outstream, value.f1, value.f1a, value.f2, value.f2a, value.nested); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordContainingNestedGenericRecords(f1=fields{1}, f1a=fields{2}, f2=fields{3}, f2a=fields{4}, nested=fields{5}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordNotUsedInProtocolSerializer.m b/matlab/generated/+test_model/+binary/RecordNotUsedInProtocolSerializer.m new file mode 100644 index 00000000..90725dfb --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordNotUsedInProtocolSerializer.m @@ -0,0 +1,25 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordNotUsedInProtocolSerializer < yardl.binary.RecordSerializer + methods + function self = RecordNotUsedInProtocolSerializer() + field_serializers{1} = yardl.binary.UnionSerializer('test_model.GenericUnion3', {yardl.binary.Int32Serializer, yardl.binary.Float32Serializer, yardl.binary.StringSerializer}, {@test_model.GenericUnion3.T, @test_model.GenericUnion3.U, @test_model.GenericUnion3.V}); + field_serializers{2} = yardl.binary.UnionSerializer('test_model.GenericUnion3Alternate', {yardl.binary.Int32Serializer, yardl.binary.Float32Serializer, yardl.binary.StringSerializer}, {@test_model.GenericUnion3Alternate.U, @test_model.GenericUnion3Alternate.V, @test_model.GenericUnion3Alternate.W}); + self@yardl.binary.RecordSerializer('test_model.RecordNotUsedInProtocol', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordNotUsedInProtocol + end + self.write_(outstream, value.u1, value.u2); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordNotUsedInProtocol(u1=fields{1}, u2=fields{2}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithAliasedGenericsSerializer.m b/matlab/generated/+test_model/+binary/RecordWithAliasedGenericsSerializer.m new file mode 100644 index 00000000..ad2e284c --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithAliasedGenericsSerializer.m @@ -0,0 +1,25 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithAliasedGenericsSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithAliasedGenericsSerializer() + field_serializers{1} = tuples.binary.TupleSerializer(yardl.binary.StringSerializer, yardl.binary.StringSerializer); + field_serializers{2} = tuples.binary.TupleSerializer(yardl.binary.StringSerializer, yardl.binary.StringSerializer); + self@yardl.binary.RecordSerializer('test_model.RecordWithAliasedGenerics', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithAliasedGenerics + end + self.write_(outstream, value.my_strings, value.aliased_strings); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithAliasedGenerics(my_strings=fields{1}, aliased_strings=fields{2}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithAliasedOptionalGenericFieldSerializer.m b/matlab/generated/+test_model/+binary/RecordWithAliasedOptionalGenericFieldSerializer.m new file mode 100644 index 00000000..89cf2b76 --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithAliasedOptionalGenericFieldSerializer.m @@ -0,0 +1,24 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithAliasedOptionalGenericFieldSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithAliasedOptionalGenericFieldSerializer(t_serializer) + field_serializers{1} = yardl.binary.OptionalSerializer(t_serializer); + self@yardl.binary.RecordSerializer('test_model.RecordWithAliasedOptionalGenericField', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithAliasedOptionalGenericField + end + self.write_(outstream, value.v); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithAliasedOptionalGenericField(v=fields{1}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithAliasedOptionalGenericUnionFieldSerializer.m b/matlab/generated/+test_model/+binary/RecordWithAliasedOptionalGenericUnionFieldSerializer.m new file mode 100644 index 00000000..612151e3 --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithAliasedOptionalGenericUnionFieldSerializer.m @@ -0,0 +1,24 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithAliasedOptionalGenericUnionFieldSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithAliasedOptionalGenericUnionFieldSerializer(u_serializer, v_serializer) + field_serializers{1} = yardl.binary.UnionSerializer('test_model.AliasedMultiGenericOptional', {yardl.binary.NoneSerializer, u_serializer, v_serializer}, {yardl.None, @test_model.AliasedMultiGenericOptional.T, @test_model.AliasedMultiGenericOptional.U}); + self@yardl.binary.RecordSerializer('test_model.RecordWithAliasedOptionalGenericUnionField', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithAliasedOptionalGenericUnionField + end + self.write_(outstream, value.v); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithAliasedOptionalGenericUnionField(v=fields{1}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithArraysSerializer.m b/matlab/generated/+test_model/+binary/RecordWithArraysSerializer.m new file mode 100644 index 00000000..e67bcc5f --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithArraysSerializer.m @@ -0,0 +1,32 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithArraysSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithArraysSerializer() + field_serializers{1} = yardl.binary.DynamicNDArraySerializer(yardl.binary.Int32Serializer); + field_serializers{2} = yardl.binary.DynamicNDArraySerializer(yardl.binary.Int32Serializer); + field_serializers{3} = yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 1); + field_serializers{4} = yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2); + field_serializers{5} = yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2); + field_serializers{6} = yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [4, 3]); + field_serializers{7} = yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [4, 3]); + field_serializers{8} = yardl.binary.DynamicNDArraySerializer(yardl.binary.Int32Serializer); + field_serializers{9} = yardl.binary.FixedNDArraySerializer(yardl.binary.FixedVectorSerializer(yardl.binary.Int32Serializer, 4), [5]); + self@yardl.binary.RecordSerializer('test_model.RecordWithArrays', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithArrays + end + self.write_(outstream, value.default_array, value.default_array_with_empty_dimension, value.rank_1_array, value.rank_2_array, value.rank_2_array_with_named_dimensions, value.rank_2_fixed_array, value.rank_2_fixed_array_with_named_dimensions, value.dynamic_array, value.array_of_vectors); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithArrays(default_array=fields{1}, default_array_with_empty_dimension=fields{2}, rank_1_array=fields{3}, rank_2_array=fields{4}, rank_2_array_with_named_dimensions=fields{5}, rank_2_fixed_array=fields{6}, rank_2_fixed_array_with_named_dimensions=fields{7}, dynamic_array=fields{8}, array_of_vectors=fields{9}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithArraysSimpleSyntaxSerializer.m b/matlab/generated/+test_model/+binary/RecordWithArraysSimpleSyntaxSerializer.m new file mode 100644 index 00000000..153c9fdc --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithArraysSimpleSyntaxSerializer.m @@ -0,0 +1,32 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithArraysSimpleSyntaxSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithArraysSimpleSyntaxSerializer() + field_serializers{1} = yardl.binary.DynamicNDArraySerializer(yardl.binary.Int32Serializer); + field_serializers{2} = yardl.binary.DynamicNDArraySerializer(yardl.binary.Int32Serializer); + field_serializers{3} = yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 1); + field_serializers{4} = yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2); + field_serializers{5} = yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2); + field_serializers{6} = yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [4, 3]); + field_serializers{7} = yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [4, 3]); + field_serializers{8} = yardl.binary.DynamicNDArraySerializer(yardl.binary.Int32Serializer); + field_serializers{9} = yardl.binary.FixedNDArraySerializer(yardl.binary.FixedVectorSerializer(yardl.binary.Int32Serializer, 4), [5]); + self@yardl.binary.RecordSerializer('test_model.RecordWithArraysSimpleSyntax', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithArraysSimpleSyntax + end + self.write_(outstream, value.default_array, value.default_array_with_empty_dimension, value.rank_1_array, value.rank_2_array, value.rank_2_array_with_named_dimensions, value.rank_2_fixed_array, value.rank_2_fixed_array_with_named_dimensions, value.dynamic_array, value.array_of_vectors); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithArraysSimpleSyntax(default_array=fields{1}, default_array_with_empty_dimension=fields{2}, rank_1_array=fields{3}, rank_2_array=fields{4}, rank_2_array_with_named_dimensions=fields{5}, rank_2_fixed_array=fields{6}, rank_2_fixed_array_with_named_dimensions=fields{7}, dynamic_array=fields{8}, array_of_vectors=fields{9}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithComputedFieldsSerializer.m b/matlab/generated/+test_model/+binary/RecordWithComputedFieldsSerializer.m new file mode 100644 index 00000000..7c9f1ee5 --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithComputedFieldsSerializer.m @@ -0,0 +1,51 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithComputedFieldsSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithComputedFieldsSerializer() + field_serializers{1} = yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2); + field_serializers{2} = yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2); + field_serializers{3} = yardl.binary.DynamicNDArraySerializer(yardl.binary.Int32Serializer); + field_serializers{4} = yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [4, 3]); + field_serializers{5} = yardl.binary.Int32Serializer; + field_serializers{6} = yardl.binary.Int8Serializer; + field_serializers{7} = yardl.binary.Uint8Serializer; + field_serializers{8} = yardl.binary.Int16Serializer; + field_serializers{9} = yardl.binary.Uint16Serializer; + field_serializers{10} = yardl.binary.Uint32Serializer; + field_serializers{11} = yardl.binary.Int64Serializer; + field_serializers{12} = yardl.binary.Uint64Serializer; + field_serializers{13} = yardl.binary.SizeSerializer; + field_serializers{14} = yardl.binary.Float32Serializer; + field_serializers{15} = yardl.binary.Float64Serializer; + field_serializers{16} = yardl.binary.Complexfloat32Serializer; + field_serializers{17} = yardl.binary.Complexfloat64Serializer; + field_serializers{18} = yardl.binary.StringSerializer; + field_serializers{19} = tuples.binary.TupleSerializer(yardl.binary.Int32Serializer, yardl.binary.Int32Serializer); + field_serializers{20} = yardl.binary.VectorSerializer(yardl.binary.Int32Serializer); + field_serializers{21} = yardl.binary.VectorSerializer(yardl.binary.VectorSerializer(yardl.binary.Int32Serializer)); + field_serializers{22} = yardl.binary.FixedVectorSerializer(yardl.binary.Int32Serializer, 3); + field_serializers{23} = yardl.binary.FixedVectorSerializer(yardl.binary.FixedVectorSerializer(yardl.binary.Int32Serializer, 3), 2); + field_serializers{24} = yardl.binary.OptionalSerializer(yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2)); + field_serializers{25} = yardl.binary.UnionSerializer('test_model.Int32OrFloat32', {yardl.binary.Int32Serializer, yardl.binary.Float32Serializer}, {@test_model.Int32OrFloat32.Int32, @test_model.Int32OrFloat32.Float32}); + field_serializers{26} = yardl.binary.UnionSerializer('test_model.Int32OrFloat32', {yardl.binary.NoneSerializer, yardl.binary.Int32Serializer, yardl.binary.Float32Serializer}, {yardl.None, @test_model.Int32OrFloat32.Int32, @test_model.Int32OrFloat32.Float32}); + field_serializers{27} = yardl.binary.UnionSerializer('test_model.IntOrGenericRecordWithComputedFields', {yardl.binary.Int32Serializer, basic_types.binary.GenericRecordWithComputedFieldsSerializer(yardl.binary.StringSerializer, yardl.binary.Float32Serializer)}, {@test_model.IntOrGenericRecordWithComputedFields.Int, @test_model.IntOrGenericRecordWithComputedFields.GenericRecordWithComputedFields}); + field_serializers{28} = yardl.binary.MapSerializer(yardl.binary.StringSerializer, yardl.binary.StringSerializer); + self@yardl.binary.RecordSerializer('test_model.RecordWithComputedFields', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithComputedFields + end + self.write_(outstream, value.array_field, value.array_field_map_dimensions, value.dynamic_array_field, value.fixed_array_field, value.int_field, value.int8_field, value.uint8_field, value.int16_field, value.uint16_field, value.uint32_field, value.int64_field, value.uint64_field, value.size_field, value.float32_field, value.float64_field, value.complexfloat32_field, value.complexfloat64_field, value.string_field, value.tuple_field, value.vector_field, value.vector_of_vectors_field, value.fixed_vector_field, value.fixed_vector_of_vectors_field, value.optional_named_array, value.int_float_union, value.nullable_int_float_union, value.union_with_nested_generic_union, value.map_field); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithComputedFields(array_field=fields{1}, array_field_map_dimensions=fields{2}, dynamic_array_field=fields{3}, fixed_array_field=fields{4}, int_field=fields{5}, int8_field=fields{6}, uint8_field=fields{7}, int16_field=fields{8}, uint16_field=fields{9}, uint32_field=fields{10}, int64_field=fields{11}, uint64_field=fields{12}, size_field=fields{13}, float32_field=fields{14}, float64_field=fields{15}, complexfloat32_field=fields{16}, complexfloat64_field=fields{17}, string_field=fields{18}, tuple_field=fields{19}, vector_field=fields{20}, vector_of_vectors_field=fields{21}, fixed_vector_field=fields{22}, fixed_vector_of_vectors_field=fields{23}, optional_named_array=fields{24}, int_float_union=fields{25}, nullable_int_float_union=fields{26}, union_with_nested_generic_union=fields{27}, map_field=fields{28}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithDynamicNDArraysSerializer.m b/matlab/generated/+test_model/+binary/RecordWithDynamicNDArraysSerializer.m new file mode 100644 index 00000000..3e61b833 --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithDynamicNDArraysSerializer.m @@ -0,0 +1,26 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithDynamicNDArraysSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithDynamicNDArraysSerializer() + field_serializers{1} = yardl.binary.DynamicNDArraySerializer(yardl.binary.Int32Serializer); + field_serializers{2} = yardl.binary.DynamicNDArraySerializer(test_model.binary.SimpleRecordSerializer()); + field_serializers{3} = yardl.binary.DynamicNDArraySerializer(test_model.binary.RecordWithVlensSerializer()); + self@yardl.binary.RecordSerializer('test_model.RecordWithDynamicNDArrays', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithDynamicNDArrays + end + self.write_(outstream, value.ints, value.simple_record_array, value.record_with_vlens_array); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithDynamicNDArrays(ints=fields{1}, simple_record_array=fields{2}, record_with_vlens_array=fields{3}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithEnumsSerializer.m b/matlab/generated/+test_model/+binary/RecordWithEnumsSerializer.m new file mode 100644 index 00000000..89696610 --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithEnumsSerializer.m @@ -0,0 +1,26 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithEnumsSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithEnumsSerializer() + field_serializers{1} = yardl.binary.EnumSerializer('basic_types.Fruits', @basic_types.Fruits, yardl.binary.Int32Serializer); + field_serializers{2} = yardl.binary.EnumSerializer('basic_types.DaysOfWeek', @basic_types.DaysOfWeek, yardl.binary.Int32Serializer); + field_serializers{3} = yardl.binary.EnumSerializer('basic_types.TextFormat', @basic_types.TextFormat, yardl.binary.Uint64Serializer); + self@yardl.binary.RecordSerializer('test_model.RecordWithEnums', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithEnums + end + self.write_(outstream, value.enum, value.flags, value.flags_2); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithEnums(enum=fields{1}, flags=fields{2}, flags_2=fields{3}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithFixedArraysSerializer.m b/matlab/generated/+test_model/+binary/RecordWithFixedArraysSerializer.m new file mode 100644 index 00000000..649c484d --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithFixedArraysSerializer.m @@ -0,0 +1,26 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithFixedArraysSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithFixedArraysSerializer() + field_serializers{1} = yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [3, 2]); + field_serializers{2} = yardl.binary.FixedNDArraySerializer(test_model.binary.SimpleRecordSerializer(), [2, 3]); + field_serializers{3} = yardl.binary.FixedNDArraySerializer(test_model.binary.RecordWithVlensSerializer(), [2, 2]); + self@yardl.binary.RecordSerializer('test_model.RecordWithFixedArrays', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithFixedArrays + end + self.write_(outstream, value.ints, value.fixed_simple_record_array, value.fixed_record_with_vlens_array); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithFixedArrays(ints=fields{1}, fixed_simple_record_array=fields{2}, fixed_record_with_vlens_array=fields{3}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithFixedCollectionsSerializer.m b/matlab/generated/+test_model/+binary/RecordWithFixedCollectionsSerializer.m new file mode 100644 index 00000000..e155bbb4 --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithFixedCollectionsSerializer.m @@ -0,0 +1,25 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithFixedCollectionsSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithFixedCollectionsSerializer() + field_serializers{1} = yardl.binary.FixedVectorSerializer(yardl.binary.Int32Serializer, 3); + field_serializers{2} = yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [3, 2]); + self@yardl.binary.RecordSerializer('test_model.RecordWithFixedCollections', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithFixedCollections + end + self.write_(outstream, value.fixed_vector, value.fixed_array); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithFixedCollections(fixed_vector=fields{1}, fixed_array=fields{2}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithFixedVectorsSerializer.m b/matlab/generated/+test_model/+binary/RecordWithFixedVectorsSerializer.m new file mode 100644 index 00000000..7a296ac5 --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithFixedVectorsSerializer.m @@ -0,0 +1,26 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithFixedVectorsSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithFixedVectorsSerializer() + field_serializers{1} = yardl.binary.FixedVectorSerializer(yardl.binary.Int32Serializer, 5); + field_serializers{2} = yardl.binary.FixedVectorSerializer(test_model.binary.SimpleRecordSerializer(), 3); + field_serializers{3} = yardl.binary.FixedVectorSerializer(test_model.binary.RecordWithVlensSerializer(), 2); + self@yardl.binary.RecordSerializer('test_model.RecordWithFixedVectors', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithFixedVectors + end + self.write_(outstream, value.fixed_int_vector, value.fixed_simple_record_vector, value.fixed_record_with_vlens_vector); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithFixedVectors(fixed_int_vector=fields{1}, fixed_simple_record_vector=fields{2}, fixed_record_with_vlens_vector=fields{3}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithGenericArraysSerializer.m b/matlab/generated/+test_model/+binary/RecordWithGenericArraysSerializer.m new file mode 100644 index 00000000..c82a2717 --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithGenericArraysSerializer.m @@ -0,0 +1,29 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithGenericArraysSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithGenericArraysSerializer(t_serializer) + field_serializers{1} = yardl.binary.NDArraySerializer(t_serializer, 2); + field_serializers{2} = yardl.binary.FixedNDArraySerializer(t_serializer, [8, 16]); + field_serializers{3} = yardl.binary.DynamicNDArraySerializer(t_serializer); + field_serializers{4} = yardl.binary.NDArraySerializer(t_serializer, 2); + field_serializers{5} = yardl.binary.FixedNDArraySerializer(t_serializer, [8, 16]); + field_serializers{6} = yardl.binary.DynamicNDArraySerializer(t_serializer); + self@yardl.binary.RecordSerializer('test_model.RecordWithGenericArrays', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithGenericArrays + end + self.write_(outstream, value.nd, value.fixed_nd, value.dynamic_nd, value.aliased_nd, value.aliased_fixed_nd, value.aliased_dynamic_nd); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithGenericArrays(nd=fields{1}, fixed_nd=fields{2}, dynamic_nd=fields{3}, aliased_nd=fields{4}, aliased_fixed_nd=fields{5}, aliased_dynamic_nd=fields{6}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithGenericFixedVectorsSerializer.m b/matlab/generated/+test_model/+binary/RecordWithGenericFixedVectorsSerializer.m new file mode 100644 index 00000000..0fc88fd0 --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithGenericFixedVectorsSerializer.m @@ -0,0 +1,25 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithGenericFixedVectorsSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithGenericFixedVectorsSerializer(t_serializer) + field_serializers{1} = yardl.binary.FixedVectorSerializer(t_serializer, 3); + field_serializers{2} = yardl.binary.FixedVectorSerializer(t_serializer, 3); + self@yardl.binary.RecordSerializer('test_model.RecordWithGenericFixedVectors', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithGenericFixedVectors + end + self.write_(outstream, value.fv, value.afv); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithGenericFixedVectors(fv=fields{1}, afv=fields{2}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithGenericMapsSerializer.m b/matlab/generated/+test_model/+binary/RecordWithGenericMapsSerializer.m new file mode 100644 index 00000000..14082704 --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithGenericMapsSerializer.m @@ -0,0 +1,25 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithGenericMapsSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithGenericMapsSerializer(t_serializer, u_serializer) + field_serializers{1} = yardl.binary.MapSerializer(t_serializer, u_serializer); + field_serializers{2} = yardl.binary.MapSerializer(t_serializer, u_serializer); + self@yardl.binary.RecordSerializer('test_model.RecordWithGenericMaps', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithGenericMaps + end + self.write_(outstream, value.m, value.am); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithGenericMaps(m=fields{1}, am=fields{2}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithGenericVectorOfRecordsSerializer.m b/matlab/generated/+test_model/+binary/RecordWithGenericVectorOfRecordsSerializer.m new file mode 100644 index 00000000..fbc1f344 --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithGenericVectorOfRecordsSerializer.m @@ -0,0 +1,24 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithGenericVectorOfRecordsSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithGenericVectorOfRecordsSerializer(t_serializer, u_serializer) + field_serializers{1} = yardl.binary.VectorSerializer(yardl.binary.VectorSerializer(test_model.binary.GenericRecordSerializer(t_serializer, u_serializer))); + self@yardl.binary.RecordSerializer('test_model.RecordWithGenericVectorOfRecords', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithGenericVectorOfRecords + end + self.write_(outstream, value.v); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithGenericVectorOfRecords(v=fields{1}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithGenericVectorsSerializer.m b/matlab/generated/+test_model/+binary/RecordWithGenericVectorsSerializer.m new file mode 100644 index 00000000..27713d9f --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithGenericVectorsSerializer.m @@ -0,0 +1,25 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithGenericVectorsSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithGenericVectorsSerializer(t_serializer) + field_serializers{1} = yardl.binary.VectorSerializer(t_serializer); + field_serializers{2} = yardl.binary.VectorSerializer(t_serializer); + self@yardl.binary.RecordSerializer('test_model.RecordWithGenericVectors', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithGenericVectors + end + self.write_(outstream, value.v, value.av); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithGenericVectors(v=fields{1}, av=fields{2}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithKeywordFieldsSerializer.m b/matlab/generated/+test_model/+binary/RecordWithKeywordFieldsSerializer.m new file mode 100644 index 00000000..fbd2fc2b --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithKeywordFieldsSerializer.m @@ -0,0 +1,26 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithKeywordFieldsSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithKeywordFieldsSerializer() + field_serializers{1} = yardl.binary.StringSerializer; + field_serializers{2} = yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2); + field_serializers{3} = yardl.binary.EnumSerializer('test_model.EnumWithKeywordSymbols', @test_model.EnumWithKeywordSymbols, yardl.binary.Int32Serializer); + self@yardl.binary.RecordSerializer('test_model.RecordWithKeywordFields', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithKeywordFields + end + self.write_(outstream, value.int, value.sizeof, value.if_); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithKeywordFields(int=fields{1}, sizeof=fields{2}, if_=fields{3}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithNDArraysSerializer.m b/matlab/generated/+test_model/+binary/RecordWithNDArraysSerializer.m new file mode 100644 index 00000000..ce768aad --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithNDArraysSerializer.m @@ -0,0 +1,26 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithNDArraysSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithNDArraysSerializer() + field_serializers{1} = yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2); + field_serializers{2} = yardl.binary.NDArraySerializer(test_model.binary.SimpleRecordSerializer(), 2); + field_serializers{3} = yardl.binary.NDArraySerializer(test_model.binary.RecordWithVlensSerializer(), 2); + self@yardl.binary.RecordSerializer('test_model.RecordWithNDArrays', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithNDArrays + end + self.write_(outstream, value.ints, value.fixed_simple_record_array, value.fixed_record_with_vlens_array); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithNDArrays(ints=fields{1}, fixed_simple_record_array=fields{2}, fixed_record_with_vlens_array=fields{3}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithNDArraysSingleDimensionSerializer.m b/matlab/generated/+test_model/+binary/RecordWithNDArraysSingleDimensionSerializer.m new file mode 100644 index 00000000..54e900af --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithNDArraysSingleDimensionSerializer.m @@ -0,0 +1,26 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithNDArraysSingleDimensionSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithNDArraysSingleDimensionSerializer() + field_serializers{1} = yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 1); + field_serializers{2} = yardl.binary.NDArraySerializer(test_model.binary.SimpleRecordSerializer(), 1); + field_serializers{3} = yardl.binary.NDArraySerializer(test_model.binary.RecordWithVlensSerializer(), 1); + self@yardl.binary.RecordSerializer('test_model.RecordWithNDArraysSingleDimension', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithNDArraysSingleDimension + end + self.write_(outstream, value.ints, value.fixed_simple_record_array, value.fixed_record_with_vlens_array); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithNDArraysSingleDimension(ints=fields{1}, fixed_simple_record_array=fields{2}, fixed_record_with_vlens_array=fields{3}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithNamedFixedArraysSerializer.m b/matlab/generated/+test_model/+binary/RecordWithNamedFixedArraysSerializer.m new file mode 100644 index 00000000..25ec629b --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithNamedFixedArraysSerializer.m @@ -0,0 +1,26 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithNamedFixedArraysSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithNamedFixedArraysSerializer() + field_serializers{1} = yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [3, 2]); + field_serializers{2} = yardl.binary.FixedNDArraySerializer(test_model.binary.SimpleRecordSerializer(), [2, 3]); + field_serializers{3} = yardl.binary.FixedNDArraySerializer(test_model.binary.RecordWithVlensSerializer(), [2, 2]); + self@yardl.binary.RecordSerializer('test_model.RecordWithNamedFixedArrays', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithNamedFixedArrays + end + self.write_(outstream, value.ints, value.fixed_simple_record_array, value.fixed_record_with_vlens_array); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithNamedFixedArrays(ints=fields{1}, fixed_simple_record_array=fields{2}, fixed_record_with_vlens_array=fields{3}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithOptionalFieldsSerializer.m b/matlab/generated/+test_model/+binary/RecordWithOptionalFieldsSerializer.m new file mode 100644 index 00000000..20efe112 --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithOptionalFieldsSerializer.m @@ -0,0 +1,26 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithOptionalFieldsSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithOptionalFieldsSerializer() + field_serializers{1} = yardl.binary.OptionalSerializer(yardl.binary.Int32Serializer); + field_serializers{2} = yardl.binary.OptionalSerializer(yardl.binary.Int32Serializer); + field_serializers{3} = yardl.binary.OptionalSerializer(yardl.binary.TimeSerializer); + self@yardl.binary.RecordSerializer('test_model.RecordWithOptionalFields', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithOptionalFields + end + self.write_(outstream, value.optional_int, value.optional_int_alternate_syntax, value.optional_time); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithOptionalFields(optional_int=fields{1}, optional_int_alternate_syntax=fields{2}, optional_time=fields{3}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithOptionalGenericFieldSerializer.m b/matlab/generated/+test_model/+binary/RecordWithOptionalGenericFieldSerializer.m new file mode 100644 index 00000000..d2290501 --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithOptionalGenericFieldSerializer.m @@ -0,0 +1,24 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithOptionalGenericFieldSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithOptionalGenericFieldSerializer(t_serializer) + field_serializers{1} = yardl.binary.OptionalSerializer(t_serializer); + self@yardl.binary.RecordSerializer('test_model.RecordWithOptionalGenericField', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithOptionalGenericField + end + self.write_(outstream, value.v); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithOptionalGenericField(v=fields{1}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithOptionalGenericUnionFieldSerializer.m b/matlab/generated/+test_model/+binary/RecordWithOptionalGenericUnionFieldSerializer.m new file mode 100644 index 00000000..96b48901 --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithOptionalGenericUnionFieldSerializer.m @@ -0,0 +1,24 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithOptionalGenericUnionFieldSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithOptionalGenericUnionFieldSerializer(u_serializer, v_serializer) + field_serializers{1} = yardl.binary.UnionSerializer('test_model.UOrV', {yardl.binary.NoneSerializer, u_serializer, v_serializer}, {yardl.None, @test_model.UOrV.U, @test_model.UOrV.V}); + self@yardl.binary.RecordSerializer('test_model.RecordWithOptionalGenericUnionField', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithOptionalGenericUnionField + end + self.write_(outstream, value.v); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithOptionalGenericUnionField(v=fields{1}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithOptionalVectorSerializer.m b/matlab/generated/+test_model/+binary/RecordWithOptionalVectorSerializer.m new file mode 100644 index 00000000..a56df049 --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithOptionalVectorSerializer.m @@ -0,0 +1,24 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithOptionalVectorSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithOptionalVectorSerializer() + field_serializers{1} = yardl.binary.OptionalSerializer(yardl.binary.VectorSerializer(yardl.binary.Int32Serializer)); + self@yardl.binary.RecordSerializer('test_model.RecordWithOptionalVector', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithOptionalVector + end + self.write_(outstream, value.optional_vector); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithOptionalVector(optional_vector=fields{1}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithPrimitiveAliasesSerializer.m b/matlab/generated/+test_model/+binary/RecordWithPrimitiveAliasesSerializer.m new file mode 100644 index 00000000..1c45774f --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithPrimitiveAliasesSerializer.m @@ -0,0 +1,32 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithPrimitiveAliasesSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithPrimitiveAliasesSerializer() + field_serializers{1} = yardl.binary.Uint8Serializer; + field_serializers{2} = yardl.binary.Int32Serializer; + field_serializers{3} = yardl.binary.Uint32Serializer; + field_serializers{4} = yardl.binary.Int64Serializer; + field_serializers{5} = yardl.binary.Uint64Serializer; + field_serializers{6} = yardl.binary.Float32Serializer; + field_serializers{7} = yardl.binary.Float64Serializer; + field_serializers{8} = yardl.binary.Complexfloat32Serializer; + field_serializers{9} = yardl.binary.Complexfloat64Serializer; + self@yardl.binary.RecordSerializer('test_model.RecordWithPrimitiveAliases', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithPrimitiveAliases + end + self.write_(outstream, value.byte_field, value.int_field, value.uint_field, value.long_field, value.ulong_field, value.float_field, value.double_field, value.complexfloat_field, value.complexdouble_field); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithPrimitiveAliases(byte_field=fields{1}, int_field=fields{2}, uint_field=fields{3}, long_field=fields{4}, ulong_field=fields{5}, float_field=fields{6}, double_field=fields{7}, complexfloat_field=fields{8}, complexdouble_field=fields{9}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithPrimitivesSerializer.m b/matlab/generated/+test_model/+binary/RecordWithPrimitivesSerializer.m new file mode 100644 index 00000000..4ca70450 --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithPrimitivesSerializer.m @@ -0,0 +1,40 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithPrimitivesSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithPrimitivesSerializer() + field_serializers{1} = yardl.binary.BoolSerializer; + field_serializers{2} = yardl.binary.Int8Serializer; + field_serializers{3} = yardl.binary.Uint8Serializer; + field_serializers{4} = yardl.binary.Int16Serializer; + field_serializers{5} = yardl.binary.Uint16Serializer; + field_serializers{6} = yardl.binary.Int32Serializer; + field_serializers{7} = yardl.binary.Uint32Serializer; + field_serializers{8} = yardl.binary.Int64Serializer; + field_serializers{9} = yardl.binary.Uint64Serializer; + field_serializers{10} = yardl.binary.SizeSerializer; + field_serializers{11} = yardl.binary.Float32Serializer; + field_serializers{12} = yardl.binary.Float64Serializer; + field_serializers{13} = yardl.binary.Complexfloat32Serializer; + field_serializers{14} = yardl.binary.Complexfloat64Serializer; + field_serializers{15} = yardl.binary.DateSerializer; + field_serializers{16} = yardl.binary.TimeSerializer; + field_serializers{17} = yardl.binary.DatetimeSerializer; + self@yardl.binary.RecordSerializer('test_model.RecordWithPrimitives', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithPrimitives + end + self.write_(outstream, value.bool_field, value.int8_field, value.uint8_field, value.int16_field, value.uint16_field, value.int32_field, value.uint32_field, value.int64_field, value.uint64_field, value.size_field, value.float32_field, value.float64_field, value.complexfloat32_field, value.complexfloat64_field, value.date_field, value.time_field, value.datetime_field); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithPrimitives(bool_field=fields{1}, int8_field=fields{2}, uint8_field=fields{3}, int16_field=fields{4}, uint16_field=fields{5}, int32_field=fields{6}, uint32_field=fields{7}, int64_field=fields{8}, uint64_field=fields{9}, size_field=fields{10}, float32_field=fields{11}, float64_field=fields{12}, complexfloat32_field=fields{13}, complexfloat64_field=fields{14}, date_field=fields{15}, time_field=fields{16}, datetime_field=fields{17}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithStringsSerializer.m b/matlab/generated/+test_model/+binary/RecordWithStringsSerializer.m new file mode 100644 index 00000000..0342bf59 --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithStringsSerializer.m @@ -0,0 +1,25 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithStringsSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithStringsSerializer() + field_serializers{1} = yardl.binary.StringSerializer; + field_serializers{2} = yardl.binary.StringSerializer; + self@yardl.binary.RecordSerializer('test_model.RecordWithStrings', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithStrings + end + self.write_(outstream, value.a, value.b); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithStrings(a=fields{1}, b=fields{2}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithUnionsOfContainersSerializer.m b/matlab/generated/+test_model/+binary/RecordWithUnionsOfContainersSerializer.m new file mode 100644 index 00000000..affbce1e --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithUnionsOfContainersSerializer.m @@ -0,0 +1,26 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithUnionsOfContainersSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithUnionsOfContainersSerializer() + field_serializers{1} = yardl.binary.UnionSerializer('test_model.MapOrScalar', {yardl.binary.MapSerializer(yardl.binary.StringSerializer, yardl.binary.Int32Serializer), yardl.binary.Int32Serializer}, {@test_model.MapOrScalar.Map, @test_model.MapOrScalar.Scalar}); + field_serializers{2} = yardl.binary.UnionSerializer('test_model.VectorOrScalar', {yardl.binary.VectorSerializer(yardl.binary.Int32Serializer), yardl.binary.Int32Serializer}, {@test_model.VectorOrScalar.Vector, @test_model.VectorOrScalar.Scalar}); + field_serializers{3} = yardl.binary.UnionSerializer('test_model.ArrayOrScalar', {yardl.binary.DynamicNDArraySerializer(yardl.binary.Int32Serializer), yardl.binary.Int32Serializer}, {@test_model.ArrayOrScalar.Array, @test_model.ArrayOrScalar.Scalar}); + self@yardl.binary.RecordSerializer('test_model.RecordWithUnionsOfContainers', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithUnionsOfContainers + end + self.write_(outstream, value.map_or_scalar, value.vector_or_scalar, value.array_or_scalar); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithUnionsOfContainers(map_or_scalar=fields{1}, vector_or_scalar=fields{2}, array_or_scalar=fields{3}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithVectorOfTimesSerializer.m b/matlab/generated/+test_model/+binary/RecordWithVectorOfTimesSerializer.m new file mode 100644 index 00000000..1cb42129 --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithVectorOfTimesSerializer.m @@ -0,0 +1,24 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithVectorOfTimesSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithVectorOfTimesSerializer() + field_serializers{1} = yardl.binary.VectorSerializer(yardl.binary.TimeSerializer); + self@yardl.binary.RecordSerializer('test_model.RecordWithVectorOfTimes', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithVectorOfTimes + end + self.write_(outstream, value.times); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithVectorOfTimes(times=fields{1}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithVectorsSerializer.m b/matlab/generated/+test_model/+binary/RecordWithVectorsSerializer.m new file mode 100644 index 00000000..1b5b7fe5 --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithVectorsSerializer.m @@ -0,0 +1,26 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithVectorsSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithVectorsSerializer() + field_serializers{1} = yardl.binary.VectorSerializer(yardl.binary.Int32Serializer); + field_serializers{2} = yardl.binary.FixedVectorSerializer(yardl.binary.Int32Serializer, 3); + field_serializers{3} = yardl.binary.VectorSerializer(yardl.binary.FixedVectorSerializer(yardl.binary.Int32Serializer, 2)); + self@yardl.binary.RecordSerializer('test_model.RecordWithVectors', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithVectors + end + self.write_(outstream, value.default_vector, value.default_vector_fixed_length, value.vector_of_vectors); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithVectors(default_vector=fields{1}, default_vector_fixed_length=fields{2}, vector_of_vectors=fields{3}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithVlenCollectionsSerializer.m b/matlab/generated/+test_model/+binary/RecordWithVlenCollectionsSerializer.m new file mode 100644 index 00000000..3c177289 --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithVlenCollectionsSerializer.m @@ -0,0 +1,25 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithVlenCollectionsSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithVlenCollectionsSerializer() + field_serializers{1} = yardl.binary.VectorSerializer(yardl.binary.Int32Serializer); + field_serializers{2} = yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2); + self@yardl.binary.RecordSerializer('test_model.RecordWithVlenCollections', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithVlenCollections + end + self.write_(outstream, value.vector, value.array); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithVlenCollections(vector=fields{1}, array=fields{2}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/RecordWithVlensSerializer.m b/matlab/generated/+test_model/+binary/RecordWithVlensSerializer.m new file mode 100644 index 00000000..a068254e --- /dev/null +++ b/matlab/generated/+test_model/+binary/RecordWithVlensSerializer.m @@ -0,0 +1,26 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithVlensSerializer < yardl.binary.RecordSerializer + methods + function self = RecordWithVlensSerializer() + field_serializers{1} = yardl.binary.VectorSerializer(test_model.binary.SimpleRecordSerializer()); + field_serializers{2} = yardl.binary.Int32Serializer; + field_serializers{3} = yardl.binary.Int32Serializer; + self@yardl.binary.RecordSerializer('test_model.RecordWithVlens', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.RecordWithVlens + end + self.write_(outstream, value.a, value.b, value.c); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.RecordWithVlens(a=fields{1}, b=fields{2}, c=fields{3}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/ScalarOptionalsReader.m b/matlab/generated/+test_model/+binary/ScalarOptionalsReader.m new file mode 100644 index 00000000..ff820061 --- /dev/null +++ b/matlab/generated/+test_model/+binary/ScalarOptionalsReader.m @@ -0,0 +1,40 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef ScalarOptionalsReader < yardl.binary.BinaryProtocolReader & test_model.ScalarOptionalsReaderBase + % Binary reader for the ScalarOptionals protocol + properties (Access=protected) + optional_int_serializer + optional_record_serializer + record_with_optional_fields_serializer + optional_record_with_optional_fields_serializer + end + + methods + function self = ScalarOptionalsReader(filename) + self@test_model.ScalarOptionalsReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.ScalarOptionalsReaderBase.schema); + self.optional_int_serializer = yardl.binary.OptionalSerializer(yardl.binary.Int32Serializer); + self.optional_record_serializer = yardl.binary.OptionalSerializer(test_model.binary.SimpleRecordSerializer()); + self.record_with_optional_fields_serializer = test_model.binary.RecordWithOptionalFieldsSerializer(); + self.optional_record_with_optional_fields_serializer = yardl.binary.OptionalSerializer(test_model.binary.RecordWithOptionalFieldsSerializer()); + end + end + + methods (Access=protected) + function value = read_optional_int_(self) + value = self.optional_int_serializer.read(self.stream_); + end + + function value = read_optional_record_(self) + value = self.optional_record_serializer.read(self.stream_); + end + + function value = read_record_with_optional_fields_(self) + value = self.record_with_optional_fields_serializer.read(self.stream_); + end + + function value = read_optional_record_with_optional_fields_(self) + value = self.optional_record_with_optional_fields_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/ScalarOptionalsWriter.m b/matlab/generated/+test_model/+binary/ScalarOptionalsWriter.m new file mode 100644 index 00000000..592059c7 --- /dev/null +++ b/matlab/generated/+test_model/+binary/ScalarOptionalsWriter.m @@ -0,0 +1,40 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef ScalarOptionalsWriter < yardl.binary.BinaryProtocolWriter & test_model.ScalarOptionalsWriterBase + % Binary writer for the ScalarOptionals protocol + properties (Access=protected) + optional_int_serializer + optional_record_serializer + record_with_optional_fields_serializer + optional_record_with_optional_fields_serializer + end + + methods + function self = ScalarOptionalsWriter(filename) + self@test_model.ScalarOptionalsWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.ScalarOptionalsWriterBase.schema); + self.optional_int_serializer = yardl.binary.OptionalSerializer(yardl.binary.Int32Serializer); + self.optional_record_serializer = yardl.binary.OptionalSerializer(test_model.binary.SimpleRecordSerializer()); + self.record_with_optional_fields_serializer = test_model.binary.RecordWithOptionalFieldsSerializer(); + self.optional_record_with_optional_fields_serializer = yardl.binary.OptionalSerializer(test_model.binary.RecordWithOptionalFieldsSerializer()); + end + end + + methods (Access=protected) + function write_optional_int_(self, value) + self.optional_int_serializer.write(self.stream_, value); + end + + function write_optional_record_(self, value) + self.optional_record_serializer.write(self.stream_, value); + end + + function write_record_with_optional_fields_(self, value) + self.record_with_optional_fields_serializer.write(self.stream_, value); + end + + function write_optional_record_with_optional_fields_(self, value) + self.optional_record_with_optional_fields_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/ScalarsReader.m b/matlab/generated/+test_model/+binary/ScalarsReader.m new file mode 100644 index 00000000..b8f893d3 --- /dev/null +++ b/matlab/generated/+test_model/+binary/ScalarsReader.m @@ -0,0 +1,28 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef ScalarsReader < yardl.binary.BinaryProtocolReader & test_model.ScalarsReaderBase + % Binary reader for the Scalars protocol + properties (Access=protected) + int32_serializer + record_serializer + end + + methods + function self = ScalarsReader(filename) + self@test_model.ScalarsReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.ScalarsReaderBase.schema); + self.int32_serializer = yardl.binary.Int32Serializer; + self.record_serializer = test_model.binary.RecordWithPrimitivesSerializer(); + end + end + + methods (Access=protected) + function value = read_int32_(self) + value = self.int32_serializer.read(self.stream_); + end + + function value = read_record_(self) + value = self.record_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/ScalarsWriter.m b/matlab/generated/+test_model/+binary/ScalarsWriter.m new file mode 100644 index 00000000..7701f0a7 --- /dev/null +++ b/matlab/generated/+test_model/+binary/ScalarsWriter.m @@ -0,0 +1,28 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef ScalarsWriter < yardl.binary.BinaryProtocolWriter & test_model.ScalarsWriterBase + % Binary writer for the Scalars protocol + properties (Access=protected) + int32_serializer + record_serializer + end + + methods + function self = ScalarsWriter(filename) + self@test_model.ScalarsWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.ScalarsWriterBase.schema); + self.int32_serializer = yardl.binary.Int32Serializer; + self.record_serializer = test_model.binary.RecordWithPrimitivesSerializer(); + end + end + + methods (Access=protected) + function write_int32_(self, value) + self.int32_serializer.write(self.stream_, value); + end + + function write_record_(self, value) + self.record_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/SimpleAcquisitionSerializer.m b/matlab/generated/+test_model/+binary/SimpleAcquisitionSerializer.m new file mode 100644 index 00000000..284a092c --- /dev/null +++ b/matlab/generated/+test_model/+binary/SimpleAcquisitionSerializer.m @@ -0,0 +1,27 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef SimpleAcquisitionSerializer < yardl.binary.RecordSerializer + methods + function self = SimpleAcquisitionSerializer() + field_serializers{1} = yardl.binary.Uint64Serializer; + field_serializers{2} = test_model.binary.SimpleEncodingCountersSerializer(); + field_serializers{3} = yardl.binary.NDArraySerializer(yardl.binary.Complexfloat32Serializer, 2); + field_serializers{4} = yardl.binary.NDArraySerializer(yardl.binary.Float32Serializer, 2); + self@yardl.binary.RecordSerializer('test_model.SimpleAcquisition', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.SimpleAcquisition + end + self.write_(outstream, value.flags, value.idx, value.data, value.trajectory); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.SimpleAcquisition(flags=fields{1}, idx=fields{2}, data=fields{3}, trajectory=fields{4}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/SimpleEncodingCountersSerializer.m b/matlab/generated/+test_model/+binary/SimpleEncodingCountersSerializer.m new file mode 100644 index 00000000..e8ad021e --- /dev/null +++ b/matlab/generated/+test_model/+binary/SimpleEncodingCountersSerializer.m @@ -0,0 +1,27 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef SimpleEncodingCountersSerializer < yardl.binary.RecordSerializer + methods + function self = SimpleEncodingCountersSerializer() + field_serializers{1} = yardl.binary.OptionalSerializer(yardl.binary.Uint32Serializer); + field_serializers{2} = yardl.binary.OptionalSerializer(yardl.binary.Uint32Serializer); + field_serializers{3} = yardl.binary.OptionalSerializer(yardl.binary.Uint32Serializer); + field_serializers{4} = yardl.binary.OptionalSerializer(yardl.binary.Uint32Serializer); + self@yardl.binary.RecordSerializer('test_model.SimpleEncodingCounters', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.SimpleEncodingCounters + end + self.write_(outstream, value.e1, value.e2, value.slice, value.repetition); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.SimpleEncodingCounters(e1=fields{1}, e2=fields{2}, slice=fields{3}, repetition=fields{4}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/SimpleGenericsReader.m b/matlab/generated/+test_model/+binary/SimpleGenericsReader.m new file mode 100644 index 00000000..80bc066c --- /dev/null +++ b/matlab/generated/+test_model/+binary/SimpleGenericsReader.m @@ -0,0 +1,74 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef SimpleGenericsReader < yardl.binary.BinaryProtocolReader & test_model.SimpleGenericsReaderBase + % Binary reader for the SimpleGenerics protocol + properties (Access=protected) + float_image_serializer + int_image_serializer + int_image_alternate_syntax_serializer + string_image_serializer + int_float_tuple_serializer + float_float_tuple_serializer + int_float_tuple_alternate_syntax_serializer + int_string_tuple_serializer + stream_of_type_variants_serializer + end + + methods + function self = SimpleGenericsReader(filename) + self@test_model.SimpleGenericsReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.SimpleGenericsReaderBase.schema); + self.float_image_serializer = yardl.binary.NDArraySerializer(yardl.binary.Float32Serializer, 2); + self.int_image_serializer = yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2); + self.int_image_alternate_syntax_serializer = yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2); + self.string_image_serializer = yardl.binary.NDArraySerializer(yardl.binary.StringSerializer, 2); + self.int_float_tuple_serializer = tuples.binary.TupleSerializer(yardl.binary.Int32Serializer, yardl.binary.Float32Serializer); + self.float_float_tuple_serializer = tuples.binary.TupleSerializer(yardl.binary.Float32Serializer, yardl.binary.Float32Serializer); + self.int_float_tuple_alternate_syntax_serializer = tuples.binary.TupleSerializer(yardl.binary.Int32Serializer, yardl.binary.Float32Serializer); + self.int_string_tuple_serializer = tuples.binary.TupleSerializer(yardl.binary.Int32Serializer, yardl.binary.StringSerializer); + self.stream_of_type_variants_serializer = yardl.binary.StreamSerializer(yardl.binary.UnionSerializer('test_model.ImageFloatOrImageDouble', {yardl.binary.NDArraySerializer(yardl.binary.Float32Serializer, 2), yardl.binary.NDArraySerializer(yardl.binary.Float64Serializer, 2)}, {@test_model.ImageFloatOrImageDouble.ImageFloat, @test_model.ImageFloatOrImageDouble.ImageDouble})); + end + end + + methods (Access=protected) + function value = read_float_image_(self) + value = self.float_image_serializer.read(self.stream_); + end + + function value = read_int_image_(self) + value = self.int_image_serializer.read(self.stream_); + end + + function value = read_int_image_alternate_syntax_(self) + value = self.int_image_alternate_syntax_serializer.read(self.stream_); + end + + function value = read_string_image_(self) + value = self.string_image_serializer.read(self.stream_); + end + + function value = read_int_float_tuple_(self) + value = self.int_float_tuple_serializer.read(self.stream_); + end + + function value = read_float_float_tuple_(self) + value = self.float_float_tuple_serializer.read(self.stream_); + end + + function value = read_int_float_tuple_alternate_syntax_(self) + value = self.int_float_tuple_alternate_syntax_serializer.read(self.stream_); + end + + function value = read_int_string_tuple_(self) + value = self.int_string_tuple_serializer.read(self.stream_); + end + + function more = has_stream_of_type_variants_(self) + more = self.stream_of_type_variants_serializer.hasnext(self.stream_); + end + + function value = read_stream_of_type_variants_(self) + value = self.stream_of_type_variants_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/SimpleGenericsWriter.m b/matlab/generated/+test_model/+binary/SimpleGenericsWriter.m new file mode 100644 index 00000000..d5faf313 --- /dev/null +++ b/matlab/generated/+test_model/+binary/SimpleGenericsWriter.m @@ -0,0 +1,70 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef SimpleGenericsWriter < yardl.binary.BinaryProtocolWriter & test_model.SimpleGenericsWriterBase + % Binary writer for the SimpleGenerics protocol + properties (Access=protected) + float_image_serializer + int_image_serializer + int_image_alternate_syntax_serializer + string_image_serializer + int_float_tuple_serializer + float_float_tuple_serializer + int_float_tuple_alternate_syntax_serializer + int_string_tuple_serializer + stream_of_type_variants_serializer + end + + methods + function self = SimpleGenericsWriter(filename) + self@test_model.SimpleGenericsWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.SimpleGenericsWriterBase.schema); + self.float_image_serializer = yardl.binary.NDArraySerializer(yardl.binary.Float32Serializer, 2); + self.int_image_serializer = yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2); + self.int_image_alternate_syntax_serializer = yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2); + self.string_image_serializer = yardl.binary.NDArraySerializer(yardl.binary.StringSerializer, 2); + self.int_float_tuple_serializer = tuples.binary.TupleSerializer(yardl.binary.Int32Serializer, yardl.binary.Float32Serializer); + self.float_float_tuple_serializer = tuples.binary.TupleSerializer(yardl.binary.Float32Serializer, yardl.binary.Float32Serializer); + self.int_float_tuple_alternate_syntax_serializer = tuples.binary.TupleSerializer(yardl.binary.Int32Serializer, yardl.binary.Float32Serializer); + self.int_string_tuple_serializer = tuples.binary.TupleSerializer(yardl.binary.Int32Serializer, yardl.binary.StringSerializer); + self.stream_of_type_variants_serializer = yardl.binary.StreamSerializer(yardl.binary.UnionSerializer('test_model.ImageFloatOrImageDouble', {yardl.binary.NDArraySerializer(yardl.binary.Float32Serializer, 2), yardl.binary.NDArraySerializer(yardl.binary.Float64Serializer, 2)}, {@test_model.ImageFloatOrImageDouble.ImageFloat, @test_model.ImageFloatOrImageDouble.ImageDouble})); + end + end + + methods (Access=protected) + function write_float_image_(self, value) + self.float_image_serializer.write(self.stream_, value); + end + + function write_int_image_(self, value) + self.int_image_serializer.write(self.stream_, value); + end + + function write_int_image_alternate_syntax_(self, value) + self.int_image_alternate_syntax_serializer.write(self.stream_, value); + end + + function write_string_image_(self, value) + self.string_image_serializer.write(self.stream_, value); + end + + function write_int_float_tuple_(self, value) + self.int_float_tuple_serializer.write(self.stream_, value); + end + + function write_float_float_tuple_(self, value) + self.float_float_tuple_serializer.write(self.stream_, value); + end + + function write_int_float_tuple_alternate_syntax_(self, value) + self.int_float_tuple_alternate_syntax_serializer.write(self.stream_, value); + end + + function write_int_string_tuple_(self, value) + self.int_string_tuple_serializer.write(self.stream_, value); + end + + function write_stream_of_type_variants_(self, value) + self.stream_of_type_variants_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/SimpleRecordSerializer.m b/matlab/generated/+test_model/+binary/SimpleRecordSerializer.m new file mode 100644 index 00000000..04ef3054 --- /dev/null +++ b/matlab/generated/+test_model/+binary/SimpleRecordSerializer.m @@ -0,0 +1,26 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef SimpleRecordSerializer < yardl.binary.RecordSerializer + methods + function self = SimpleRecordSerializer() + field_serializers{1} = yardl.binary.Int32Serializer; + field_serializers{2} = yardl.binary.Int32Serializer; + field_serializers{3} = yardl.binary.Int32Serializer; + self@yardl.binary.RecordSerializer('test_model.SimpleRecord', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.SimpleRecord + end + self.write_(outstream, value.x, value.y, value.z); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.SimpleRecord(x=fields{1}, y=fields{2}, z=fields{3}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/SmallBenchmarkRecordSerializer.m b/matlab/generated/+test_model/+binary/SmallBenchmarkRecordSerializer.m new file mode 100644 index 00000000..764ed7d1 --- /dev/null +++ b/matlab/generated/+test_model/+binary/SmallBenchmarkRecordSerializer.m @@ -0,0 +1,26 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef SmallBenchmarkRecordSerializer < yardl.binary.RecordSerializer + methods + function self = SmallBenchmarkRecordSerializer() + field_serializers{1} = yardl.binary.Float64Serializer; + field_serializers{2} = yardl.binary.Float32Serializer; + field_serializers{3} = yardl.binary.Float32Serializer; + self@yardl.binary.RecordSerializer('test_model.SmallBenchmarkRecord', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.SmallBenchmarkRecord + end + self.write_(outstream, value.a, value.b, value.c); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.SmallBenchmarkRecord(a=fields{1}, b=fields{2}, c=fields{3}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/StateTestReader.m b/matlab/generated/+test_model/+binary/StateTestReader.m new file mode 100644 index 00000000..df5b39e3 --- /dev/null +++ b/matlab/generated/+test_model/+binary/StateTestReader.m @@ -0,0 +1,38 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef StateTestReader < yardl.binary.BinaryProtocolReader & test_model.StateTestReaderBase + % Binary reader for the StateTest protocol + properties (Access=protected) + an_int_serializer + a_stream_serializer + another_int_serializer + end + + methods + function self = StateTestReader(filename) + self@test_model.StateTestReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.StateTestReaderBase.schema); + self.an_int_serializer = yardl.binary.Int32Serializer; + self.a_stream_serializer = yardl.binary.StreamSerializer(yardl.binary.Int32Serializer); + self.another_int_serializer = yardl.binary.Int32Serializer; + end + end + + methods (Access=protected) + function value = read_an_int_(self) + value = self.an_int_serializer.read(self.stream_); + end + + function more = has_a_stream_(self) + more = self.a_stream_serializer.hasnext(self.stream_); + end + + function value = read_a_stream_(self) + value = self.a_stream_serializer.read(self.stream_); + end + + function value = read_another_int_(self) + value = self.another_int_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/StateTestWriter.m b/matlab/generated/+test_model/+binary/StateTestWriter.m new file mode 100644 index 00000000..065d5487 --- /dev/null +++ b/matlab/generated/+test_model/+binary/StateTestWriter.m @@ -0,0 +1,34 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef StateTestWriter < yardl.binary.BinaryProtocolWriter & test_model.StateTestWriterBase + % Binary writer for the StateTest protocol + properties (Access=protected) + an_int_serializer + a_stream_serializer + another_int_serializer + end + + methods + function self = StateTestWriter(filename) + self@test_model.StateTestWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.StateTestWriterBase.schema); + self.an_int_serializer = yardl.binary.Int32Serializer; + self.a_stream_serializer = yardl.binary.StreamSerializer(yardl.binary.Int32Serializer); + self.another_int_serializer = yardl.binary.Int32Serializer; + end + end + + methods (Access=protected) + function write_an_int_(self, value) + self.an_int_serializer.write(self.stream_, value); + end + + function write_a_stream_(self, value) + self.a_stream_serializer.write(self.stream_, value); + end + + function write_another_int_(self, value) + self.another_int_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/StreamsOfAliasedUnionsReader.m b/matlab/generated/+test_model/+binary/StreamsOfAliasedUnionsReader.m new file mode 100644 index 00000000..eaf865b8 --- /dev/null +++ b/matlab/generated/+test_model/+binary/StreamsOfAliasedUnionsReader.m @@ -0,0 +1,36 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef StreamsOfAliasedUnionsReader < yardl.binary.BinaryProtocolReader & test_model.StreamsOfAliasedUnionsReaderBase + % Binary reader for the StreamsOfAliasedUnions protocol + properties (Access=protected) + int_or_simple_record_serializer + nullable_int_or_simple_record_serializer + end + + methods + function self = StreamsOfAliasedUnionsReader(filename) + self@test_model.StreamsOfAliasedUnionsReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.StreamsOfAliasedUnionsReaderBase.schema); + self.int_or_simple_record_serializer = yardl.binary.StreamSerializer(yardl.binary.UnionSerializer('test_model.AliasedIntOrSimpleRecord', {yardl.binary.Int32Serializer, test_model.binary.SimpleRecordSerializer()}, {@test_model.AliasedIntOrSimpleRecord.Int32, @test_model.AliasedIntOrSimpleRecord.SimpleRecord})); + self.nullable_int_or_simple_record_serializer = yardl.binary.StreamSerializer(yardl.binary.UnionSerializer('test_model.AliasedNullableIntSimpleRecord', {yardl.binary.NoneSerializer, yardl.binary.Int32Serializer, test_model.binary.SimpleRecordSerializer()}, {yardl.None, @test_model.AliasedNullableIntSimpleRecord.Int32, @test_model.AliasedNullableIntSimpleRecord.SimpleRecord})); + end + end + + methods (Access=protected) + function more = has_int_or_simple_record_(self) + more = self.int_or_simple_record_serializer.hasnext(self.stream_); + end + + function value = read_int_or_simple_record_(self) + value = self.int_or_simple_record_serializer.read(self.stream_); + end + + function more = has_nullable_int_or_simple_record_(self) + more = self.nullable_int_or_simple_record_serializer.hasnext(self.stream_); + end + + function value = read_nullable_int_or_simple_record_(self) + value = self.nullable_int_or_simple_record_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/StreamsOfAliasedUnionsWriter.m b/matlab/generated/+test_model/+binary/StreamsOfAliasedUnionsWriter.m new file mode 100644 index 00000000..2766971d --- /dev/null +++ b/matlab/generated/+test_model/+binary/StreamsOfAliasedUnionsWriter.m @@ -0,0 +1,28 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef StreamsOfAliasedUnionsWriter < yardl.binary.BinaryProtocolWriter & test_model.StreamsOfAliasedUnionsWriterBase + % Binary writer for the StreamsOfAliasedUnions protocol + properties (Access=protected) + int_or_simple_record_serializer + nullable_int_or_simple_record_serializer + end + + methods + function self = StreamsOfAliasedUnionsWriter(filename) + self@test_model.StreamsOfAliasedUnionsWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.StreamsOfAliasedUnionsWriterBase.schema); + self.int_or_simple_record_serializer = yardl.binary.StreamSerializer(yardl.binary.UnionSerializer('test_model.AliasedIntOrSimpleRecord', {yardl.binary.Int32Serializer, test_model.binary.SimpleRecordSerializer()}, {@test_model.AliasedIntOrSimpleRecord.Int32, @test_model.AliasedIntOrSimpleRecord.SimpleRecord})); + self.nullable_int_or_simple_record_serializer = yardl.binary.StreamSerializer(yardl.binary.UnionSerializer('test_model.AliasedNullableIntSimpleRecord', {yardl.binary.NoneSerializer, yardl.binary.Int32Serializer, test_model.binary.SimpleRecordSerializer()}, {yardl.None, @test_model.AliasedNullableIntSimpleRecord.Int32, @test_model.AliasedNullableIntSimpleRecord.SimpleRecord})); + end + end + + methods (Access=protected) + function write_int_or_simple_record_(self, value) + self.int_or_simple_record_serializer.write(self.stream_, value); + end + + function write_nullable_int_or_simple_record_(self, value) + self.nullable_int_or_simple_record_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/StreamsOfUnionsReader.m b/matlab/generated/+test_model/+binary/StreamsOfUnionsReader.m new file mode 100644 index 00000000..98cea845 --- /dev/null +++ b/matlab/generated/+test_model/+binary/StreamsOfUnionsReader.m @@ -0,0 +1,36 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef StreamsOfUnionsReader < yardl.binary.BinaryProtocolReader & test_model.StreamsOfUnionsReaderBase + % Binary reader for the StreamsOfUnions protocol + properties (Access=protected) + int_or_simple_record_serializer + nullable_int_or_simple_record_serializer + end + + methods + function self = StreamsOfUnionsReader(filename) + self@test_model.StreamsOfUnionsReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.StreamsOfUnionsReaderBase.schema); + self.int_or_simple_record_serializer = yardl.binary.StreamSerializer(yardl.binary.UnionSerializer('test_model.Int32OrSimpleRecord', {yardl.binary.Int32Serializer, test_model.binary.SimpleRecordSerializer()}, {@test_model.Int32OrSimpleRecord.Int32, @test_model.Int32OrSimpleRecord.SimpleRecord})); + self.nullable_int_or_simple_record_serializer = yardl.binary.StreamSerializer(yardl.binary.UnionSerializer('test_model.Int32OrSimpleRecord', {yardl.binary.NoneSerializer, yardl.binary.Int32Serializer, test_model.binary.SimpleRecordSerializer()}, {yardl.None, @test_model.Int32OrSimpleRecord.Int32, @test_model.Int32OrSimpleRecord.SimpleRecord})); + end + end + + methods (Access=protected) + function more = has_int_or_simple_record_(self) + more = self.int_or_simple_record_serializer.hasnext(self.stream_); + end + + function value = read_int_or_simple_record_(self) + value = self.int_or_simple_record_serializer.read(self.stream_); + end + + function more = has_nullable_int_or_simple_record_(self) + more = self.nullable_int_or_simple_record_serializer.hasnext(self.stream_); + end + + function value = read_nullable_int_or_simple_record_(self) + value = self.nullable_int_or_simple_record_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/StreamsOfUnionsWriter.m b/matlab/generated/+test_model/+binary/StreamsOfUnionsWriter.m new file mode 100644 index 00000000..a711c70d --- /dev/null +++ b/matlab/generated/+test_model/+binary/StreamsOfUnionsWriter.m @@ -0,0 +1,28 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef StreamsOfUnionsWriter < yardl.binary.BinaryProtocolWriter & test_model.StreamsOfUnionsWriterBase + % Binary writer for the StreamsOfUnions protocol + properties (Access=protected) + int_or_simple_record_serializer + nullable_int_or_simple_record_serializer + end + + methods + function self = StreamsOfUnionsWriter(filename) + self@test_model.StreamsOfUnionsWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.StreamsOfUnionsWriterBase.schema); + self.int_or_simple_record_serializer = yardl.binary.StreamSerializer(yardl.binary.UnionSerializer('test_model.Int32OrSimpleRecord', {yardl.binary.Int32Serializer, test_model.binary.SimpleRecordSerializer()}, {@test_model.Int32OrSimpleRecord.Int32, @test_model.Int32OrSimpleRecord.SimpleRecord})); + self.nullable_int_or_simple_record_serializer = yardl.binary.StreamSerializer(yardl.binary.UnionSerializer('test_model.Int32OrSimpleRecord', {yardl.binary.NoneSerializer, yardl.binary.Int32Serializer, test_model.binary.SimpleRecordSerializer()}, {yardl.None, @test_model.Int32OrSimpleRecord.Int32, @test_model.Int32OrSimpleRecord.SimpleRecord})); + end + end + + methods (Access=protected) + function write_int_or_simple_record_(self, value) + self.int_or_simple_record_serializer.write(self.stream_, value); + end + + function write_nullable_int_or_simple_record_(self, value) + self.nullable_int_or_simple_record_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/StreamsReader.m b/matlab/generated/+test_model/+binary/StreamsReader.m new file mode 100644 index 00000000..088eef5c --- /dev/null +++ b/matlab/generated/+test_model/+binary/StreamsReader.m @@ -0,0 +1,56 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef StreamsReader < yardl.binary.BinaryProtocolReader & test_model.StreamsReaderBase + % Binary reader for the Streams protocol + properties (Access=protected) + int_data_serializer + optional_int_data_serializer + record_with_optional_vector_data_serializer + fixed_vector_serializer + end + + methods + function self = StreamsReader(filename) + self@test_model.StreamsReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.StreamsReaderBase.schema); + self.int_data_serializer = yardl.binary.StreamSerializer(yardl.binary.Int32Serializer); + self.optional_int_data_serializer = yardl.binary.StreamSerializer(yardl.binary.OptionalSerializer(yardl.binary.Int32Serializer)); + self.record_with_optional_vector_data_serializer = yardl.binary.StreamSerializer(test_model.binary.RecordWithOptionalVectorSerializer()); + self.fixed_vector_serializer = yardl.binary.StreamSerializer(yardl.binary.FixedVectorSerializer(yardl.binary.Int32Serializer, 3)); + end + end + + methods (Access=protected) + function more = has_int_data_(self) + more = self.int_data_serializer.hasnext(self.stream_); + end + + function value = read_int_data_(self) + value = self.int_data_serializer.read(self.stream_); + end + + function more = has_optional_int_data_(self) + more = self.optional_int_data_serializer.hasnext(self.stream_); + end + + function value = read_optional_int_data_(self) + value = self.optional_int_data_serializer.read(self.stream_); + end + + function more = has_record_with_optional_vector_data_(self) + more = self.record_with_optional_vector_data_serializer.hasnext(self.stream_); + end + + function value = read_record_with_optional_vector_data_(self) + value = self.record_with_optional_vector_data_serializer.read(self.stream_); + end + + function more = has_fixed_vector_(self) + more = self.fixed_vector_serializer.hasnext(self.stream_); + end + + function value = read_fixed_vector_(self) + value = self.fixed_vector_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/StreamsWriter.m b/matlab/generated/+test_model/+binary/StreamsWriter.m new file mode 100644 index 00000000..4f3240c1 --- /dev/null +++ b/matlab/generated/+test_model/+binary/StreamsWriter.m @@ -0,0 +1,40 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef StreamsWriter < yardl.binary.BinaryProtocolWriter & test_model.StreamsWriterBase + % Binary writer for the Streams protocol + properties (Access=protected) + int_data_serializer + optional_int_data_serializer + record_with_optional_vector_data_serializer + fixed_vector_serializer + end + + methods + function self = StreamsWriter(filename) + self@test_model.StreamsWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.StreamsWriterBase.schema); + self.int_data_serializer = yardl.binary.StreamSerializer(yardl.binary.Int32Serializer); + self.optional_int_data_serializer = yardl.binary.StreamSerializer(yardl.binary.OptionalSerializer(yardl.binary.Int32Serializer)); + self.record_with_optional_vector_data_serializer = yardl.binary.StreamSerializer(test_model.binary.RecordWithOptionalVectorSerializer()); + self.fixed_vector_serializer = yardl.binary.StreamSerializer(yardl.binary.FixedVectorSerializer(yardl.binary.Int32Serializer, 3)); + end + end + + methods (Access=protected) + function write_int_data_(self, value) + self.int_data_serializer.write(self.stream_, value); + end + + function write_optional_int_data_(self, value) + self.optional_int_data_serializer.write(self.stream_, value); + end + + function write_record_with_optional_vector_data_(self, value) + self.record_with_optional_vector_data_serializer.write(self.stream_, value); + end + + function write_fixed_vector_(self, value) + self.fixed_vector_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/StringsReader.m b/matlab/generated/+test_model/+binary/StringsReader.m new file mode 100644 index 00000000..c11c3c12 --- /dev/null +++ b/matlab/generated/+test_model/+binary/StringsReader.m @@ -0,0 +1,28 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef StringsReader < yardl.binary.BinaryProtocolReader & test_model.StringsReaderBase + % Binary reader for the Strings protocol + properties (Access=protected) + single_string_serializer + rec_with_string_serializer + end + + methods + function self = StringsReader(filename) + self@test_model.StringsReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.StringsReaderBase.schema); + self.single_string_serializer = yardl.binary.StringSerializer; + self.rec_with_string_serializer = test_model.binary.RecordWithStringsSerializer(); + end + end + + methods (Access=protected) + function value = read_single_string_(self) + value = self.single_string_serializer.read(self.stream_); + end + + function value = read_rec_with_string_(self) + value = self.rec_with_string_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/StringsWriter.m b/matlab/generated/+test_model/+binary/StringsWriter.m new file mode 100644 index 00000000..2c8bb7ef --- /dev/null +++ b/matlab/generated/+test_model/+binary/StringsWriter.m @@ -0,0 +1,28 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef StringsWriter < yardl.binary.BinaryProtocolWriter & test_model.StringsWriterBase + % Binary writer for the Strings protocol + properties (Access=protected) + single_string_serializer + rec_with_string_serializer + end + + methods + function self = StringsWriter(filename) + self@test_model.StringsWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.StringsWriterBase.schema); + self.single_string_serializer = yardl.binary.StringSerializer; + self.rec_with_string_serializer = test_model.binary.RecordWithStringsSerializer(); + end + end + + methods (Access=protected) + function write_single_string_(self, value) + self.single_string_serializer.write(self.stream_, value); + end + + function write_rec_with_string_(self, value) + self.rec_with_string_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/SubarraysInRecordsReader.m b/matlab/generated/+test_model/+binary/SubarraysInRecordsReader.m new file mode 100644 index 00000000..96a2eaf2 --- /dev/null +++ b/matlab/generated/+test_model/+binary/SubarraysInRecordsReader.m @@ -0,0 +1,28 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef SubarraysInRecordsReader < yardl.binary.BinaryProtocolReader & test_model.SubarraysInRecordsReaderBase + % Binary reader for the SubarraysInRecords protocol + properties (Access=protected) + with_fixed_subarrays_serializer + with_vlen_subarrays_serializer + end + + methods + function self = SubarraysInRecordsReader(filename) + self@test_model.SubarraysInRecordsReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.SubarraysInRecordsReaderBase.schema); + self.with_fixed_subarrays_serializer = yardl.binary.DynamicNDArraySerializer(test_model.binary.RecordWithFixedCollectionsSerializer()); + self.with_vlen_subarrays_serializer = yardl.binary.DynamicNDArraySerializer(test_model.binary.RecordWithVlenCollectionsSerializer()); + end + end + + methods (Access=protected) + function value = read_with_fixed_subarrays_(self) + value = self.with_fixed_subarrays_serializer.read(self.stream_); + end + + function value = read_with_vlen_subarrays_(self) + value = self.with_vlen_subarrays_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/SubarraysInRecordsWriter.m b/matlab/generated/+test_model/+binary/SubarraysInRecordsWriter.m new file mode 100644 index 00000000..159bea93 --- /dev/null +++ b/matlab/generated/+test_model/+binary/SubarraysInRecordsWriter.m @@ -0,0 +1,28 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef SubarraysInRecordsWriter < yardl.binary.BinaryProtocolWriter & test_model.SubarraysInRecordsWriterBase + % Binary writer for the SubarraysInRecords protocol + properties (Access=protected) + with_fixed_subarrays_serializer + with_vlen_subarrays_serializer + end + + methods + function self = SubarraysInRecordsWriter(filename) + self@test_model.SubarraysInRecordsWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.SubarraysInRecordsWriterBase.schema); + self.with_fixed_subarrays_serializer = yardl.binary.DynamicNDArraySerializer(test_model.binary.RecordWithFixedCollectionsSerializer()); + self.with_vlen_subarrays_serializer = yardl.binary.DynamicNDArraySerializer(test_model.binary.RecordWithVlenCollectionsSerializer()); + end + end + + methods (Access=protected) + function write_with_fixed_subarrays_(self, value) + self.with_fixed_subarrays_serializer.write(self.stream_, value); + end + + function write_with_vlen_subarrays_(self, value) + self.with_vlen_subarrays_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/SubarraysReader.m b/matlab/generated/+test_model/+binary/SubarraysReader.m new file mode 100644 index 00000000..3b6bb7f7 --- /dev/null +++ b/matlab/generated/+test_model/+binary/SubarraysReader.m @@ -0,0 +1,70 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef SubarraysReader < yardl.binary.BinaryProtocolReader & test_model.SubarraysReaderBase + % Binary reader for the Subarrays protocol + properties (Access=protected) + dynamic_with_fixed_int_subarray_serializer + dynamic_with_fixed_float_subarray_serializer + known_dim_count_with_fixed_int_subarray_serializer + known_dim_count_with_fixed_float_subarray_serializer + fixed_with_fixed_int_subarray_serializer + fixed_with_fixed_float_subarray_serializer + nested_subarray_serializer + dynamic_with_fixed_vector_subarray_serializer + generic_subarray_serializer + end + + methods + function self = SubarraysReader(filename) + self@test_model.SubarraysReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.SubarraysReaderBase.schema); + self.dynamic_with_fixed_int_subarray_serializer = yardl.binary.DynamicNDArraySerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [3])); + self.dynamic_with_fixed_float_subarray_serializer = yardl.binary.DynamicNDArraySerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Float32Serializer, [3])); + self.known_dim_count_with_fixed_int_subarray_serializer = yardl.binary.NDArraySerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [3]), 1); + self.known_dim_count_with_fixed_float_subarray_serializer = yardl.binary.NDArraySerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Float32Serializer, [3]), 1); + self.fixed_with_fixed_int_subarray_serializer = yardl.binary.FixedNDArraySerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [3]), [2]); + self.fixed_with_fixed_float_subarray_serializer = yardl.binary.FixedNDArraySerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Float32Serializer, [3]), [2]); + self.nested_subarray_serializer = yardl.binary.DynamicNDArraySerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [3]), [2])); + self.dynamic_with_fixed_vector_subarray_serializer = yardl.binary.DynamicNDArraySerializer(yardl.binary.FixedVectorSerializer(yardl.binary.Int32Serializer, 3)); + self.generic_subarray_serializer = yardl.binary.NDArraySerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [3]), 2); + end + end + + methods (Access=protected) + function value = read_dynamic_with_fixed_int_subarray_(self) + value = self.dynamic_with_fixed_int_subarray_serializer.read(self.stream_); + end + + function value = read_dynamic_with_fixed_float_subarray_(self) + value = self.dynamic_with_fixed_float_subarray_serializer.read(self.stream_); + end + + function value = read_known_dim_count_with_fixed_int_subarray_(self) + value = self.known_dim_count_with_fixed_int_subarray_serializer.read(self.stream_); + end + + function value = read_known_dim_count_with_fixed_float_subarray_(self) + value = self.known_dim_count_with_fixed_float_subarray_serializer.read(self.stream_); + end + + function value = read_fixed_with_fixed_int_subarray_(self) + value = self.fixed_with_fixed_int_subarray_serializer.read(self.stream_); + end + + function value = read_fixed_with_fixed_float_subarray_(self) + value = self.fixed_with_fixed_float_subarray_serializer.read(self.stream_); + end + + function value = read_nested_subarray_(self) + value = self.nested_subarray_serializer.read(self.stream_); + end + + function value = read_dynamic_with_fixed_vector_subarray_(self) + value = self.dynamic_with_fixed_vector_subarray_serializer.read(self.stream_); + end + + function value = read_generic_subarray_(self) + value = self.generic_subarray_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/SubarraysWriter.m b/matlab/generated/+test_model/+binary/SubarraysWriter.m new file mode 100644 index 00000000..c5a64290 --- /dev/null +++ b/matlab/generated/+test_model/+binary/SubarraysWriter.m @@ -0,0 +1,70 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef SubarraysWriter < yardl.binary.BinaryProtocolWriter & test_model.SubarraysWriterBase + % Binary writer for the Subarrays protocol + properties (Access=protected) + dynamic_with_fixed_int_subarray_serializer + dynamic_with_fixed_float_subarray_serializer + known_dim_count_with_fixed_int_subarray_serializer + known_dim_count_with_fixed_float_subarray_serializer + fixed_with_fixed_int_subarray_serializer + fixed_with_fixed_float_subarray_serializer + nested_subarray_serializer + dynamic_with_fixed_vector_subarray_serializer + generic_subarray_serializer + end + + methods + function self = SubarraysWriter(filename) + self@test_model.SubarraysWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.SubarraysWriterBase.schema); + self.dynamic_with_fixed_int_subarray_serializer = yardl.binary.DynamicNDArraySerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [3])); + self.dynamic_with_fixed_float_subarray_serializer = yardl.binary.DynamicNDArraySerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Float32Serializer, [3])); + self.known_dim_count_with_fixed_int_subarray_serializer = yardl.binary.NDArraySerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [3]), 1); + self.known_dim_count_with_fixed_float_subarray_serializer = yardl.binary.NDArraySerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Float32Serializer, [3]), 1); + self.fixed_with_fixed_int_subarray_serializer = yardl.binary.FixedNDArraySerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [3]), [2]); + self.fixed_with_fixed_float_subarray_serializer = yardl.binary.FixedNDArraySerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Float32Serializer, [3]), [2]); + self.nested_subarray_serializer = yardl.binary.DynamicNDArraySerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [3]), [2])); + self.dynamic_with_fixed_vector_subarray_serializer = yardl.binary.DynamicNDArraySerializer(yardl.binary.FixedVectorSerializer(yardl.binary.Int32Serializer, 3)); + self.generic_subarray_serializer = yardl.binary.NDArraySerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [3]), 2); + end + end + + methods (Access=protected) + function write_dynamic_with_fixed_int_subarray_(self, value) + self.dynamic_with_fixed_int_subarray_serializer.write(self.stream_, value); + end + + function write_dynamic_with_fixed_float_subarray_(self, value) + self.dynamic_with_fixed_float_subarray_serializer.write(self.stream_, value); + end + + function write_known_dim_count_with_fixed_int_subarray_(self, value) + self.known_dim_count_with_fixed_int_subarray_serializer.write(self.stream_, value); + end + + function write_known_dim_count_with_fixed_float_subarray_(self, value) + self.known_dim_count_with_fixed_float_subarray_serializer.write(self.stream_, value); + end + + function write_fixed_with_fixed_int_subarray_(self, value) + self.fixed_with_fixed_int_subarray_serializer.write(self.stream_, value); + end + + function write_fixed_with_fixed_float_subarray_(self, value) + self.fixed_with_fixed_float_subarray_serializer.write(self.stream_, value); + end + + function write_nested_subarray_(self, value) + self.nested_subarray_serializer.write(self.stream_, value); + end + + function write_dynamic_with_fixed_vector_subarray_(self, value) + self.dynamic_with_fixed_vector_subarray_serializer.write(self.stream_, value); + end + + function write_generic_subarray_(self, value) + self.generic_subarray_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/TupleWithRecordsSerializer.m b/matlab/generated/+test_model/+binary/TupleWithRecordsSerializer.m new file mode 100644 index 00000000..ee6c1e79 --- /dev/null +++ b/matlab/generated/+test_model/+binary/TupleWithRecordsSerializer.m @@ -0,0 +1,25 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TupleWithRecordsSerializer < yardl.binary.RecordSerializer + methods + function self = TupleWithRecordsSerializer() + field_serializers{1} = test_model.binary.SimpleRecordSerializer(); + field_serializers{2} = test_model.binary.SimpleRecordSerializer(); + self@yardl.binary.RecordSerializer('test_model.TupleWithRecords', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) test_model.TupleWithRecords + end + self.write_(outstream, value.a, value.b); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = test_model.TupleWithRecords(a=fields{1}, b=fields{2}); + end + end +end diff --git a/matlab/generated/+test_model/+binary/UnionsReader.m b/matlab/generated/+test_model/+binary/UnionsReader.m new file mode 100644 index 00000000..95614609 --- /dev/null +++ b/matlab/generated/+test_model/+binary/UnionsReader.m @@ -0,0 +1,40 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef UnionsReader < yardl.binary.BinaryProtocolReader & test_model.UnionsReaderBase + % Binary reader for the Unions protocol + properties (Access=protected) + int_or_simple_record_serializer + int_or_record_with_vlens_serializer + monosotate_or_int_or_simple_record_serializer + record_with_unions_serializer + end + + methods + function self = UnionsReader(filename) + self@test_model.UnionsReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.UnionsReaderBase.schema); + self.int_or_simple_record_serializer = yardl.binary.UnionSerializer('test_model.Int32OrSimpleRecord', {yardl.binary.Int32Serializer, test_model.binary.SimpleRecordSerializer()}, {@test_model.Int32OrSimpleRecord.Int32, @test_model.Int32OrSimpleRecord.SimpleRecord}); + self.int_or_record_with_vlens_serializer = yardl.binary.UnionSerializer('test_model.Int32OrRecordWithVlens', {yardl.binary.Int32Serializer, test_model.binary.RecordWithVlensSerializer()}, {@test_model.Int32OrRecordWithVlens.Int32, @test_model.Int32OrRecordWithVlens.RecordWithVlens}); + self.monosotate_or_int_or_simple_record_serializer = yardl.binary.UnionSerializer('test_model.Int32OrSimpleRecord', {yardl.binary.NoneSerializer, yardl.binary.Int32Serializer, test_model.binary.SimpleRecordSerializer()}, {yardl.None, @test_model.Int32OrSimpleRecord.Int32, @test_model.Int32OrSimpleRecord.SimpleRecord}); + self.record_with_unions_serializer = basic_types.binary.RecordWithUnionsSerializer(); + end + end + + methods (Access=protected) + function value = read_int_or_simple_record_(self) + value = self.int_or_simple_record_serializer.read(self.stream_); + end + + function value = read_int_or_record_with_vlens_(self) + value = self.int_or_record_with_vlens_serializer.read(self.stream_); + end + + function value = read_monosotate_or_int_or_simple_record_(self) + value = self.monosotate_or_int_or_simple_record_serializer.read(self.stream_); + end + + function value = read_record_with_unions_(self) + value = self.record_with_unions_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/UnionsWriter.m b/matlab/generated/+test_model/+binary/UnionsWriter.m new file mode 100644 index 00000000..dc1addc0 --- /dev/null +++ b/matlab/generated/+test_model/+binary/UnionsWriter.m @@ -0,0 +1,40 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef UnionsWriter < yardl.binary.BinaryProtocolWriter & test_model.UnionsWriterBase + % Binary writer for the Unions protocol + properties (Access=protected) + int_or_simple_record_serializer + int_or_record_with_vlens_serializer + monosotate_or_int_or_simple_record_serializer + record_with_unions_serializer + end + + methods + function self = UnionsWriter(filename) + self@test_model.UnionsWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.UnionsWriterBase.schema); + self.int_or_simple_record_serializer = yardl.binary.UnionSerializer('test_model.Int32OrSimpleRecord', {yardl.binary.Int32Serializer, test_model.binary.SimpleRecordSerializer()}, {@test_model.Int32OrSimpleRecord.Int32, @test_model.Int32OrSimpleRecord.SimpleRecord}); + self.int_or_record_with_vlens_serializer = yardl.binary.UnionSerializer('test_model.Int32OrRecordWithVlens', {yardl.binary.Int32Serializer, test_model.binary.RecordWithVlensSerializer()}, {@test_model.Int32OrRecordWithVlens.Int32, @test_model.Int32OrRecordWithVlens.RecordWithVlens}); + self.monosotate_or_int_or_simple_record_serializer = yardl.binary.UnionSerializer('test_model.Int32OrSimpleRecord', {yardl.binary.NoneSerializer, yardl.binary.Int32Serializer, test_model.binary.SimpleRecordSerializer()}, {yardl.None, @test_model.Int32OrSimpleRecord.Int32, @test_model.Int32OrSimpleRecord.SimpleRecord}); + self.record_with_unions_serializer = basic_types.binary.RecordWithUnionsSerializer(); + end + end + + methods (Access=protected) + function write_int_or_simple_record_(self, value) + self.int_or_simple_record_serializer.write(self.stream_, value); + end + + function write_int_or_record_with_vlens_(self, value) + self.int_or_record_with_vlens_serializer.write(self.stream_, value); + end + + function write_monosotate_or_int_or_simple_record_(self, value) + self.monosotate_or_int_or_simple_record_serializer.write(self.stream_, value); + end + + function write_record_with_unions_(self, value) + self.record_with_unions_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+binary/VlensReader.m b/matlab/generated/+test_model/+binary/VlensReader.m new file mode 100644 index 00000000..ee2886f5 --- /dev/null +++ b/matlab/generated/+test_model/+binary/VlensReader.m @@ -0,0 +1,40 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef VlensReader < yardl.binary.BinaryProtocolReader & test_model.VlensReaderBase + % Binary reader for the Vlens protocol + properties (Access=protected) + int_vector_serializer + complex_vector_serializer + record_with_vlens_serializer + vlen_of_record_with_vlens_serializer + end + + methods + function self = VlensReader(filename) + self@test_model.VlensReaderBase(); + self@yardl.binary.BinaryProtocolReader(filename, test_model.VlensReaderBase.schema); + self.int_vector_serializer = yardl.binary.VectorSerializer(yardl.binary.Int32Serializer); + self.complex_vector_serializer = yardl.binary.VectorSerializer(yardl.binary.Complexfloat32Serializer); + self.record_with_vlens_serializer = test_model.binary.RecordWithVlensSerializer(); + self.vlen_of_record_with_vlens_serializer = yardl.binary.VectorSerializer(test_model.binary.RecordWithVlensSerializer()); + end + end + + methods (Access=protected) + function value = read_int_vector_(self) + value = self.int_vector_serializer.read(self.stream_); + end + + function value = read_complex_vector_(self) + value = self.complex_vector_serializer.read(self.stream_); + end + + function value = read_record_with_vlens_(self) + value = self.record_with_vlens_serializer.read(self.stream_); + end + + function value = read_vlen_of_record_with_vlens_(self) + value = self.vlen_of_record_with_vlens_serializer.read(self.stream_); + end + end +end diff --git a/matlab/generated/+test_model/+binary/VlensWriter.m b/matlab/generated/+test_model/+binary/VlensWriter.m new file mode 100644 index 00000000..f7a00243 --- /dev/null +++ b/matlab/generated/+test_model/+binary/VlensWriter.m @@ -0,0 +1,40 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef VlensWriter < yardl.binary.BinaryProtocolWriter & test_model.VlensWriterBase + % Binary writer for the Vlens protocol + properties (Access=protected) + int_vector_serializer + complex_vector_serializer + record_with_vlens_serializer + vlen_of_record_with_vlens_serializer + end + + methods + function self = VlensWriter(filename) + self@test_model.VlensWriterBase(); + self@yardl.binary.BinaryProtocolWriter(filename, test_model.VlensWriterBase.schema); + self.int_vector_serializer = yardl.binary.VectorSerializer(yardl.binary.Int32Serializer); + self.complex_vector_serializer = yardl.binary.VectorSerializer(yardl.binary.Complexfloat32Serializer); + self.record_with_vlens_serializer = test_model.binary.RecordWithVlensSerializer(); + self.vlen_of_record_with_vlens_serializer = yardl.binary.VectorSerializer(test_model.binary.RecordWithVlensSerializer()); + end + end + + methods (Access=protected) + function write_int_vector_(self, value) + self.int_vector_serializer.write(self.stream_, value); + end + + function write_complex_vector_(self, value) + self.complex_vector_serializer.write(self.stream_, value); + end + + function write_record_with_vlens_(self, value) + self.record_with_vlens_serializer.write(self.stream_, value); + end + + function write_vlen_of_record_with_vlens_(self, value) + self.vlen_of_record_with_vlens_serializer.write(self.stream_, value); + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockAdvancedGenericsWriter.m b/matlab/generated/+test_model/+testing/MockAdvancedGenericsWriter.m new file mode 100644 index 00000000..e005205c --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockAdvancedGenericsWriter.m @@ -0,0 +1,88 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockAdvancedGenericsWriter < matlab.mixin.Copyable & test_model.AdvancedGenericsWriterBase + properties + testCase_ + expected_float_image_image + expected_generic_record_1 + expected_tuple_of_optionals + expected_tuple_of_optionals_alternate_syntax + expected_tuple_of_vectors + end + + methods + function self = MockAdvancedGenericsWriter(testCase) + self.testCase_ = testCase; + self.expected_float_image_image = yardl.None; + self.expected_generic_record_1 = yardl.None; + self.expected_tuple_of_optionals = yardl.None; + self.expected_tuple_of_optionals_alternate_syntax = yardl.None; + self.expected_tuple_of_vectors = yardl.None; + end + + function expect_write_float_image_image_(self, value) + self.expected_float_image_image = yardl.Optional(value); + end + + function expect_write_generic_record_1_(self, value) + self.expected_generic_record_1 = yardl.Optional(value); + end + + function expect_write_tuple_of_optionals_(self, value) + self.expected_tuple_of_optionals = yardl.Optional(value); + end + + function expect_write_tuple_of_optionals_alternate_syntax_(self, value) + self.expected_tuple_of_optionals_alternate_syntax = yardl.Optional(value); + end + + function expect_write_tuple_of_vectors_(self, value) + self.expected_tuple_of_vectors = yardl.Optional(value); + end + + function verify(self) + self.testCase_.verifyEqual(self.expected_float_image_image, yardl.None, "Expected call to write_float_image_image_ was not received"); + self.testCase_.verifyEqual(self.expected_generic_record_1, yardl.None, "Expected call to write_generic_record_1_ was not received"); + self.testCase_.verifyEqual(self.expected_tuple_of_optionals, yardl.None, "Expected call to write_tuple_of_optionals_ was not received"); + self.testCase_.verifyEqual(self.expected_tuple_of_optionals_alternate_syntax, yardl.None, "Expected call to write_tuple_of_optionals_alternate_syntax_ was not received"); + self.testCase_.verifyEqual(self.expected_tuple_of_vectors, yardl.None, "Expected call to write_tuple_of_vectors_ was not received"); + end + end + + methods (Access=protected) + function write_float_image_image_(self, value) + self.testCase_.verifyTrue(self.expected_float_image_image.has_value(), "Unexpected call to write_float_image_image_"); + self.testCase_.verifyEqual(value, self.expected_float_image_image.value, "Unexpected argument value for call to write_float_image_image_"); + self.expected_float_image_image = yardl.None; + end + + function write_generic_record_1_(self, value) + self.testCase_.verifyTrue(self.expected_generic_record_1.has_value(), "Unexpected call to write_generic_record_1_"); + self.testCase_.verifyEqual(value, self.expected_generic_record_1.value, "Unexpected argument value for call to write_generic_record_1_"); + self.expected_generic_record_1 = yardl.None; + end + + function write_tuple_of_optionals_(self, value) + self.testCase_.verifyTrue(self.expected_tuple_of_optionals.has_value(), "Unexpected call to write_tuple_of_optionals_"); + self.testCase_.verifyEqual(value, self.expected_tuple_of_optionals.value, "Unexpected argument value for call to write_tuple_of_optionals_"); + self.expected_tuple_of_optionals = yardl.None; + end + + function write_tuple_of_optionals_alternate_syntax_(self, value) + self.testCase_.verifyTrue(self.expected_tuple_of_optionals_alternate_syntax.has_value(), "Unexpected call to write_tuple_of_optionals_alternate_syntax_"); + self.testCase_.verifyEqual(value, self.expected_tuple_of_optionals_alternate_syntax.value, "Unexpected argument value for call to write_tuple_of_optionals_alternate_syntax_"); + self.expected_tuple_of_optionals_alternate_syntax = yardl.None; + end + + function write_tuple_of_vectors_(self, value) + self.testCase_.verifyTrue(self.expected_tuple_of_vectors.has_value(), "Unexpected call to write_tuple_of_vectors_"); + self.testCase_.verifyEqual(value, self.expected_tuple_of_vectors.value, "Unexpected argument value for call to write_tuple_of_vectors_"); + self.expected_tuple_of_vectors = yardl.None; + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockAliasesWriter.m b/matlab/generated/+test_model/+testing/MockAliasesWriter.m new file mode 100644 index 00000000..8a7590f5 --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockAliasesWriter.m @@ -0,0 +1,167 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockAliasesWriter < matlab.mixin.Copyable & test_model.AliasesWriterBase + properties + testCase_ + expected_aliased_string + expected_aliased_enum + expected_aliased_open_generic + expected_aliased_closed_generic + expected_aliased_optional + expected_aliased_generic_optional + expected_aliased_generic_union_2 + expected_aliased_generic_vector + expected_aliased_generic_fixed_vector + expected_stream_of_aliased_generic_union_2 + end + + methods + function self = MockAliasesWriter(testCase) + self.testCase_ = testCase; + self.expected_aliased_string = yardl.None; + self.expected_aliased_enum = yardl.None; + self.expected_aliased_open_generic = yardl.None; + self.expected_aliased_closed_generic = yardl.None; + self.expected_aliased_optional = yardl.None; + self.expected_aliased_generic_optional = yardl.None; + self.expected_aliased_generic_union_2 = yardl.None; + self.expected_aliased_generic_vector = yardl.None; + self.expected_aliased_generic_fixed_vector = yardl.None; + self.expected_stream_of_aliased_generic_union_2 = {}; + end + + function expect_write_aliased_string_(self, value) + self.expected_aliased_string = yardl.Optional(value); + end + + function expect_write_aliased_enum_(self, value) + self.expected_aliased_enum = yardl.Optional(value); + end + + function expect_write_aliased_open_generic_(self, value) + self.expected_aliased_open_generic = yardl.Optional(value); + end + + function expect_write_aliased_closed_generic_(self, value) + self.expected_aliased_closed_generic = yardl.Optional(value); + end + + function expect_write_aliased_optional_(self, value) + self.expected_aliased_optional = yardl.Optional(value); + end + + function expect_write_aliased_generic_optional_(self, value) + self.expected_aliased_generic_optional = yardl.Optional(value); + end + + function expect_write_aliased_generic_union_2_(self, value) + self.expected_aliased_generic_union_2 = yardl.Optional(value); + end + + function expect_write_aliased_generic_vector_(self, value) + self.expected_aliased_generic_vector = yardl.Optional(value); + end + + function expect_write_aliased_generic_fixed_vector_(self, value) + self.expected_aliased_generic_fixed_vector = yardl.Optional(value); + end + + function expect_write_stream_of_aliased_generic_union_2_(self, value) + if iscell(value) + for n = 1:numel(value) + self.expected_stream_of_aliased_generic_union_2{end+1} = value{n}; + end + return; + end + shape = size(value); + lastDim = ndims(value); + count = shape(lastDim); + index = repelem({':'}, lastDim-1); + for n = 1:count + self.expected_stream_of_aliased_generic_union_2{end+1} = value(index{:}, n); + end + end + + function verify(self) + self.testCase_.verifyEqual(self.expected_aliased_string, yardl.None, "Expected call to write_aliased_string_ was not received"); + self.testCase_.verifyEqual(self.expected_aliased_enum, yardl.None, "Expected call to write_aliased_enum_ was not received"); + self.testCase_.verifyEqual(self.expected_aliased_open_generic, yardl.None, "Expected call to write_aliased_open_generic_ was not received"); + self.testCase_.verifyEqual(self.expected_aliased_closed_generic, yardl.None, "Expected call to write_aliased_closed_generic_ was not received"); + self.testCase_.verifyEqual(self.expected_aliased_optional, yardl.None, "Expected call to write_aliased_optional_ was not received"); + self.testCase_.verifyEqual(self.expected_aliased_generic_optional, yardl.None, "Expected call to write_aliased_generic_optional_ was not received"); + self.testCase_.verifyEqual(self.expected_aliased_generic_union_2, yardl.None, "Expected call to write_aliased_generic_union_2_ was not received"); + self.testCase_.verifyEqual(self.expected_aliased_generic_vector, yardl.None, "Expected call to write_aliased_generic_vector_ was not received"); + self.testCase_.verifyEqual(self.expected_aliased_generic_fixed_vector, yardl.None, "Expected call to write_aliased_generic_fixed_vector_ was not received"); + self.testCase_.verifyTrue(isempty(self.expected_stream_of_aliased_generic_union_2), "Expected call to write_stream_of_aliased_generic_union_2_ was not received"); + end + end + + methods (Access=protected) + function write_aliased_string_(self, value) + self.testCase_.verifyTrue(self.expected_aliased_string.has_value(), "Unexpected call to write_aliased_string_"); + self.testCase_.verifyEqual(value, self.expected_aliased_string.value, "Unexpected argument value for call to write_aliased_string_"); + self.expected_aliased_string = yardl.None; + end + + function write_aliased_enum_(self, value) + self.testCase_.verifyTrue(self.expected_aliased_enum.has_value(), "Unexpected call to write_aliased_enum_"); + self.testCase_.verifyEqual(value, self.expected_aliased_enum.value, "Unexpected argument value for call to write_aliased_enum_"); + self.expected_aliased_enum = yardl.None; + end + + function write_aliased_open_generic_(self, value) + self.testCase_.verifyTrue(self.expected_aliased_open_generic.has_value(), "Unexpected call to write_aliased_open_generic_"); + self.testCase_.verifyEqual(value, self.expected_aliased_open_generic.value, "Unexpected argument value for call to write_aliased_open_generic_"); + self.expected_aliased_open_generic = yardl.None; + end + + function write_aliased_closed_generic_(self, value) + self.testCase_.verifyTrue(self.expected_aliased_closed_generic.has_value(), "Unexpected call to write_aliased_closed_generic_"); + self.testCase_.verifyEqual(value, self.expected_aliased_closed_generic.value, "Unexpected argument value for call to write_aliased_closed_generic_"); + self.expected_aliased_closed_generic = yardl.None; + end + + function write_aliased_optional_(self, value) + self.testCase_.verifyTrue(self.expected_aliased_optional.has_value(), "Unexpected call to write_aliased_optional_"); + self.testCase_.verifyEqual(value, self.expected_aliased_optional.value, "Unexpected argument value for call to write_aliased_optional_"); + self.expected_aliased_optional = yardl.None; + end + + function write_aliased_generic_optional_(self, value) + self.testCase_.verifyTrue(self.expected_aliased_generic_optional.has_value(), "Unexpected call to write_aliased_generic_optional_"); + self.testCase_.verifyEqual(value, self.expected_aliased_generic_optional.value, "Unexpected argument value for call to write_aliased_generic_optional_"); + self.expected_aliased_generic_optional = yardl.None; + end + + function write_aliased_generic_union_2_(self, value) + self.testCase_.verifyTrue(self.expected_aliased_generic_union_2.has_value(), "Unexpected call to write_aliased_generic_union_2_"); + self.testCase_.verifyEqual(value, self.expected_aliased_generic_union_2.value, "Unexpected argument value for call to write_aliased_generic_union_2_"); + self.expected_aliased_generic_union_2 = yardl.None; + end + + function write_aliased_generic_vector_(self, value) + self.testCase_.verifyTrue(self.expected_aliased_generic_vector.has_value(), "Unexpected call to write_aliased_generic_vector_"); + self.testCase_.verifyEqual(value, self.expected_aliased_generic_vector.value, "Unexpected argument value for call to write_aliased_generic_vector_"); + self.expected_aliased_generic_vector = yardl.None; + end + + function write_aliased_generic_fixed_vector_(self, value) + self.testCase_.verifyTrue(self.expected_aliased_generic_fixed_vector.has_value(), "Unexpected call to write_aliased_generic_fixed_vector_"); + self.testCase_.verifyEqual(value, self.expected_aliased_generic_fixed_vector.value, "Unexpected argument value for call to write_aliased_generic_fixed_vector_"); + self.expected_aliased_generic_fixed_vector = yardl.None; + end + + function write_stream_of_aliased_generic_union_2_(self, value) + assert(iscell(value)); + assert(isscalar(value)); + self.testCase_.verifyFalse(isempty(self.expected_stream_of_aliased_generic_union_2), "Unexpected call to write_stream_of_aliased_generic_union_2_"); + self.testCase_.verifyEqual(value{1}, self.expected_stream_of_aliased_generic_union_2{1}, "Unexpected argument value for call to write_stream_of_aliased_generic_union_2_"); + self.expected_stream_of_aliased_generic_union_2 = self.expected_stream_of_aliased_generic_union_2(2:end); + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockBenchmarkFloat256x256Writer.m b/matlab/generated/+test_model/+testing/MockBenchmarkFloat256x256Writer.m new file mode 100644 index 00000000..133c5a3f --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockBenchmarkFloat256x256Writer.m @@ -0,0 +1,50 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockBenchmarkFloat256x256Writer < matlab.mixin.Copyable & test_model.BenchmarkFloat256x256WriterBase + properties + testCase_ + expected_float256x256 + end + + methods + function self = MockBenchmarkFloat256x256Writer(testCase) + self.testCase_ = testCase; + self.expected_float256x256 = {}; + end + + function expect_write_float256x256_(self, value) + if iscell(value) + for n = 1:numel(value) + self.expected_float256x256{end+1} = value{n}; + end + return; + end + shape = size(value); + lastDim = ndims(value); + count = shape(lastDim); + index = repelem({':'}, lastDim-1); + for n = 1:count + self.expected_float256x256{end+1} = value(index{:}, n); + end + end + + function verify(self) + self.testCase_.verifyTrue(isempty(self.expected_float256x256), "Expected call to write_float256x256_ was not received"); + end + end + + methods (Access=protected) + function write_float256x256_(self, value) + assert(iscell(value)); + assert(isscalar(value)); + self.testCase_.verifyFalse(isempty(self.expected_float256x256), "Unexpected call to write_float256x256_"); + self.testCase_.verifyEqual(value{1}, self.expected_float256x256{1}, "Unexpected argument value for call to write_float256x256_"); + self.expected_float256x256 = self.expected_float256x256(2:end); + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockBenchmarkFloatVlenWriter.m b/matlab/generated/+test_model/+testing/MockBenchmarkFloatVlenWriter.m new file mode 100644 index 00000000..df217bfb --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockBenchmarkFloatVlenWriter.m @@ -0,0 +1,50 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockBenchmarkFloatVlenWriter < matlab.mixin.Copyable & test_model.BenchmarkFloatVlenWriterBase + properties + testCase_ + expected_float_array + end + + methods + function self = MockBenchmarkFloatVlenWriter(testCase) + self.testCase_ = testCase; + self.expected_float_array = {}; + end + + function expect_write_float_array_(self, value) + if iscell(value) + for n = 1:numel(value) + self.expected_float_array{end+1} = value{n}; + end + return; + end + shape = size(value); + lastDim = ndims(value); + count = shape(lastDim); + index = repelem({':'}, lastDim-1); + for n = 1:count + self.expected_float_array{end+1} = value(index{:}, n); + end + end + + function verify(self) + self.testCase_.verifyTrue(isempty(self.expected_float_array), "Expected call to write_float_array_ was not received"); + end + end + + methods (Access=protected) + function write_float_array_(self, value) + assert(iscell(value)); + assert(isscalar(value)); + self.testCase_.verifyFalse(isempty(self.expected_float_array), "Unexpected call to write_float_array_"); + self.testCase_.verifyEqual(value{1}, self.expected_float_array{1}, "Unexpected argument value for call to write_float_array_"); + self.expected_float_array = self.expected_float_array(2:end); + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockBenchmarkInt256x256Writer.m b/matlab/generated/+test_model/+testing/MockBenchmarkInt256x256Writer.m new file mode 100644 index 00000000..8c28f8d1 --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockBenchmarkInt256x256Writer.m @@ -0,0 +1,50 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockBenchmarkInt256x256Writer < matlab.mixin.Copyable & test_model.BenchmarkInt256x256WriterBase + properties + testCase_ + expected_int256x256 + end + + methods + function self = MockBenchmarkInt256x256Writer(testCase) + self.testCase_ = testCase; + self.expected_int256x256 = {}; + end + + function expect_write_int256x256_(self, value) + if iscell(value) + for n = 1:numel(value) + self.expected_int256x256{end+1} = value{n}; + end + return; + end + shape = size(value); + lastDim = ndims(value); + count = shape(lastDim); + index = repelem({':'}, lastDim-1); + for n = 1:count + self.expected_int256x256{end+1} = value(index{:}, n); + end + end + + function verify(self) + self.testCase_.verifyTrue(isempty(self.expected_int256x256), "Expected call to write_int256x256_ was not received"); + end + end + + methods (Access=protected) + function write_int256x256_(self, value) + assert(iscell(value)); + assert(isscalar(value)); + self.testCase_.verifyFalse(isempty(self.expected_int256x256), "Unexpected call to write_int256x256_"); + self.testCase_.verifyEqual(value{1}, self.expected_int256x256{1}, "Unexpected argument value for call to write_int256x256_"); + self.expected_int256x256 = self.expected_int256x256(2:end); + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockBenchmarkSimpleMrdWriter.m b/matlab/generated/+test_model/+testing/MockBenchmarkSimpleMrdWriter.m new file mode 100644 index 00000000..0fc522f9 --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockBenchmarkSimpleMrdWriter.m @@ -0,0 +1,50 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockBenchmarkSimpleMrdWriter < matlab.mixin.Copyable & test_model.BenchmarkSimpleMrdWriterBase + properties + testCase_ + expected_data + end + + methods + function self = MockBenchmarkSimpleMrdWriter(testCase) + self.testCase_ = testCase; + self.expected_data = {}; + end + + function expect_write_data_(self, value) + if iscell(value) + for n = 1:numel(value) + self.expected_data{end+1} = value{n}; + end + return; + end + shape = size(value); + lastDim = ndims(value); + count = shape(lastDim); + index = repelem({':'}, lastDim-1); + for n = 1:count + self.expected_data{end+1} = value(index{:}, n); + end + end + + function verify(self) + self.testCase_.verifyTrue(isempty(self.expected_data), "Expected call to write_data_ was not received"); + end + end + + methods (Access=protected) + function write_data_(self, value) + assert(iscell(value)); + assert(isscalar(value)); + self.testCase_.verifyFalse(isempty(self.expected_data), "Unexpected call to write_data_"); + self.testCase_.verifyEqual(value{1}, self.expected_data{1}, "Unexpected argument value for call to write_data_"); + self.expected_data = self.expected_data(2:end); + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockBenchmarkSmallRecordWithOptionalsWriter.m b/matlab/generated/+test_model/+testing/MockBenchmarkSmallRecordWithOptionalsWriter.m new file mode 100644 index 00000000..299bb4ed --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockBenchmarkSmallRecordWithOptionalsWriter.m @@ -0,0 +1,50 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockBenchmarkSmallRecordWithOptionalsWriter < matlab.mixin.Copyable & test_model.BenchmarkSmallRecordWithOptionalsWriterBase + properties + testCase_ + expected_small_record + end + + methods + function self = MockBenchmarkSmallRecordWithOptionalsWriter(testCase) + self.testCase_ = testCase; + self.expected_small_record = {}; + end + + function expect_write_small_record_(self, value) + if iscell(value) + for n = 1:numel(value) + self.expected_small_record{end+1} = value{n}; + end + return; + end + shape = size(value); + lastDim = ndims(value); + count = shape(lastDim); + index = repelem({':'}, lastDim-1); + for n = 1:count + self.expected_small_record{end+1} = value(index{:}, n); + end + end + + function verify(self) + self.testCase_.verifyTrue(isempty(self.expected_small_record), "Expected call to write_small_record_ was not received"); + end + end + + methods (Access=protected) + function write_small_record_(self, value) + assert(iscell(value)); + assert(isscalar(value)); + self.testCase_.verifyFalse(isempty(self.expected_small_record), "Unexpected call to write_small_record_"); + self.testCase_.verifyEqual(value{1}, self.expected_small_record{1}, "Unexpected argument value for call to write_small_record_"); + self.expected_small_record = self.expected_small_record(2:end); + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockBenchmarkSmallRecordWriter.m b/matlab/generated/+test_model/+testing/MockBenchmarkSmallRecordWriter.m new file mode 100644 index 00000000..ca14a7c7 --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockBenchmarkSmallRecordWriter.m @@ -0,0 +1,50 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockBenchmarkSmallRecordWriter < matlab.mixin.Copyable & test_model.BenchmarkSmallRecordWriterBase + properties + testCase_ + expected_small_record + end + + methods + function self = MockBenchmarkSmallRecordWriter(testCase) + self.testCase_ = testCase; + self.expected_small_record = {}; + end + + function expect_write_small_record_(self, value) + if iscell(value) + for n = 1:numel(value) + self.expected_small_record{end+1} = value{n}; + end + return; + end + shape = size(value); + lastDim = ndims(value); + count = shape(lastDim); + index = repelem({':'}, lastDim-1); + for n = 1:count + self.expected_small_record{end+1} = value(index{:}, n); + end + end + + function verify(self) + self.testCase_.verifyTrue(isempty(self.expected_small_record), "Expected call to write_small_record_ was not received"); + end + end + + methods (Access=protected) + function write_small_record_(self, value) + assert(iscell(value)); + assert(isscalar(value)); + self.testCase_.verifyFalse(isempty(self.expected_small_record), "Unexpected call to write_small_record_"); + self.testCase_.verifyEqual(value{1}, self.expected_small_record{1}, "Unexpected argument value for call to write_small_record_"); + self.expected_small_record = self.expected_small_record(2:end); + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockDynamicNDArraysWriter.m b/matlab/generated/+test_model/+testing/MockDynamicNDArraysWriter.m new file mode 100644 index 00000000..764e3629 --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockDynamicNDArraysWriter.m @@ -0,0 +1,75 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockDynamicNDArraysWriter < matlab.mixin.Copyable & test_model.DynamicNDArraysWriterBase + properties + testCase_ + expected_ints + expected_simple_record_array + expected_record_with_vlens_array + expected_record_with_dynamic_nd_arrays + end + + methods + function self = MockDynamicNDArraysWriter(testCase) + self.testCase_ = testCase; + self.expected_ints = yardl.None; + self.expected_simple_record_array = yardl.None; + self.expected_record_with_vlens_array = yardl.None; + self.expected_record_with_dynamic_nd_arrays = yardl.None; + end + + function expect_write_ints_(self, value) + self.expected_ints = yardl.Optional(value); + end + + function expect_write_simple_record_array_(self, value) + self.expected_simple_record_array = yardl.Optional(value); + end + + function expect_write_record_with_vlens_array_(self, value) + self.expected_record_with_vlens_array = yardl.Optional(value); + end + + function expect_write_record_with_dynamic_nd_arrays_(self, value) + self.expected_record_with_dynamic_nd_arrays = yardl.Optional(value); + end + + function verify(self) + self.testCase_.verifyEqual(self.expected_ints, yardl.None, "Expected call to write_ints_ was not received"); + self.testCase_.verifyEqual(self.expected_simple_record_array, yardl.None, "Expected call to write_simple_record_array_ was not received"); + self.testCase_.verifyEqual(self.expected_record_with_vlens_array, yardl.None, "Expected call to write_record_with_vlens_array_ was not received"); + self.testCase_.verifyEqual(self.expected_record_with_dynamic_nd_arrays, yardl.None, "Expected call to write_record_with_dynamic_nd_arrays_ was not received"); + end + end + + methods (Access=protected) + function write_ints_(self, value) + self.testCase_.verifyTrue(self.expected_ints.has_value(), "Unexpected call to write_ints_"); + self.testCase_.verifyEqual(value, self.expected_ints.value, "Unexpected argument value for call to write_ints_"); + self.expected_ints = yardl.None; + end + + function write_simple_record_array_(self, value) + self.testCase_.verifyTrue(self.expected_simple_record_array.has_value(), "Unexpected call to write_simple_record_array_"); + self.testCase_.verifyEqual(value, self.expected_simple_record_array.value, "Unexpected argument value for call to write_simple_record_array_"); + self.expected_simple_record_array = yardl.None; + end + + function write_record_with_vlens_array_(self, value) + self.testCase_.verifyTrue(self.expected_record_with_vlens_array.has_value(), "Unexpected call to write_record_with_vlens_array_"); + self.testCase_.verifyEqual(value, self.expected_record_with_vlens_array.value, "Unexpected argument value for call to write_record_with_vlens_array_"); + self.expected_record_with_vlens_array = yardl.None; + end + + function write_record_with_dynamic_nd_arrays_(self, value) + self.testCase_.verifyTrue(self.expected_record_with_dynamic_nd_arrays.has_value(), "Unexpected call to write_record_with_dynamic_nd_arrays_"); + self.testCase_.verifyEqual(value, self.expected_record_with_dynamic_nd_arrays.value, "Unexpected argument value for call to write_record_with_dynamic_nd_arrays_"); + self.expected_record_with_dynamic_nd_arrays = yardl.None; + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockEnumsWriter.m b/matlab/generated/+test_model/+testing/MockEnumsWriter.m new file mode 100644 index 00000000..adafd431 --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockEnumsWriter.m @@ -0,0 +1,62 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockEnumsWriter < matlab.mixin.Copyable & test_model.EnumsWriterBase + properties + testCase_ + expected_single + expected_vec + expected_size + end + + methods + function self = MockEnumsWriter(testCase) + self.testCase_ = testCase; + self.expected_single = yardl.None; + self.expected_vec = yardl.None; + self.expected_size = yardl.None; + end + + function expect_write_single_(self, value) + self.expected_single = yardl.Optional(value); + end + + function expect_write_vec_(self, value) + self.expected_vec = yardl.Optional(value); + end + + function expect_write_size_(self, value) + self.expected_size = yardl.Optional(value); + end + + function verify(self) + self.testCase_.verifyEqual(self.expected_single, yardl.None, "Expected call to write_single_ was not received"); + self.testCase_.verifyEqual(self.expected_vec, yardl.None, "Expected call to write_vec_ was not received"); + self.testCase_.verifyEqual(self.expected_size, yardl.None, "Expected call to write_size_ was not received"); + end + end + + methods (Access=protected) + function write_single_(self, value) + self.testCase_.verifyTrue(self.expected_single.has_value(), "Unexpected call to write_single_"); + self.testCase_.verifyEqual(value, self.expected_single.value, "Unexpected argument value for call to write_single_"); + self.expected_single = yardl.None; + end + + function write_vec_(self, value) + self.testCase_.verifyTrue(self.expected_vec.has_value(), "Unexpected call to write_vec_"); + self.testCase_.verifyEqual(value, self.expected_vec.value, "Unexpected argument value for call to write_vec_"); + self.expected_vec = yardl.None; + end + + function write_size_(self, value) + self.testCase_.verifyTrue(self.expected_size.has_value(), "Unexpected call to write_size_"); + self.testCase_.verifyEqual(value, self.expected_size.value, "Unexpected argument value for call to write_size_"); + self.expected_size = yardl.None; + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockFixedArraysWriter.m b/matlab/generated/+test_model/+testing/MockFixedArraysWriter.m new file mode 100644 index 00000000..5efac74a --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockFixedArraysWriter.m @@ -0,0 +1,88 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockFixedArraysWriter < matlab.mixin.Copyable & test_model.FixedArraysWriterBase + properties + testCase_ + expected_ints + expected_fixed_simple_record_array + expected_fixed_record_with_vlens_array + expected_record_with_fixed_arrays + expected_named_array + end + + methods + function self = MockFixedArraysWriter(testCase) + self.testCase_ = testCase; + self.expected_ints = yardl.None; + self.expected_fixed_simple_record_array = yardl.None; + self.expected_fixed_record_with_vlens_array = yardl.None; + self.expected_record_with_fixed_arrays = yardl.None; + self.expected_named_array = yardl.None; + end + + function expect_write_ints_(self, value) + self.expected_ints = yardl.Optional(value); + end + + function expect_write_fixed_simple_record_array_(self, value) + self.expected_fixed_simple_record_array = yardl.Optional(value); + end + + function expect_write_fixed_record_with_vlens_array_(self, value) + self.expected_fixed_record_with_vlens_array = yardl.Optional(value); + end + + function expect_write_record_with_fixed_arrays_(self, value) + self.expected_record_with_fixed_arrays = yardl.Optional(value); + end + + function expect_write_named_array_(self, value) + self.expected_named_array = yardl.Optional(value); + end + + function verify(self) + self.testCase_.verifyEqual(self.expected_ints, yardl.None, "Expected call to write_ints_ was not received"); + self.testCase_.verifyEqual(self.expected_fixed_simple_record_array, yardl.None, "Expected call to write_fixed_simple_record_array_ was not received"); + self.testCase_.verifyEqual(self.expected_fixed_record_with_vlens_array, yardl.None, "Expected call to write_fixed_record_with_vlens_array_ was not received"); + self.testCase_.verifyEqual(self.expected_record_with_fixed_arrays, yardl.None, "Expected call to write_record_with_fixed_arrays_ was not received"); + self.testCase_.verifyEqual(self.expected_named_array, yardl.None, "Expected call to write_named_array_ was not received"); + end + end + + methods (Access=protected) + function write_ints_(self, value) + self.testCase_.verifyTrue(self.expected_ints.has_value(), "Unexpected call to write_ints_"); + self.testCase_.verifyEqual(value, self.expected_ints.value, "Unexpected argument value for call to write_ints_"); + self.expected_ints = yardl.None; + end + + function write_fixed_simple_record_array_(self, value) + self.testCase_.verifyTrue(self.expected_fixed_simple_record_array.has_value(), "Unexpected call to write_fixed_simple_record_array_"); + self.testCase_.verifyEqual(value, self.expected_fixed_simple_record_array.value, "Unexpected argument value for call to write_fixed_simple_record_array_"); + self.expected_fixed_simple_record_array = yardl.None; + end + + function write_fixed_record_with_vlens_array_(self, value) + self.testCase_.verifyTrue(self.expected_fixed_record_with_vlens_array.has_value(), "Unexpected call to write_fixed_record_with_vlens_array_"); + self.testCase_.verifyEqual(value, self.expected_fixed_record_with_vlens_array.value, "Unexpected argument value for call to write_fixed_record_with_vlens_array_"); + self.expected_fixed_record_with_vlens_array = yardl.None; + end + + function write_record_with_fixed_arrays_(self, value) + self.testCase_.verifyTrue(self.expected_record_with_fixed_arrays.has_value(), "Unexpected call to write_record_with_fixed_arrays_"); + self.testCase_.verifyEqual(value, self.expected_record_with_fixed_arrays.value, "Unexpected argument value for call to write_record_with_fixed_arrays_"); + self.expected_record_with_fixed_arrays = yardl.None; + end + + function write_named_array_(self, value) + self.testCase_.verifyTrue(self.expected_named_array.has_value(), "Unexpected call to write_named_array_"); + self.testCase_.verifyEqual(value, self.expected_named_array.value, "Unexpected argument value for call to write_named_array_"); + self.expected_named_array = yardl.None; + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockFixedVectorsWriter.m b/matlab/generated/+test_model/+testing/MockFixedVectorsWriter.m new file mode 100644 index 00000000..89bccca2 --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockFixedVectorsWriter.m @@ -0,0 +1,75 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockFixedVectorsWriter < matlab.mixin.Copyable & test_model.FixedVectorsWriterBase + properties + testCase_ + expected_fixed_int_vector + expected_fixed_simple_record_vector + expected_fixed_record_with_vlens_vector + expected_record_with_fixed_vectors + end + + methods + function self = MockFixedVectorsWriter(testCase) + self.testCase_ = testCase; + self.expected_fixed_int_vector = yardl.None; + self.expected_fixed_simple_record_vector = yardl.None; + self.expected_fixed_record_with_vlens_vector = yardl.None; + self.expected_record_with_fixed_vectors = yardl.None; + end + + function expect_write_fixed_int_vector_(self, value) + self.expected_fixed_int_vector = yardl.Optional(value); + end + + function expect_write_fixed_simple_record_vector_(self, value) + self.expected_fixed_simple_record_vector = yardl.Optional(value); + end + + function expect_write_fixed_record_with_vlens_vector_(self, value) + self.expected_fixed_record_with_vlens_vector = yardl.Optional(value); + end + + function expect_write_record_with_fixed_vectors_(self, value) + self.expected_record_with_fixed_vectors = yardl.Optional(value); + end + + function verify(self) + self.testCase_.verifyEqual(self.expected_fixed_int_vector, yardl.None, "Expected call to write_fixed_int_vector_ was not received"); + self.testCase_.verifyEqual(self.expected_fixed_simple_record_vector, yardl.None, "Expected call to write_fixed_simple_record_vector_ was not received"); + self.testCase_.verifyEqual(self.expected_fixed_record_with_vlens_vector, yardl.None, "Expected call to write_fixed_record_with_vlens_vector_ was not received"); + self.testCase_.verifyEqual(self.expected_record_with_fixed_vectors, yardl.None, "Expected call to write_record_with_fixed_vectors_ was not received"); + end + end + + methods (Access=protected) + function write_fixed_int_vector_(self, value) + self.testCase_.verifyTrue(self.expected_fixed_int_vector.has_value(), "Unexpected call to write_fixed_int_vector_"); + self.testCase_.verifyEqual(value, self.expected_fixed_int_vector.value, "Unexpected argument value for call to write_fixed_int_vector_"); + self.expected_fixed_int_vector = yardl.None; + end + + function write_fixed_simple_record_vector_(self, value) + self.testCase_.verifyTrue(self.expected_fixed_simple_record_vector.has_value(), "Unexpected call to write_fixed_simple_record_vector_"); + self.testCase_.verifyEqual(value, self.expected_fixed_simple_record_vector.value, "Unexpected argument value for call to write_fixed_simple_record_vector_"); + self.expected_fixed_simple_record_vector = yardl.None; + end + + function write_fixed_record_with_vlens_vector_(self, value) + self.testCase_.verifyTrue(self.expected_fixed_record_with_vlens_vector.has_value(), "Unexpected call to write_fixed_record_with_vlens_vector_"); + self.testCase_.verifyEqual(value, self.expected_fixed_record_with_vlens_vector.value, "Unexpected argument value for call to write_fixed_record_with_vlens_vector_"); + self.expected_fixed_record_with_vlens_vector = yardl.None; + end + + function write_record_with_fixed_vectors_(self, value) + self.testCase_.verifyTrue(self.expected_record_with_fixed_vectors.has_value(), "Unexpected call to write_record_with_fixed_vectors_"); + self.testCase_.verifyEqual(value, self.expected_record_with_fixed_vectors.value, "Unexpected argument value for call to write_record_with_fixed_vectors_"); + self.expected_record_with_fixed_vectors = yardl.None; + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockFlagsWriter.m b/matlab/generated/+test_model/+testing/MockFlagsWriter.m new file mode 100644 index 00000000..31992a45 --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockFlagsWriter.m @@ -0,0 +1,77 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockFlagsWriter < matlab.mixin.Copyable & test_model.FlagsWriterBase + properties + testCase_ + expected_days + expected_formats + end + + methods + function self = MockFlagsWriter(testCase) + self.testCase_ = testCase; + self.expected_days = {}; + self.expected_formats = {}; + end + + function expect_write_days_(self, value) + if iscell(value) + for n = 1:numel(value) + self.expected_days{end+1} = value{n}; + end + return; + end + shape = size(value); + lastDim = ndims(value); + count = shape(lastDim); + index = repelem({':'}, lastDim-1); + for n = 1:count + self.expected_days{end+1} = value(index{:}, n); + end + end + + function expect_write_formats_(self, value) + if iscell(value) + for n = 1:numel(value) + self.expected_formats{end+1} = value{n}; + end + return; + end + shape = size(value); + lastDim = ndims(value); + count = shape(lastDim); + index = repelem({':'}, lastDim-1); + for n = 1:count + self.expected_formats{end+1} = value(index{:}, n); + end + end + + function verify(self) + self.testCase_.verifyTrue(isempty(self.expected_days), "Expected call to write_days_ was not received"); + self.testCase_.verifyTrue(isempty(self.expected_formats), "Expected call to write_formats_ was not received"); + end + end + + methods (Access=protected) + function write_days_(self, value) + assert(iscell(value)); + assert(isscalar(value)); + self.testCase_.verifyFalse(isempty(self.expected_days), "Unexpected call to write_days_"); + self.testCase_.verifyEqual(value{1}, self.expected_days{1}, "Unexpected argument value for call to write_days_"); + self.expected_days = self.expected_days(2:end); + end + + function write_formats_(self, value) + assert(iscell(value)); + assert(isscalar(value)); + self.testCase_.verifyFalse(isempty(self.expected_formats), "Unexpected call to write_formats_"); + self.testCase_.verifyEqual(value{1}, self.expected_formats{1}, "Unexpected argument value for call to write_formats_"); + self.expected_formats = self.expected_formats(2:end); + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockMapsWriter.m b/matlab/generated/+test_model/+testing/MockMapsWriter.m new file mode 100644 index 00000000..a1e34ef1 --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockMapsWriter.m @@ -0,0 +1,75 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockMapsWriter < matlab.mixin.Copyable & test_model.MapsWriterBase + properties + testCase_ + expected_string_to_int + expected_int_to_string + expected_string_to_union + expected_aliased_generic + end + + methods + function self = MockMapsWriter(testCase) + self.testCase_ = testCase; + self.expected_string_to_int = yardl.None; + self.expected_int_to_string = yardl.None; + self.expected_string_to_union = yardl.None; + self.expected_aliased_generic = yardl.None; + end + + function expect_write_string_to_int_(self, value) + self.expected_string_to_int = yardl.Optional(value); + end + + function expect_write_int_to_string_(self, value) + self.expected_int_to_string = yardl.Optional(value); + end + + function expect_write_string_to_union_(self, value) + self.expected_string_to_union = yardl.Optional(value); + end + + function expect_write_aliased_generic_(self, value) + self.expected_aliased_generic = yardl.Optional(value); + end + + function verify(self) + self.testCase_.verifyEqual(self.expected_string_to_int, yardl.None, "Expected call to write_string_to_int_ was not received"); + self.testCase_.verifyEqual(self.expected_int_to_string, yardl.None, "Expected call to write_int_to_string_ was not received"); + self.testCase_.verifyEqual(self.expected_string_to_union, yardl.None, "Expected call to write_string_to_union_ was not received"); + self.testCase_.verifyEqual(self.expected_aliased_generic, yardl.None, "Expected call to write_aliased_generic_ was not received"); + end + end + + methods (Access=protected) + function write_string_to_int_(self, value) + self.testCase_.verifyTrue(self.expected_string_to_int.has_value(), "Unexpected call to write_string_to_int_"); + self.testCase_.verifyEqual(value, self.expected_string_to_int.value, "Unexpected argument value for call to write_string_to_int_"); + self.expected_string_to_int = yardl.None; + end + + function write_int_to_string_(self, value) + self.testCase_.verifyTrue(self.expected_int_to_string.has_value(), "Unexpected call to write_int_to_string_"); + self.testCase_.verifyEqual(value, self.expected_int_to_string.value, "Unexpected argument value for call to write_int_to_string_"); + self.expected_int_to_string = yardl.None; + end + + function write_string_to_union_(self, value) + self.testCase_.verifyTrue(self.expected_string_to_union.has_value(), "Unexpected call to write_string_to_union_"); + self.testCase_.verifyEqual(value, self.expected_string_to_union.value, "Unexpected argument value for call to write_string_to_union_"); + self.expected_string_to_union = yardl.None; + end + + function write_aliased_generic_(self, value) + self.testCase_.verifyTrue(self.expected_aliased_generic.has_value(), "Unexpected call to write_aliased_generic_"); + self.testCase_.verifyEqual(value, self.expected_aliased_generic.value, "Unexpected argument value for call to write_aliased_generic_"); + self.expected_aliased_generic = yardl.None; + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockMultiDArraysWriter.m b/matlab/generated/+test_model/+testing/MockMultiDArraysWriter.m new file mode 100644 index 00000000..1286c0df --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockMultiDArraysWriter.m @@ -0,0 +1,77 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockMultiDArraysWriter < matlab.mixin.Copyable & test_model.MultiDArraysWriterBase + properties + testCase_ + expected_images + expected_frames + end + + methods + function self = MockMultiDArraysWriter(testCase) + self.testCase_ = testCase; + self.expected_images = {}; + self.expected_frames = {}; + end + + function expect_write_images_(self, value) + if iscell(value) + for n = 1:numel(value) + self.expected_images{end+1} = value{n}; + end + return; + end + shape = size(value); + lastDim = ndims(value); + count = shape(lastDim); + index = repelem({':'}, lastDim-1); + for n = 1:count + self.expected_images{end+1} = value(index{:}, n); + end + end + + function expect_write_frames_(self, value) + if iscell(value) + for n = 1:numel(value) + self.expected_frames{end+1} = value{n}; + end + return; + end + shape = size(value); + lastDim = ndims(value); + count = shape(lastDim); + index = repelem({':'}, lastDim-1); + for n = 1:count + self.expected_frames{end+1} = value(index{:}, n); + end + end + + function verify(self) + self.testCase_.verifyTrue(isempty(self.expected_images), "Expected call to write_images_ was not received"); + self.testCase_.verifyTrue(isempty(self.expected_frames), "Expected call to write_frames_ was not received"); + end + end + + methods (Access=protected) + function write_images_(self, value) + assert(iscell(value)); + assert(isscalar(value)); + self.testCase_.verifyFalse(isempty(self.expected_images), "Unexpected call to write_images_"); + self.testCase_.verifyEqual(value{1}, self.expected_images{1}, "Unexpected argument value for call to write_images_"); + self.expected_images = self.expected_images(2:end); + end + + function write_frames_(self, value) + assert(iscell(value)); + assert(isscalar(value)); + self.testCase_.verifyFalse(isempty(self.expected_frames), "Unexpected call to write_frames_"); + self.testCase_.verifyEqual(value{1}, self.expected_frames{1}, "Unexpected argument value for call to write_frames_"); + self.expected_frames = self.expected_frames(2:end); + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockNDArraysSingleDimensionWriter.m b/matlab/generated/+test_model/+testing/MockNDArraysSingleDimensionWriter.m new file mode 100644 index 00000000..0674eedc --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockNDArraysSingleDimensionWriter.m @@ -0,0 +1,75 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockNDArraysSingleDimensionWriter < matlab.mixin.Copyable & test_model.NDArraysSingleDimensionWriterBase + properties + testCase_ + expected_ints + expected_simple_record_array + expected_record_with_vlens_array + expected_record_with_nd_arrays + end + + methods + function self = MockNDArraysSingleDimensionWriter(testCase) + self.testCase_ = testCase; + self.expected_ints = yardl.None; + self.expected_simple_record_array = yardl.None; + self.expected_record_with_vlens_array = yardl.None; + self.expected_record_with_nd_arrays = yardl.None; + end + + function expect_write_ints_(self, value) + self.expected_ints = yardl.Optional(value); + end + + function expect_write_simple_record_array_(self, value) + self.expected_simple_record_array = yardl.Optional(value); + end + + function expect_write_record_with_vlens_array_(self, value) + self.expected_record_with_vlens_array = yardl.Optional(value); + end + + function expect_write_record_with_nd_arrays_(self, value) + self.expected_record_with_nd_arrays = yardl.Optional(value); + end + + function verify(self) + self.testCase_.verifyEqual(self.expected_ints, yardl.None, "Expected call to write_ints_ was not received"); + self.testCase_.verifyEqual(self.expected_simple_record_array, yardl.None, "Expected call to write_simple_record_array_ was not received"); + self.testCase_.verifyEqual(self.expected_record_with_vlens_array, yardl.None, "Expected call to write_record_with_vlens_array_ was not received"); + self.testCase_.verifyEqual(self.expected_record_with_nd_arrays, yardl.None, "Expected call to write_record_with_nd_arrays_ was not received"); + end + end + + methods (Access=protected) + function write_ints_(self, value) + self.testCase_.verifyTrue(self.expected_ints.has_value(), "Unexpected call to write_ints_"); + self.testCase_.verifyEqual(value, self.expected_ints.value, "Unexpected argument value for call to write_ints_"); + self.expected_ints = yardl.None; + end + + function write_simple_record_array_(self, value) + self.testCase_.verifyTrue(self.expected_simple_record_array.has_value(), "Unexpected call to write_simple_record_array_"); + self.testCase_.verifyEqual(value, self.expected_simple_record_array.value, "Unexpected argument value for call to write_simple_record_array_"); + self.expected_simple_record_array = yardl.None; + end + + function write_record_with_vlens_array_(self, value) + self.testCase_.verifyTrue(self.expected_record_with_vlens_array.has_value(), "Unexpected call to write_record_with_vlens_array_"); + self.testCase_.verifyEqual(value, self.expected_record_with_vlens_array.value, "Unexpected argument value for call to write_record_with_vlens_array_"); + self.expected_record_with_vlens_array = yardl.None; + end + + function write_record_with_nd_arrays_(self, value) + self.testCase_.verifyTrue(self.expected_record_with_nd_arrays.has_value(), "Unexpected call to write_record_with_nd_arrays_"); + self.testCase_.verifyEqual(value, self.expected_record_with_nd_arrays.value, "Unexpected argument value for call to write_record_with_nd_arrays_"); + self.expected_record_with_nd_arrays = yardl.None; + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockNDArraysWriter.m b/matlab/generated/+test_model/+testing/MockNDArraysWriter.m new file mode 100644 index 00000000..595176c8 --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockNDArraysWriter.m @@ -0,0 +1,88 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockNDArraysWriter < matlab.mixin.Copyable & test_model.NDArraysWriterBase + properties + testCase_ + expected_ints + expected_simple_record_array + expected_record_with_vlens_array + expected_record_with_nd_arrays + expected_named_array + end + + methods + function self = MockNDArraysWriter(testCase) + self.testCase_ = testCase; + self.expected_ints = yardl.None; + self.expected_simple_record_array = yardl.None; + self.expected_record_with_vlens_array = yardl.None; + self.expected_record_with_nd_arrays = yardl.None; + self.expected_named_array = yardl.None; + end + + function expect_write_ints_(self, value) + self.expected_ints = yardl.Optional(value); + end + + function expect_write_simple_record_array_(self, value) + self.expected_simple_record_array = yardl.Optional(value); + end + + function expect_write_record_with_vlens_array_(self, value) + self.expected_record_with_vlens_array = yardl.Optional(value); + end + + function expect_write_record_with_nd_arrays_(self, value) + self.expected_record_with_nd_arrays = yardl.Optional(value); + end + + function expect_write_named_array_(self, value) + self.expected_named_array = yardl.Optional(value); + end + + function verify(self) + self.testCase_.verifyEqual(self.expected_ints, yardl.None, "Expected call to write_ints_ was not received"); + self.testCase_.verifyEqual(self.expected_simple_record_array, yardl.None, "Expected call to write_simple_record_array_ was not received"); + self.testCase_.verifyEqual(self.expected_record_with_vlens_array, yardl.None, "Expected call to write_record_with_vlens_array_ was not received"); + self.testCase_.verifyEqual(self.expected_record_with_nd_arrays, yardl.None, "Expected call to write_record_with_nd_arrays_ was not received"); + self.testCase_.verifyEqual(self.expected_named_array, yardl.None, "Expected call to write_named_array_ was not received"); + end + end + + methods (Access=protected) + function write_ints_(self, value) + self.testCase_.verifyTrue(self.expected_ints.has_value(), "Unexpected call to write_ints_"); + self.testCase_.verifyEqual(value, self.expected_ints.value, "Unexpected argument value for call to write_ints_"); + self.expected_ints = yardl.None; + end + + function write_simple_record_array_(self, value) + self.testCase_.verifyTrue(self.expected_simple_record_array.has_value(), "Unexpected call to write_simple_record_array_"); + self.testCase_.verifyEqual(value, self.expected_simple_record_array.value, "Unexpected argument value for call to write_simple_record_array_"); + self.expected_simple_record_array = yardl.None; + end + + function write_record_with_vlens_array_(self, value) + self.testCase_.verifyTrue(self.expected_record_with_vlens_array.has_value(), "Unexpected call to write_record_with_vlens_array_"); + self.testCase_.verifyEqual(value, self.expected_record_with_vlens_array.value, "Unexpected argument value for call to write_record_with_vlens_array_"); + self.expected_record_with_vlens_array = yardl.None; + end + + function write_record_with_nd_arrays_(self, value) + self.testCase_.verifyTrue(self.expected_record_with_nd_arrays.has_value(), "Unexpected call to write_record_with_nd_arrays_"); + self.testCase_.verifyEqual(value, self.expected_record_with_nd_arrays.value, "Unexpected argument value for call to write_record_with_nd_arrays_"); + self.expected_record_with_nd_arrays = yardl.None; + end + + function write_named_array_(self, value) + self.testCase_.verifyTrue(self.expected_named_array.has_value(), "Unexpected call to write_named_array_"); + self.testCase_.verifyEqual(value, self.expected_named_array.value, "Unexpected argument value for call to write_named_array_"); + self.expected_named_array = yardl.None; + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockNestedRecordsWriter.m b/matlab/generated/+test_model/+testing/MockNestedRecordsWriter.m new file mode 100644 index 00000000..591d0b68 --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockNestedRecordsWriter.m @@ -0,0 +1,36 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockNestedRecordsWriter < matlab.mixin.Copyable & test_model.NestedRecordsWriterBase + properties + testCase_ + expected_tuple_with_records + end + + methods + function self = MockNestedRecordsWriter(testCase) + self.testCase_ = testCase; + self.expected_tuple_with_records = yardl.None; + end + + function expect_write_tuple_with_records_(self, value) + self.expected_tuple_with_records = yardl.Optional(value); + end + + function verify(self) + self.testCase_.verifyEqual(self.expected_tuple_with_records, yardl.None, "Expected call to write_tuple_with_records_ was not received"); + end + end + + methods (Access=protected) + function write_tuple_with_records_(self, value) + self.testCase_.verifyTrue(self.expected_tuple_with_records.has_value(), "Unexpected call to write_tuple_with_records_"); + self.testCase_.verifyEqual(value, self.expected_tuple_with_records.value, "Unexpected argument value for call to write_tuple_with_records_"); + self.expected_tuple_with_records = yardl.None; + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockOptionalVectorsWriter.m b/matlab/generated/+test_model/+testing/MockOptionalVectorsWriter.m new file mode 100644 index 00000000..d1370323 --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockOptionalVectorsWriter.m @@ -0,0 +1,36 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockOptionalVectorsWriter < matlab.mixin.Copyable & test_model.OptionalVectorsWriterBase + properties + testCase_ + expected_record_with_optional_vector + end + + methods + function self = MockOptionalVectorsWriter(testCase) + self.testCase_ = testCase; + self.expected_record_with_optional_vector = yardl.None; + end + + function expect_write_record_with_optional_vector_(self, value) + self.expected_record_with_optional_vector = yardl.Optional(value); + end + + function verify(self) + self.testCase_.verifyEqual(self.expected_record_with_optional_vector, yardl.None, "Expected call to write_record_with_optional_vector_ was not received"); + end + end + + methods (Access=protected) + function write_record_with_optional_vector_(self, value) + self.testCase_.verifyTrue(self.expected_record_with_optional_vector.has_value(), "Unexpected call to write_record_with_optional_vector_"); + self.testCase_.verifyEqual(value, self.expected_record_with_optional_vector.value, "Unexpected argument value for call to write_record_with_optional_vector_"); + self.expected_record_with_optional_vector = yardl.None; + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockProtocolWithComputedFieldsWriter.m b/matlab/generated/+test_model/+testing/MockProtocolWithComputedFieldsWriter.m new file mode 100644 index 00000000..c6487c10 --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockProtocolWithComputedFieldsWriter.m @@ -0,0 +1,36 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockProtocolWithComputedFieldsWriter < matlab.mixin.Copyable & test_model.ProtocolWithComputedFieldsWriterBase + properties + testCase_ + expected_record_with_computed_fields + end + + methods + function self = MockProtocolWithComputedFieldsWriter(testCase) + self.testCase_ = testCase; + self.expected_record_with_computed_fields = yardl.None; + end + + function expect_write_record_with_computed_fields_(self, value) + self.expected_record_with_computed_fields = yardl.Optional(value); + end + + function verify(self) + self.testCase_.verifyEqual(self.expected_record_with_computed_fields, yardl.None, "Expected call to write_record_with_computed_fields_ was not received"); + end + end + + methods (Access=protected) + function write_record_with_computed_fields_(self, value) + self.testCase_.verifyTrue(self.expected_record_with_computed_fields.has_value(), "Unexpected call to write_record_with_computed_fields_"); + self.testCase_.verifyEqual(value, self.expected_record_with_computed_fields.value, "Unexpected argument value for call to write_record_with_computed_fields_"); + self.expected_record_with_computed_fields = yardl.None; + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockProtocolWithKeywordStepsWriter.m b/matlab/generated/+test_model/+testing/MockProtocolWithKeywordStepsWriter.m new file mode 100644 index 00000000..8b727e67 --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockProtocolWithKeywordStepsWriter.m @@ -0,0 +1,63 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockProtocolWithKeywordStepsWriter < matlab.mixin.Copyable & test_model.ProtocolWithKeywordStepsWriterBase + properties + testCase_ + expected_int + expected_float + end + + methods + function self = MockProtocolWithKeywordStepsWriter(testCase) + self.testCase_ = testCase; + self.expected_int = {}; + self.expected_float = yardl.None; + end + + function expect_write_int_(self, value) + if iscell(value) + for n = 1:numel(value) + self.expected_int{end+1} = value{n}; + end + return; + end + shape = size(value); + lastDim = ndims(value); + count = shape(lastDim); + index = repelem({':'}, lastDim-1); + for n = 1:count + self.expected_int{end+1} = value(index{:}, n); + end + end + + function expect_write_float_(self, value) + self.expected_float = yardl.Optional(value); + end + + function verify(self) + self.testCase_.verifyTrue(isempty(self.expected_int), "Expected call to write_int_ was not received"); + self.testCase_.verifyEqual(self.expected_float, yardl.None, "Expected call to write_float_ was not received"); + end + end + + methods (Access=protected) + function write_int_(self, value) + assert(iscell(value)); + assert(isscalar(value)); + self.testCase_.verifyFalse(isempty(self.expected_int), "Unexpected call to write_int_"); + self.testCase_.verifyEqual(value{1}, self.expected_int{1}, "Unexpected argument value for call to write_int_"); + self.expected_int = self.expected_int(2:end); + end + + function write_float_(self, value) + self.testCase_.verifyTrue(self.expected_float.has_value(), "Unexpected call to write_float_"); + self.testCase_.verifyEqual(value, self.expected_float.value, "Unexpected argument value for call to write_float_"); + self.expected_float = yardl.None; + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockScalarOptionalsWriter.m b/matlab/generated/+test_model/+testing/MockScalarOptionalsWriter.m new file mode 100644 index 00000000..df85b932 --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockScalarOptionalsWriter.m @@ -0,0 +1,75 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockScalarOptionalsWriter < matlab.mixin.Copyable & test_model.ScalarOptionalsWriterBase + properties + testCase_ + expected_optional_int + expected_optional_record + expected_record_with_optional_fields + expected_optional_record_with_optional_fields + end + + methods + function self = MockScalarOptionalsWriter(testCase) + self.testCase_ = testCase; + self.expected_optional_int = yardl.None; + self.expected_optional_record = yardl.None; + self.expected_record_with_optional_fields = yardl.None; + self.expected_optional_record_with_optional_fields = yardl.None; + end + + function expect_write_optional_int_(self, value) + self.expected_optional_int = yardl.Optional(value); + end + + function expect_write_optional_record_(self, value) + self.expected_optional_record = yardl.Optional(value); + end + + function expect_write_record_with_optional_fields_(self, value) + self.expected_record_with_optional_fields = yardl.Optional(value); + end + + function expect_write_optional_record_with_optional_fields_(self, value) + self.expected_optional_record_with_optional_fields = yardl.Optional(value); + end + + function verify(self) + self.testCase_.verifyEqual(self.expected_optional_int, yardl.None, "Expected call to write_optional_int_ was not received"); + self.testCase_.verifyEqual(self.expected_optional_record, yardl.None, "Expected call to write_optional_record_ was not received"); + self.testCase_.verifyEqual(self.expected_record_with_optional_fields, yardl.None, "Expected call to write_record_with_optional_fields_ was not received"); + self.testCase_.verifyEqual(self.expected_optional_record_with_optional_fields, yardl.None, "Expected call to write_optional_record_with_optional_fields_ was not received"); + end + end + + methods (Access=protected) + function write_optional_int_(self, value) + self.testCase_.verifyTrue(self.expected_optional_int.has_value(), "Unexpected call to write_optional_int_"); + self.testCase_.verifyEqual(value, self.expected_optional_int.value, "Unexpected argument value for call to write_optional_int_"); + self.expected_optional_int = yardl.None; + end + + function write_optional_record_(self, value) + self.testCase_.verifyTrue(self.expected_optional_record.has_value(), "Unexpected call to write_optional_record_"); + self.testCase_.verifyEqual(value, self.expected_optional_record.value, "Unexpected argument value for call to write_optional_record_"); + self.expected_optional_record = yardl.None; + end + + function write_record_with_optional_fields_(self, value) + self.testCase_.verifyTrue(self.expected_record_with_optional_fields.has_value(), "Unexpected call to write_record_with_optional_fields_"); + self.testCase_.verifyEqual(value, self.expected_record_with_optional_fields.value, "Unexpected argument value for call to write_record_with_optional_fields_"); + self.expected_record_with_optional_fields = yardl.None; + end + + function write_optional_record_with_optional_fields_(self, value) + self.testCase_.verifyTrue(self.expected_optional_record_with_optional_fields.has_value(), "Unexpected call to write_optional_record_with_optional_fields_"); + self.testCase_.verifyEqual(value, self.expected_optional_record_with_optional_fields.value, "Unexpected argument value for call to write_optional_record_with_optional_fields_"); + self.expected_optional_record_with_optional_fields = yardl.None; + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockScalarsWriter.m b/matlab/generated/+test_model/+testing/MockScalarsWriter.m new file mode 100644 index 00000000..54c56b7f --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockScalarsWriter.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockScalarsWriter < matlab.mixin.Copyable & test_model.ScalarsWriterBase + properties + testCase_ + expected_int32 + expected_record + end + + methods + function self = MockScalarsWriter(testCase) + self.testCase_ = testCase; + self.expected_int32 = yardl.None; + self.expected_record = yardl.None; + end + + function expect_write_int32_(self, value) + self.expected_int32 = yardl.Optional(value); + end + + function expect_write_record_(self, value) + self.expected_record = yardl.Optional(value); + end + + function verify(self) + self.testCase_.verifyEqual(self.expected_int32, yardl.None, "Expected call to write_int32_ was not received"); + self.testCase_.verifyEqual(self.expected_record, yardl.None, "Expected call to write_record_ was not received"); + end + end + + methods (Access=protected) + function write_int32_(self, value) + self.testCase_.verifyTrue(self.expected_int32.has_value(), "Unexpected call to write_int32_"); + self.testCase_.verifyEqual(value, self.expected_int32.value, "Unexpected argument value for call to write_int32_"); + self.expected_int32 = yardl.None; + end + + function write_record_(self, value) + self.testCase_.verifyTrue(self.expected_record.has_value(), "Unexpected call to write_record_"); + self.testCase_.verifyEqual(value, self.expected_record.value, "Unexpected argument value for call to write_record_"); + self.expected_record = yardl.None; + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockSimpleGenericsWriter.m b/matlab/generated/+test_model/+testing/MockSimpleGenericsWriter.m new file mode 100644 index 00000000..4e131bfc --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockSimpleGenericsWriter.m @@ -0,0 +1,154 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockSimpleGenericsWriter < matlab.mixin.Copyable & test_model.SimpleGenericsWriterBase + properties + testCase_ + expected_float_image + expected_int_image + expected_int_image_alternate_syntax + expected_string_image + expected_int_float_tuple + expected_float_float_tuple + expected_int_float_tuple_alternate_syntax + expected_int_string_tuple + expected_stream_of_type_variants + end + + methods + function self = MockSimpleGenericsWriter(testCase) + self.testCase_ = testCase; + self.expected_float_image = yardl.None; + self.expected_int_image = yardl.None; + self.expected_int_image_alternate_syntax = yardl.None; + self.expected_string_image = yardl.None; + self.expected_int_float_tuple = yardl.None; + self.expected_float_float_tuple = yardl.None; + self.expected_int_float_tuple_alternate_syntax = yardl.None; + self.expected_int_string_tuple = yardl.None; + self.expected_stream_of_type_variants = {}; + end + + function expect_write_float_image_(self, value) + self.expected_float_image = yardl.Optional(value); + end + + function expect_write_int_image_(self, value) + self.expected_int_image = yardl.Optional(value); + end + + function expect_write_int_image_alternate_syntax_(self, value) + self.expected_int_image_alternate_syntax = yardl.Optional(value); + end + + function expect_write_string_image_(self, value) + self.expected_string_image = yardl.Optional(value); + end + + function expect_write_int_float_tuple_(self, value) + self.expected_int_float_tuple = yardl.Optional(value); + end + + function expect_write_float_float_tuple_(self, value) + self.expected_float_float_tuple = yardl.Optional(value); + end + + function expect_write_int_float_tuple_alternate_syntax_(self, value) + self.expected_int_float_tuple_alternate_syntax = yardl.Optional(value); + end + + function expect_write_int_string_tuple_(self, value) + self.expected_int_string_tuple = yardl.Optional(value); + end + + function expect_write_stream_of_type_variants_(self, value) + if iscell(value) + for n = 1:numel(value) + self.expected_stream_of_type_variants{end+1} = value{n}; + end + return; + end + shape = size(value); + lastDim = ndims(value); + count = shape(lastDim); + index = repelem({':'}, lastDim-1); + for n = 1:count + self.expected_stream_of_type_variants{end+1} = value(index{:}, n); + end + end + + function verify(self) + self.testCase_.verifyEqual(self.expected_float_image, yardl.None, "Expected call to write_float_image_ was not received"); + self.testCase_.verifyEqual(self.expected_int_image, yardl.None, "Expected call to write_int_image_ was not received"); + self.testCase_.verifyEqual(self.expected_int_image_alternate_syntax, yardl.None, "Expected call to write_int_image_alternate_syntax_ was not received"); + self.testCase_.verifyEqual(self.expected_string_image, yardl.None, "Expected call to write_string_image_ was not received"); + self.testCase_.verifyEqual(self.expected_int_float_tuple, yardl.None, "Expected call to write_int_float_tuple_ was not received"); + self.testCase_.verifyEqual(self.expected_float_float_tuple, yardl.None, "Expected call to write_float_float_tuple_ was not received"); + self.testCase_.verifyEqual(self.expected_int_float_tuple_alternate_syntax, yardl.None, "Expected call to write_int_float_tuple_alternate_syntax_ was not received"); + self.testCase_.verifyEqual(self.expected_int_string_tuple, yardl.None, "Expected call to write_int_string_tuple_ was not received"); + self.testCase_.verifyTrue(isempty(self.expected_stream_of_type_variants), "Expected call to write_stream_of_type_variants_ was not received"); + end + end + + methods (Access=protected) + function write_float_image_(self, value) + self.testCase_.verifyTrue(self.expected_float_image.has_value(), "Unexpected call to write_float_image_"); + self.testCase_.verifyEqual(value, self.expected_float_image.value, "Unexpected argument value for call to write_float_image_"); + self.expected_float_image = yardl.None; + end + + function write_int_image_(self, value) + self.testCase_.verifyTrue(self.expected_int_image.has_value(), "Unexpected call to write_int_image_"); + self.testCase_.verifyEqual(value, self.expected_int_image.value, "Unexpected argument value for call to write_int_image_"); + self.expected_int_image = yardl.None; + end + + function write_int_image_alternate_syntax_(self, value) + self.testCase_.verifyTrue(self.expected_int_image_alternate_syntax.has_value(), "Unexpected call to write_int_image_alternate_syntax_"); + self.testCase_.verifyEqual(value, self.expected_int_image_alternate_syntax.value, "Unexpected argument value for call to write_int_image_alternate_syntax_"); + self.expected_int_image_alternate_syntax = yardl.None; + end + + function write_string_image_(self, value) + self.testCase_.verifyTrue(self.expected_string_image.has_value(), "Unexpected call to write_string_image_"); + self.testCase_.verifyEqual(value, self.expected_string_image.value, "Unexpected argument value for call to write_string_image_"); + self.expected_string_image = yardl.None; + end + + function write_int_float_tuple_(self, value) + self.testCase_.verifyTrue(self.expected_int_float_tuple.has_value(), "Unexpected call to write_int_float_tuple_"); + self.testCase_.verifyEqual(value, self.expected_int_float_tuple.value, "Unexpected argument value for call to write_int_float_tuple_"); + self.expected_int_float_tuple = yardl.None; + end + + function write_float_float_tuple_(self, value) + self.testCase_.verifyTrue(self.expected_float_float_tuple.has_value(), "Unexpected call to write_float_float_tuple_"); + self.testCase_.verifyEqual(value, self.expected_float_float_tuple.value, "Unexpected argument value for call to write_float_float_tuple_"); + self.expected_float_float_tuple = yardl.None; + end + + function write_int_float_tuple_alternate_syntax_(self, value) + self.testCase_.verifyTrue(self.expected_int_float_tuple_alternate_syntax.has_value(), "Unexpected call to write_int_float_tuple_alternate_syntax_"); + self.testCase_.verifyEqual(value, self.expected_int_float_tuple_alternate_syntax.value, "Unexpected argument value for call to write_int_float_tuple_alternate_syntax_"); + self.expected_int_float_tuple_alternate_syntax = yardl.None; + end + + function write_int_string_tuple_(self, value) + self.testCase_.verifyTrue(self.expected_int_string_tuple.has_value(), "Unexpected call to write_int_string_tuple_"); + self.testCase_.verifyEqual(value, self.expected_int_string_tuple.value, "Unexpected argument value for call to write_int_string_tuple_"); + self.expected_int_string_tuple = yardl.None; + end + + function write_stream_of_type_variants_(self, value) + assert(iscell(value)); + assert(isscalar(value)); + self.testCase_.verifyFalse(isempty(self.expected_stream_of_type_variants), "Unexpected call to write_stream_of_type_variants_"); + self.testCase_.verifyEqual(value{1}, self.expected_stream_of_type_variants{1}, "Unexpected argument value for call to write_stream_of_type_variants_"); + self.expected_stream_of_type_variants = self.expected_stream_of_type_variants(2:end); + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockStateTestWriter.m b/matlab/generated/+test_model/+testing/MockStateTestWriter.m new file mode 100644 index 00000000..dfdf50d0 --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockStateTestWriter.m @@ -0,0 +1,76 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockStateTestWriter < matlab.mixin.Copyable & test_model.StateTestWriterBase + properties + testCase_ + expected_an_int + expected_a_stream + expected_another_int + end + + methods + function self = MockStateTestWriter(testCase) + self.testCase_ = testCase; + self.expected_an_int = yardl.None; + self.expected_a_stream = {}; + self.expected_another_int = yardl.None; + end + + function expect_write_an_int_(self, value) + self.expected_an_int = yardl.Optional(value); + end + + function expect_write_a_stream_(self, value) + if iscell(value) + for n = 1:numel(value) + self.expected_a_stream{end+1} = value{n}; + end + return; + end + shape = size(value); + lastDim = ndims(value); + count = shape(lastDim); + index = repelem({':'}, lastDim-1); + for n = 1:count + self.expected_a_stream{end+1} = value(index{:}, n); + end + end + + function expect_write_another_int_(self, value) + self.expected_another_int = yardl.Optional(value); + end + + function verify(self) + self.testCase_.verifyEqual(self.expected_an_int, yardl.None, "Expected call to write_an_int_ was not received"); + self.testCase_.verifyTrue(isempty(self.expected_a_stream), "Expected call to write_a_stream_ was not received"); + self.testCase_.verifyEqual(self.expected_another_int, yardl.None, "Expected call to write_another_int_ was not received"); + end + end + + methods (Access=protected) + function write_an_int_(self, value) + self.testCase_.verifyTrue(self.expected_an_int.has_value(), "Unexpected call to write_an_int_"); + self.testCase_.verifyEqual(value, self.expected_an_int.value, "Unexpected argument value for call to write_an_int_"); + self.expected_an_int = yardl.None; + end + + function write_a_stream_(self, value) + assert(iscell(value)); + assert(isscalar(value)); + self.testCase_.verifyFalse(isempty(self.expected_a_stream), "Unexpected call to write_a_stream_"); + self.testCase_.verifyEqual(value{1}, self.expected_a_stream{1}, "Unexpected argument value for call to write_a_stream_"); + self.expected_a_stream = self.expected_a_stream(2:end); + end + + function write_another_int_(self, value) + self.testCase_.verifyTrue(self.expected_another_int.has_value(), "Unexpected call to write_another_int_"); + self.testCase_.verifyEqual(value, self.expected_another_int.value, "Unexpected argument value for call to write_another_int_"); + self.expected_another_int = yardl.None; + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockStreamsOfAliasedUnionsWriter.m b/matlab/generated/+test_model/+testing/MockStreamsOfAliasedUnionsWriter.m new file mode 100644 index 00000000..039c4c70 --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockStreamsOfAliasedUnionsWriter.m @@ -0,0 +1,77 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockStreamsOfAliasedUnionsWriter < matlab.mixin.Copyable & test_model.StreamsOfAliasedUnionsWriterBase + properties + testCase_ + expected_int_or_simple_record + expected_nullable_int_or_simple_record + end + + methods + function self = MockStreamsOfAliasedUnionsWriter(testCase) + self.testCase_ = testCase; + self.expected_int_or_simple_record = {}; + self.expected_nullable_int_or_simple_record = {}; + end + + function expect_write_int_or_simple_record_(self, value) + if iscell(value) + for n = 1:numel(value) + self.expected_int_or_simple_record{end+1} = value{n}; + end + return; + end + shape = size(value); + lastDim = ndims(value); + count = shape(lastDim); + index = repelem({':'}, lastDim-1); + for n = 1:count + self.expected_int_or_simple_record{end+1} = value(index{:}, n); + end + end + + function expect_write_nullable_int_or_simple_record_(self, value) + if iscell(value) + for n = 1:numel(value) + self.expected_nullable_int_or_simple_record{end+1} = value{n}; + end + return; + end + shape = size(value); + lastDim = ndims(value); + count = shape(lastDim); + index = repelem({':'}, lastDim-1); + for n = 1:count + self.expected_nullable_int_or_simple_record{end+1} = value(index{:}, n); + end + end + + function verify(self) + self.testCase_.verifyTrue(isempty(self.expected_int_or_simple_record), "Expected call to write_int_or_simple_record_ was not received"); + self.testCase_.verifyTrue(isempty(self.expected_nullable_int_or_simple_record), "Expected call to write_nullable_int_or_simple_record_ was not received"); + end + end + + methods (Access=protected) + function write_int_or_simple_record_(self, value) + assert(iscell(value)); + assert(isscalar(value)); + self.testCase_.verifyFalse(isempty(self.expected_int_or_simple_record), "Unexpected call to write_int_or_simple_record_"); + self.testCase_.verifyEqual(value{1}, self.expected_int_or_simple_record{1}, "Unexpected argument value for call to write_int_or_simple_record_"); + self.expected_int_or_simple_record = self.expected_int_or_simple_record(2:end); + end + + function write_nullable_int_or_simple_record_(self, value) + assert(iscell(value)); + assert(isscalar(value)); + self.testCase_.verifyFalse(isempty(self.expected_nullable_int_or_simple_record), "Unexpected call to write_nullable_int_or_simple_record_"); + self.testCase_.verifyEqual(value{1}, self.expected_nullable_int_or_simple_record{1}, "Unexpected argument value for call to write_nullable_int_or_simple_record_"); + self.expected_nullable_int_or_simple_record = self.expected_nullable_int_or_simple_record(2:end); + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockStreamsOfUnionsWriter.m b/matlab/generated/+test_model/+testing/MockStreamsOfUnionsWriter.m new file mode 100644 index 00000000..4b836e75 --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockStreamsOfUnionsWriter.m @@ -0,0 +1,77 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockStreamsOfUnionsWriter < matlab.mixin.Copyable & test_model.StreamsOfUnionsWriterBase + properties + testCase_ + expected_int_or_simple_record + expected_nullable_int_or_simple_record + end + + methods + function self = MockStreamsOfUnionsWriter(testCase) + self.testCase_ = testCase; + self.expected_int_or_simple_record = {}; + self.expected_nullable_int_or_simple_record = {}; + end + + function expect_write_int_or_simple_record_(self, value) + if iscell(value) + for n = 1:numel(value) + self.expected_int_or_simple_record{end+1} = value{n}; + end + return; + end + shape = size(value); + lastDim = ndims(value); + count = shape(lastDim); + index = repelem({':'}, lastDim-1); + for n = 1:count + self.expected_int_or_simple_record{end+1} = value(index{:}, n); + end + end + + function expect_write_nullable_int_or_simple_record_(self, value) + if iscell(value) + for n = 1:numel(value) + self.expected_nullable_int_or_simple_record{end+1} = value{n}; + end + return; + end + shape = size(value); + lastDim = ndims(value); + count = shape(lastDim); + index = repelem({':'}, lastDim-1); + for n = 1:count + self.expected_nullable_int_or_simple_record{end+1} = value(index{:}, n); + end + end + + function verify(self) + self.testCase_.verifyTrue(isempty(self.expected_int_or_simple_record), "Expected call to write_int_or_simple_record_ was not received"); + self.testCase_.verifyTrue(isempty(self.expected_nullable_int_or_simple_record), "Expected call to write_nullable_int_or_simple_record_ was not received"); + end + end + + methods (Access=protected) + function write_int_or_simple_record_(self, value) + assert(iscell(value)); + assert(isscalar(value)); + self.testCase_.verifyFalse(isempty(self.expected_int_or_simple_record), "Unexpected call to write_int_or_simple_record_"); + self.testCase_.verifyEqual(value{1}, self.expected_int_or_simple_record{1}, "Unexpected argument value for call to write_int_or_simple_record_"); + self.expected_int_or_simple_record = self.expected_int_or_simple_record(2:end); + end + + function write_nullable_int_or_simple_record_(self, value) + assert(iscell(value)); + assert(isscalar(value)); + self.testCase_.verifyFalse(isempty(self.expected_nullable_int_or_simple_record), "Unexpected call to write_nullable_int_or_simple_record_"); + self.testCase_.verifyEqual(value{1}, self.expected_nullable_int_or_simple_record{1}, "Unexpected argument value for call to write_nullable_int_or_simple_record_"); + self.expected_nullable_int_or_simple_record = self.expected_nullable_int_or_simple_record(2:end); + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockStreamsWriter.m b/matlab/generated/+test_model/+testing/MockStreamsWriter.m new file mode 100644 index 00000000..fd0988cd --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockStreamsWriter.m @@ -0,0 +1,131 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockStreamsWriter < matlab.mixin.Copyable & test_model.StreamsWriterBase + properties + testCase_ + expected_int_data + expected_optional_int_data + expected_record_with_optional_vector_data + expected_fixed_vector + end + + methods + function self = MockStreamsWriter(testCase) + self.testCase_ = testCase; + self.expected_int_data = {}; + self.expected_optional_int_data = {}; + self.expected_record_with_optional_vector_data = {}; + self.expected_fixed_vector = {}; + end + + function expect_write_int_data_(self, value) + if iscell(value) + for n = 1:numel(value) + self.expected_int_data{end+1} = value{n}; + end + return; + end + shape = size(value); + lastDim = ndims(value); + count = shape(lastDim); + index = repelem({':'}, lastDim-1); + for n = 1:count + self.expected_int_data{end+1} = value(index{:}, n); + end + end + + function expect_write_optional_int_data_(self, value) + if iscell(value) + for n = 1:numel(value) + self.expected_optional_int_data{end+1} = value{n}; + end + return; + end + shape = size(value); + lastDim = ndims(value); + count = shape(lastDim); + index = repelem({':'}, lastDim-1); + for n = 1:count + self.expected_optional_int_data{end+1} = value(index{:}, n); + end + end + + function expect_write_record_with_optional_vector_data_(self, value) + if iscell(value) + for n = 1:numel(value) + self.expected_record_with_optional_vector_data{end+1} = value{n}; + end + return; + end + shape = size(value); + lastDim = ndims(value); + count = shape(lastDim); + index = repelem({':'}, lastDim-1); + for n = 1:count + self.expected_record_with_optional_vector_data{end+1} = value(index{:}, n); + end + end + + function expect_write_fixed_vector_(self, value) + if iscell(value) + for n = 1:numel(value) + self.expected_fixed_vector{end+1} = value{n}; + end + return; + end + shape = size(value); + lastDim = ndims(value); + count = shape(lastDim); + index = repelem({':'}, lastDim-1); + for n = 1:count + self.expected_fixed_vector{end+1} = value(index{:}, n); + end + end + + function verify(self) + self.testCase_.verifyTrue(isempty(self.expected_int_data), "Expected call to write_int_data_ was not received"); + self.testCase_.verifyTrue(isempty(self.expected_optional_int_data), "Expected call to write_optional_int_data_ was not received"); + self.testCase_.verifyTrue(isempty(self.expected_record_with_optional_vector_data), "Expected call to write_record_with_optional_vector_data_ was not received"); + self.testCase_.verifyTrue(isempty(self.expected_fixed_vector), "Expected call to write_fixed_vector_ was not received"); + end + end + + methods (Access=protected) + function write_int_data_(self, value) + assert(iscell(value)); + assert(isscalar(value)); + self.testCase_.verifyFalse(isempty(self.expected_int_data), "Unexpected call to write_int_data_"); + self.testCase_.verifyEqual(value{1}, self.expected_int_data{1}, "Unexpected argument value for call to write_int_data_"); + self.expected_int_data = self.expected_int_data(2:end); + end + + function write_optional_int_data_(self, value) + assert(iscell(value)); + assert(isscalar(value)); + self.testCase_.verifyFalse(isempty(self.expected_optional_int_data), "Unexpected call to write_optional_int_data_"); + self.testCase_.verifyEqual(value{1}, self.expected_optional_int_data{1}, "Unexpected argument value for call to write_optional_int_data_"); + self.expected_optional_int_data = self.expected_optional_int_data(2:end); + end + + function write_record_with_optional_vector_data_(self, value) + assert(iscell(value)); + assert(isscalar(value)); + self.testCase_.verifyFalse(isempty(self.expected_record_with_optional_vector_data), "Unexpected call to write_record_with_optional_vector_data_"); + self.testCase_.verifyEqual(value{1}, self.expected_record_with_optional_vector_data{1}, "Unexpected argument value for call to write_record_with_optional_vector_data_"); + self.expected_record_with_optional_vector_data = self.expected_record_with_optional_vector_data(2:end); + end + + function write_fixed_vector_(self, value) + assert(iscell(value)); + assert(isscalar(value)); + self.testCase_.verifyFalse(isempty(self.expected_fixed_vector), "Unexpected call to write_fixed_vector_"); + self.testCase_.verifyEqual(value{1}, self.expected_fixed_vector{1}, "Unexpected argument value for call to write_fixed_vector_"); + self.expected_fixed_vector = self.expected_fixed_vector(2:end); + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockStringsWriter.m b/matlab/generated/+test_model/+testing/MockStringsWriter.m new file mode 100644 index 00000000..cdd7cb30 --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockStringsWriter.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockStringsWriter < matlab.mixin.Copyable & test_model.StringsWriterBase + properties + testCase_ + expected_single_string + expected_rec_with_string + end + + methods + function self = MockStringsWriter(testCase) + self.testCase_ = testCase; + self.expected_single_string = yardl.None; + self.expected_rec_with_string = yardl.None; + end + + function expect_write_single_string_(self, value) + self.expected_single_string = yardl.Optional(value); + end + + function expect_write_rec_with_string_(self, value) + self.expected_rec_with_string = yardl.Optional(value); + end + + function verify(self) + self.testCase_.verifyEqual(self.expected_single_string, yardl.None, "Expected call to write_single_string_ was not received"); + self.testCase_.verifyEqual(self.expected_rec_with_string, yardl.None, "Expected call to write_rec_with_string_ was not received"); + end + end + + methods (Access=protected) + function write_single_string_(self, value) + self.testCase_.verifyTrue(self.expected_single_string.has_value(), "Unexpected call to write_single_string_"); + self.testCase_.verifyEqual(value, self.expected_single_string.value, "Unexpected argument value for call to write_single_string_"); + self.expected_single_string = yardl.None; + end + + function write_rec_with_string_(self, value) + self.testCase_.verifyTrue(self.expected_rec_with_string.has_value(), "Unexpected call to write_rec_with_string_"); + self.testCase_.verifyEqual(value, self.expected_rec_with_string.value, "Unexpected argument value for call to write_rec_with_string_"); + self.expected_rec_with_string = yardl.None; + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockSubarraysInRecordsWriter.m b/matlab/generated/+test_model/+testing/MockSubarraysInRecordsWriter.m new file mode 100644 index 00000000..35996647 --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockSubarraysInRecordsWriter.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockSubarraysInRecordsWriter < matlab.mixin.Copyable & test_model.SubarraysInRecordsWriterBase + properties + testCase_ + expected_with_fixed_subarrays + expected_with_vlen_subarrays + end + + methods + function self = MockSubarraysInRecordsWriter(testCase) + self.testCase_ = testCase; + self.expected_with_fixed_subarrays = yardl.None; + self.expected_with_vlen_subarrays = yardl.None; + end + + function expect_write_with_fixed_subarrays_(self, value) + self.expected_with_fixed_subarrays = yardl.Optional(value); + end + + function expect_write_with_vlen_subarrays_(self, value) + self.expected_with_vlen_subarrays = yardl.Optional(value); + end + + function verify(self) + self.testCase_.verifyEqual(self.expected_with_fixed_subarrays, yardl.None, "Expected call to write_with_fixed_subarrays_ was not received"); + self.testCase_.verifyEqual(self.expected_with_vlen_subarrays, yardl.None, "Expected call to write_with_vlen_subarrays_ was not received"); + end + end + + methods (Access=protected) + function write_with_fixed_subarrays_(self, value) + self.testCase_.verifyTrue(self.expected_with_fixed_subarrays.has_value(), "Unexpected call to write_with_fixed_subarrays_"); + self.testCase_.verifyEqual(value, self.expected_with_fixed_subarrays.value, "Unexpected argument value for call to write_with_fixed_subarrays_"); + self.expected_with_fixed_subarrays = yardl.None; + end + + function write_with_vlen_subarrays_(self, value) + self.testCase_.verifyTrue(self.expected_with_vlen_subarrays.has_value(), "Unexpected call to write_with_vlen_subarrays_"); + self.testCase_.verifyEqual(value, self.expected_with_vlen_subarrays.value, "Unexpected argument value for call to write_with_vlen_subarrays_"); + self.expected_with_vlen_subarrays = yardl.None; + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockSubarraysWriter.m b/matlab/generated/+test_model/+testing/MockSubarraysWriter.m new file mode 100644 index 00000000..e0e48f43 --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockSubarraysWriter.m @@ -0,0 +1,140 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockSubarraysWriter < matlab.mixin.Copyable & test_model.SubarraysWriterBase + properties + testCase_ + expected_dynamic_with_fixed_int_subarray + expected_dynamic_with_fixed_float_subarray + expected_known_dim_count_with_fixed_int_subarray + expected_known_dim_count_with_fixed_float_subarray + expected_fixed_with_fixed_int_subarray + expected_fixed_with_fixed_float_subarray + expected_nested_subarray + expected_dynamic_with_fixed_vector_subarray + expected_generic_subarray + end + + methods + function self = MockSubarraysWriter(testCase) + self.testCase_ = testCase; + self.expected_dynamic_with_fixed_int_subarray = yardl.None; + self.expected_dynamic_with_fixed_float_subarray = yardl.None; + self.expected_known_dim_count_with_fixed_int_subarray = yardl.None; + self.expected_known_dim_count_with_fixed_float_subarray = yardl.None; + self.expected_fixed_with_fixed_int_subarray = yardl.None; + self.expected_fixed_with_fixed_float_subarray = yardl.None; + self.expected_nested_subarray = yardl.None; + self.expected_dynamic_with_fixed_vector_subarray = yardl.None; + self.expected_generic_subarray = yardl.None; + end + + function expect_write_dynamic_with_fixed_int_subarray_(self, value) + self.expected_dynamic_with_fixed_int_subarray = yardl.Optional(value); + end + + function expect_write_dynamic_with_fixed_float_subarray_(self, value) + self.expected_dynamic_with_fixed_float_subarray = yardl.Optional(value); + end + + function expect_write_known_dim_count_with_fixed_int_subarray_(self, value) + self.expected_known_dim_count_with_fixed_int_subarray = yardl.Optional(value); + end + + function expect_write_known_dim_count_with_fixed_float_subarray_(self, value) + self.expected_known_dim_count_with_fixed_float_subarray = yardl.Optional(value); + end + + function expect_write_fixed_with_fixed_int_subarray_(self, value) + self.expected_fixed_with_fixed_int_subarray = yardl.Optional(value); + end + + function expect_write_fixed_with_fixed_float_subarray_(self, value) + self.expected_fixed_with_fixed_float_subarray = yardl.Optional(value); + end + + function expect_write_nested_subarray_(self, value) + self.expected_nested_subarray = yardl.Optional(value); + end + + function expect_write_dynamic_with_fixed_vector_subarray_(self, value) + self.expected_dynamic_with_fixed_vector_subarray = yardl.Optional(value); + end + + function expect_write_generic_subarray_(self, value) + self.expected_generic_subarray = yardl.Optional(value); + end + + function verify(self) + self.testCase_.verifyEqual(self.expected_dynamic_with_fixed_int_subarray, yardl.None, "Expected call to write_dynamic_with_fixed_int_subarray_ was not received"); + self.testCase_.verifyEqual(self.expected_dynamic_with_fixed_float_subarray, yardl.None, "Expected call to write_dynamic_with_fixed_float_subarray_ was not received"); + self.testCase_.verifyEqual(self.expected_known_dim_count_with_fixed_int_subarray, yardl.None, "Expected call to write_known_dim_count_with_fixed_int_subarray_ was not received"); + self.testCase_.verifyEqual(self.expected_known_dim_count_with_fixed_float_subarray, yardl.None, "Expected call to write_known_dim_count_with_fixed_float_subarray_ was not received"); + self.testCase_.verifyEqual(self.expected_fixed_with_fixed_int_subarray, yardl.None, "Expected call to write_fixed_with_fixed_int_subarray_ was not received"); + self.testCase_.verifyEqual(self.expected_fixed_with_fixed_float_subarray, yardl.None, "Expected call to write_fixed_with_fixed_float_subarray_ was not received"); + self.testCase_.verifyEqual(self.expected_nested_subarray, yardl.None, "Expected call to write_nested_subarray_ was not received"); + self.testCase_.verifyEqual(self.expected_dynamic_with_fixed_vector_subarray, yardl.None, "Expected call to write_dynamic_with_fixed_vector_subarray_ was not received"); + self.testCase_.verifyEqual(self.expected_generic_subarray, yardl.None, "Expected call to write_generic_subarray_ was not received"); + end + end + + methods (Access=protected) + function write_dynamic_with_fixed_int_subarray_(self, value) + self.testCase_.verifyTrue(self.expected_dynamic_with_fixed_int_subarray.has_value(), "Unexpected call to write_dynamic_with_fixed_int_subarray_"); + self.testCase_.verifyEqual(value, self.expected_dynamic_with_fixed_int_subarray.value, "Unexpected argument value for call to write_dynamic_with_fixed_int_subarray_"); + self.expected_dynamic_with_fixed_int_subarray = yardl.None; + end + + function write_dynamic_with_fixed_float_subarray_(self, value) + self.testCase_.verifyTrue(self.expected_dynamic_with_fixed_float_subarray.has_value(), "Unexpected call to write_dynamic_with_fixed_float_subarray_"); + self.testCase_.verifyEqual(value, self.expected_dynamic_with_fixed_float_subarray.value, "Unexpected argument value for call to write_dynamic_with_fixed_float_subarray_"); + self.expected_dynamic_with_fixed_float_subarray = yardl.None; + end + + function write_known_dim_count_with_fixed_int_subarray_(self, value) + self.testCase_.verifyTrue(self.expected_known_dim_count_with_fixed_int_subarray.has_value(), "Unexpected call to write_known_dim_count_with_fixed_int_subarray_"); + self.testCase_.verifyEqual(value, self.expected_known_dim_count_with_fixed_int_subarray.value, "Unexpected argument value for call to write_known_dim_count_with_fixed_int_subarray_"); + self.expected_known_dim_count_with_fixed_int_subarray = yardl.None; + end + + function write_known_dim_count_with_fixed_float_subarray_(self, value) + self.testCase_.verifyTrue(self.expected_known_dim_count_with_fixed_float_subarray.has_value(), "Unexpected call to write_known_dim_count_with_fixed_float_subarray_"); + self.testCase_.verifyEqual(value, self.expected_known_dim_count_with_fixed_float_subarray.value, "Unexpected argument value for call to write_known_dim_count_with_fixed_float_subarray_"); + self.expected_known_dim_count_with_fixed_float_subarray = yardl.None; + end + + function write_fixed_with_fixed_int_subarray_(self, value) + self.testCase_.verifyTrue(self.expected_fixed_with_fixed_int_subarray.has_value(), "Unexpected call to write_fixed_with_fixed_int_subarray_"); + self.testCase_.verifyEqual(value, self.expected_fixed_with_fixed_int_subarray.value, "Unexpected argument value for call to write_fixed_with_fixed_int_subarray_"); + self.expected_fixed_with_fixed_int_subarray = yardl.None; + end + + function write_fixed_with_fixed_float_subarray_(self, value) + self.testCase_.verifyTrue(self.expected_fixed_with_fixed_float_subarray.has_value(), "Unexpected call to write_fixed_with_fixed_float_subarray_"); + self.testCase_.verifyEqual(value, self.expected_fixed_with_fixed_float_subarray.value, "Unexpected argument value for call to write_fixed_with_fixed_float_subarray_"); + self.expected_fixed_with_fixed_float_subarray = yardl.None; + end + + function write_nested_subarray_(self, value) + self.testCase_.verifyTrue(self.expected_nested_subarray.has_value(), "Unexpected call to write_nested_subarray_"); + self.testCase_.verifyEqual(value, self.expected_nested_subarray.value, "Unexpected argument value for call to write_nested_subarray_"); + self.expected_nested_subarray = yardl.None; + end + + function write_dynamic_with_fixed_vector_subarray_(self, value) + self.testCase_.verifyTrue(self.expected_dynamic_with_fixed_vector_subarray.has_value(), "Unexpected call to write_dynamic_with_fixed_vector_subarray_"); + self.testCase_.verifyEqual(value, self.expected_dynamic_with_fixed_vector_subarray.value, "Unexpected argument value for call to write_dynamic_with_fixed_vector_subarray_"); + self.expected_dynamic_with_fixed_vector_subarray = yardl.None; + end + + function write_generic_subarray_(self, value) + self.testCase_.verifyTrue(self.expected_generic_subarray.has_value(), "Unexpected call to write_generic_subarray_"); + self.testCase_.verifyEqual(value, self.expected_generic_subarray.value, "Unexpected argument value for call to write_generic_subarray_"); + self.expected_generic_subarray = yardl.None; + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockUnionsWriter.m b/matlab/generated/+test_model/+testing/MockUnionsWriter.m new file mode 100644 index 00000000..0914a301 --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockUnionsWriter.m @@ -0,0 +1,75 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockUnionsWriter < matlab.mixin.Copyable & test_model.UnionsWriterBase + properties + testCase_ + expected_int_or_simple_record + expected_int_or_record_with_vlens + expected_monosotate_or_int_or_simple_record + expected_record_with_unions + end + + methods + function self = MockUnionsWriter(testCase) + self.testCase_ = testCase; + self.expected_int_or_simple_record = yardl.None; + self.expected_int_or_record_with_vlens = yardl.None; + self.expected_monosotate_or_int_or_simple_record = yardl.None; + self.expected_record_with_unions = yardl.None; + end + + function expect_write_int_or_simple_record_(self, value) + self.expected_int_or_simple_record = yardl.Optional(value); + end + + function expect_write_int_or_record_with_vlens_(self, value) + self.expected_int_or_record_with_vlens = yardl.Optional(value); + end + + function expect_write_monosotate_or_int_or_simple_record_(self, value) + self.expected_monosotate_or_int_or_simple_record = yardl.Optional(value); + end + + function expect_write_record_with_unions_(self, value) + self.expected_record_with_unions = yardl.Optional(value); + end + + function verify(self) + self.testCase_.verifyEqual(self.expected_int_or_simple_record, yardl.None, "Expected call to write_int_or_simple_record_ was not received"); + self.testCase_.verifyEqual(self.expected_int_or_record_with_vlens, yardl.None, "Expected call to write_int_or_record_with_vlens_ was not received"); + self.testCase_.verifyEqual(self.expected_monosotate_or_int_or_simple_record, yardl.None, "Expected call to write_monosotate_or_int_or_simple_record_ was not received"); + self.testCase_.verifyEqual(self.expected_record_with_unions, yardl.None, "Expected call to write_record_with_unions_ was not received"); + end + end + + methods (Access=protected) + function write_int_or_simple_record_(self, value) + self.testCase_.verifyTrue(self.expected_int_or_simple_record.has_value(), "Unexpected call to write_int_or_simple_record_"); + self.testCase_.verifyEqual(value, self.expected_int_or_simple_record.value, "Unexpected argument value for call to write_int_or_simple_record_"); + self.expected_int_or_simple_record = yardl.None; + end + + function write_int_or_record_with_vlens_(self, value) + self.testCase_.verifyTrue(self.expected_int_or_record_with_vlens.has_value(), "Unexpected call to write_int_or_record_with_vlens_"); + self.testCase_.verifyEqual(value, self.expected_int_or_record_with_vlens.value, "Unexpected argument value for call to write_int_or_record_with_vlens_"); + self.expected_int_or_record_with_vlens = yardl.None; + end + + function write_monosotate_or_int_or_simple_record_(self, value) + self.testCase_.verifyTrue(self.expected_monosotate_or_int_or_simple_record.has_value(), "Unexpected call to write_monosotate_or_int_or_simple_record_"); + self.testCase_.verifyEqual(value, self.expected_monosotate_or_int_or_simple_record.value, "Unexpected argument value for call to write_monosotate_or_int_or_simple_record_"); + self.expected_monosotate_or_int_or_simple_record = yardl.None; + end + + function write_record_with_unions_(self, value) + self.testCase_.verifyTrue(self.expected_record_with_unions.has_value(), "Unexpected call to write_record_with_unions_"); + self.testCase_.verifyEqual(value, self.expected_record_with_unions.value, "Unexpected argument value for call to write_record_with_unions_"); + self.expected_record_with_unions = yardl.None; + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/MockVlensWriter.m b/matlab/generated/+test_model/+testing/MockVlensWriter.m new file mode 100644 index 00000000..a7ba6b13 --- /dev/null +++ b/matlab/generated/+test_model/+testing/MockVlensWriter.m @@ -0,0 +1,75 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MockVlensWriter < matlab.mixin.Copyable & test_model.VlensWriterBase + properties + testCase_ + expected_int_vector + expected_complex_vector + expected_record_with_vlens + expected_vlen_of_record_with_vlens + end + + methods + function self = MockVlensWriter(testCase) + self.testCase_ = testCase; + self.expected_int_vector = yardl.None; + self.expected_complex_vector = yardl.None; + self.expected_record_with_vlens = yardl.None; + self.expected_vlen_of_record_with_vlens = yardl.None; + end + + function expect_write_int_vector_(self, value) + self.expected_int_vector = yardl.Optional(value); + end + + function expect_write_complex_vector_(self, value) + self.expected_complex_vector = yardl.Optional(value); + end + + function expect_write_record_with_vlens_(self, value) + self.expected_record_with_vlens = yardl.Optional(value); + end + + function expect_write_vlen_of_record_with_vlens_(self, value) + self.expected_vlen_of_record_with_vlens = yardl.Optional(value); + end + + function verify(self) + self.testCase_.verifyEqual(self.expected_int_vector, yardl.None, "Expected call to write_int_vector_ was not received"); + self.testCase_.verifyEqual(self.expected_complex_vector, yardl.None, "Expected call to write_complex_vector_ was not received"); + self.testCase_.verifyEqual(self.expected_record_with_vlens, yardl.None, "Expected call to write_record_with_vlens_ was not received"); + self.testCase_.verifyEqual(self.expected_vlen_of_record_with_vlens, yardl.None, "Expected call to write_vlen_of_record_with_vlens_ was not received"); + end + end + + methods (Access=protected) + function write_int_vector_(self, value) + self.testCase_.verifyTrue(self.expected_int_vector.has_value(), "Unexpected call to write_int_vector_"); + self.testCase_.verifyEqual(value, self.expected_int_vector.value, "Unexpected argument value for call to write_int_vector_"); + self.expected_int_vector = yardl.None; + end + + function write_complex_vector_(self, value) + self.testCase_.verifyTrue(self.expected_complex_vector.has_value(), "Unexpected call to write_complex_vector_"); + self.testCase_.verifyEqual(value, self.expected_complex_vector.value, "Unexpected argument value for call to write_complex_vector_"); + self.expected_complex_vector = yardl.None; + end + + function write_record_with_vlens_(self, value) + self.testCase_.verifyTrue(self.expected_record_with_vlens.has_value(), "Unexpected call to write_record_with_vlens_"); + self.testCase_.verifyEqual(value, self.expected_record_with_vlens.value, "Unexpected argument value for call to write_record_with_vlens_"); + self.expected_record_with_vlens = yardl.None; + end + + function write_vlen_of_record_with_vlens_(self, value) + self.testCase_.verifyTrue(self.expected_vlen_of_record_with_vlens.has_value(), "Unexpected call to write_vlen_of_record_with_vlens_"); + self.testCase_.verifyEqual(value, self.expected_vlen_of_record_with_vlens.value, "Unexpected argument value for call to write_vlen_of_record_with_vlens_"); + self.expected_vlen_of_record_with_vlens = yardl.None; + end + + function close_(self) + end + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestAdvancedGenericsWriter.m b/matlab/generated/+test_model/+testing/TestAdvancedGenericsWriter.m new file mode 100644 index 00000000..94039cde --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestAdvancedGenericsWriter.m @@ -0,0 +1,81 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestAdvancedGenericsWriter < test_model.AdvancedGenericsWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestAdvancedGenericsWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockAdvancedGenericsWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestAdvancedGenericsWriter' to verify mocks")); + end + end + end + + methods (Access=protected) + function write_float_image_image_(self, value) + self.writer_.write_float_image_image(value); + self.mock_writer_.expect_write_float_image_image_(value); + end + + function write_generic_record_1_(self, value) + self.writer_.write_generic_record_1(value); + self.mock_writer_.expect_write_generic_record_1_(value); + end + + function write_tuple_of_optionals_(self, value) + self.writer_.write_tuple_of_optionals(value); + self.mock_writer_.expect_write_tuple_of_optionals_(value); + end + + function write_tuple_of_optionals_alternate_syntax_(self, value) + self.writer_.write_tuple_of_optionals_alternate_syntax(value); + self.mock_writer_.expect_write_tuple_of_optionals_alternate_syntax_(value); + end + + function write_tuple_of_vectors_(self, value) + self.writer_.write_tuple_of_vectors(value); + self.mock_writer_.expect_write_tuple_of_vectors_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestAliasesWriter.m b/matlab/generated/+test_model/+testing/TestAliasesWriter.m new file mode 100644 index 00000000..b25c0a2f --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestAliasesWriter.m @@ -0,0 +1,111 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestAliasesWriter < test_model.AliasesWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestAliasesWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockAliasesWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestAliasesWriter' to verify mocks")); + end + end + function end_stream_of_aliased_generic_union_2(self) + end_stream_of_aliased_generic_union_2@test_model.AliasesWriterBase(self); + self.writer_.end_stream_of_aliased_generic_union_2(); + end + + end + + methods (Access=protected) + function write_aliased_string_(self, value) + self.writer_.write_aliased_string(value); + self.mock_writer_.expect_write_aliased_string_(value); + end + + function write_aliased_enum_(self, value) + self.writer_.write_aliased_enum(value); + self.mock_writer_.expect_write_aliased_enum_(value); + end + + function write_aliased_open_generic_(self, value) + self.writer_.write_aliased_open_generic(value); + self.mock_writer_.expect_write_aliased_open_generic_(value); + end + + function write_aliased_closed_generic_(self, value) + self.writer_.write_aliased_closed_generic(value); + self.mock_writer_.expect_write_aliased_closed_generic_(value); + end + + function write_aliased_optional_(self, value) + self.writer_.write_aliased_optional(value); + self.mock_writer_.expect_write_aliased_optional_(value); + end + + function write_aliased_generic_optional_(self, value) + self.writer_.write_aliased_generic_optional(value); + self.mock_writer_.expect_write_aliased_generic_optional_(value); + end + + function write_aliased_generic_union_2_(self, value) + self.writer_.write_aliased_generic_union_2(value); + self.mock_writer_.expect_write_aliased_generic_union_2_(value); + end + + function write_aliased_generic_vector_(self, value) + self.writer_.write_aliased_generic_vector(value); + self.mock_writer_.expect_write_aliased_generic_vector_(value); + end + + function write_aliased_generic_fixed_vector_(self, value) + self.writer_.write_aliased_generic_fixed_vector(value); + self.mock_writer_.expect_write_aliased_generic_fixed_vector_(value); + end + + function write_stream_of_aliased_generic_union_2_(self, value) + self.writer_.write_stream_of_aliased_generic_union_2(value); + self.mock_writer_.expect_write_stream_of_aliased_generic_union_2_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestBenchmarkFloat256x256Writer.m b/matlab/generated/+test_model/+testing/TestBenchmarkFloat256x256Writer.m new file mode 100644 index 00000000..b7af276c --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestBenchmarkFloat256x256Writer.m @@ -0,0 +1,66 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestBenchmarkFloat256x256Writer < test_model.BenchmarkFloat256x256WriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestBenchmarkFloat256x256Writer(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockBenchmarkFloat256x256Writer(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestBenchmarkFloat256x256Writer' to verify mocks")); + end + end + function end_float256x256(self) + end_float256x256@test_model.BenchmarkFloat256x256WriterBase(self); + self.writer_.end_float256x256(); + end + + end + + methods (Access=protected) + function write_float256x256_(self, value) + self.writer_.write_float256x256(value); + self.mock_writer_.expect_write_float256x256_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestBenchmarkFloatVlenWriter.m b/matlab/generated/+test_model/+testing/TestBenchmarkFloatVlenWriter.m new file mode 100644 index 00000000..836d7e4b --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestBenchmarkFloatVlenWriter.m @@ -0,0 +1,66 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestBenchmarkFloatVlenWriter < test_model.BenchmarkFloatVlenWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestBenchmarkFloatVlenWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockBenchmarkFloatVlenWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestBenchmarkFloatVlenWriter' to verify mocks")); + end + end + function end_float_array(self) + end_float_array@test_model.BenchmarkFloatVlenWriterBase(self); + self.writer_.end_float_array(); + end + + end + + methods (Access=protected) + function write_float_array_(self, value) + self.writer_.write_float_array(value); + self.mock_writer_.expect_write_float_array_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestBenchmarkInt256x256Writer.m b/matlab/generated/+test_model/+testing/TestBenchmarkInt256x256Writer.m new file mode 100644 index 00000000..2e733f74 --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestBenchmarkInt256x256Writer.m @@ -0,0 +1,66 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestBenchmarkInt256x256Writer < test_model.BenchmarkInt256x256WriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestBenchmarkInt256x256Writer(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockBenchmarkInt256x256Writer(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestBenchmarkInt256x256Writer' to verify mocks")); + end + end + function end_int256x256(self) + end_int256x256@test_model.BenchmarkInt256x256WriterBase(self); + self.writer_.end_int256x256(); + end + + end + + methods (Access=protected) + function write_int256x256_(self, value) + self.writer_.write_int256x256(value); + self.mock_writer_.expect_write_int256x256_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestBenchmarkSimpleMrdWriter.m b/matlab/generated/+test_model/+testing/TestBenchmarkSimpleMrdWriter.m new file mode 100644 index 00000000..f55d5b49 --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestBenchmarkSimpleMrdWriter.m @@ -0,0 +1,66 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestBenchmarkSimpleMrdWriter < test_model.BenchmarkSimpleMrdWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestBenchmarkSimpleMrdWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockBenchmarkSimpleMrdWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestBenchmarkSimpleMrdWriter' to verify mocks")); + end + end + function end_data(self) + end_data@test_model.BenchmarkSimpleMrdWriterBase(self); + self.writer_.end_data(); + end + + end + + methods (Access=protected) + function write_data_(self, value) + self.writer_.write_data(value); + self.mock_writer_.expect_write_data_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestBenchmarkSmallRecordWithOptionalsWriter.m b/matlab/generated/+test_model/+testing/TestBenchmarkSmallRecordWithOptionalsWriter.m new file mode 100644 index 00000000..bfee9adc --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestBenchmarkSmallRecordWithOptionalsWriter.m @@ -0,0 +1,66 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestBenchmarkSmallRecordWithOptionalsWriter < test_model.BenchmarkSmallRecordWithOptionalsWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestBenchmarkSmallRecordWithOptionalsWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockBenchmarkSmallRecordWithOptionalsWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestBenchmarkSmallRecordWithOptionalsWriter' to verify mocks")); + end + end + function end_small_record(self) + end_small_record@test_model.BenchmarkSmallRecordWithOptionalsWriterBase(self); + self.writer_.end_small_record(); + end + + end + + methods (Access=protected) + function write_small_record_(self, value) + self.writer_.write_small_record(value); + self.mock_writer_.expect_write_small_record_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestBenchmarkSmallRecordWriter.m b/matlab/generated/+test_model/+testing/TestBenchmarkSmallRecordWriter.m new file mode 100644 index 00000000..94695116 --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestBenchmarkSmallRecordWriter.m @@ -0,0 +1,66 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestBenchmarkSmallRecordWriter < test_model.BenchmarkSmallRecordWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestBenchmarkSmallRecordWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockBenchmarkSmallRecordWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestBenchmarkSmallRecordWriter' to verify mocks")); + end + end + function end_small_record(self) + end_small_record@test_model.BenchmarkSmallRecordWriterBase(self); + self.writer_.end_small_record(); + end + + end + + methods (Access=protected) + function write_small_record_(self, value) + self.writer_.write_small_record(value); + self.mock_writer_.expect_write_small_record_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestDynamicNDArraysWriter.m b/matlab/generated/+test_model/+testing/TestDynamicNDArraysWriter.m new file mode 100644 index 00000000..95924669 --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestDynamicNDArraysWriter.m @@ -0,0 +1,76 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestDynamicNDArraysWriter < test_model.DynamicNDArraysWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestDynamicNDArraysWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockDynamicNDArraysWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestDynamicNDArraysWriter' to verify mocks")); + end + end + end + + methods (Access=protected) + function write_ints_(self, value) + self.writer_.write_ints(value); + self.mock_writer_.expect_write_ints_(value); + end + + function write_simple_record_array_(self, value) + self.writer_.write_simple_record_array(value); + self.mock_writer_.expect_write_simple_record_array_(value); + end + + function write_record_with_vlens_array_(self, value) + self.writer_.write_record_with_vlens_array(value); + self.mock_writer_.expect_write_record_with_vlens_array_(value); + end + + function write_record_with_dynamic_nd_arrays_(self, value) + self.writer_.write_record_with_dynamic_nd_arrays(value); + self.mock_writer_.expect_write_record_with_dynamic_nd_arrays_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestEnumsWriter.m b/matlab/generated/+test_model/+testing/TestEnumsWriter.m new file mode 100644 index 00000000..883bdbae --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestEnumsWriter.m @@ -0,0 +1,71 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestEnumsWriter < test_model.EnumsWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestEnumsWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockEnumsWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestEnumsWriter' to verify mocks")); + end + end + end + + methods (Access=protected) + function write_single_(self, value) + self.writer_.write_single(value); + self.mock_writer_.expect_write_single_(value); + end + + function write_vec_(self, value) + self.writer_.write_vec(value); + self.mock_writer_.expect_write_vec_(value); + end + + function write_size_(self, value) + self.writer_.write_size(value); + self.mock_writer_.expect_write_size_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestFixedArraysWriter.m b/matlab/generated/+test_model/+testing/TestFixedArraysWriter.m new file mode 100644 index 00000000..72597831 --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestFixedArraysWriter.m @@ -0,0 +1,81 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestFixedArraysWriter < test_model.FixedArraysWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestFixedArraysWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockFixedArraysWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestFixedArraysWriter' to verify mocks")); + end + end + end + + methods (Access=protected) + function write_ints_(self, value) + self.writer_.write_ints(value); + self.mock_writer_.expect_write_ints_(value); + end + + function write_fixed_simple_record_array_(self, value) + self.writer_.write_fixed_simple_record_array(value); + self.mock_writer_.expect_write_fixed_simple_record_array_(value); + end + + function write_fixed_record_with_vlens_array_(self, value) + self.writer_.write_fixed_record_with_vlens_array(value); + self.mock_writer_.expect_write_fixed_record_with_vlens_array_(value); + end + + function write_record_with_fixed_arrays_(self, value) + self.writer_.write_record_with_fixed_arrays(value); + self.mock_writer_.expect_write_record_with_fixed_arrays_(value); + end + + function write_named_array_(self, value) + self.writer_.write_named_array(value); + self.mock_writer_.expect_write_named_array_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestFixedVectorsWriter.m b/matlab/generated/+test_model/+testing/TestFixedVectorsWriter.m new file mode 100644 index 00000000..dda1595a --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestFixedVectorsWriter.m @@ -0,0 +1,76 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestFixedVectorsWriter < test_model.FixedVectorsWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestFixedVectorsWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockFixedVectorsWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestFixedVectorsWriter' to verify mocks")); + end + end + end + + methods (Access=protected) + function write_fixed_int_vector_(self, value) + self.writer_.write_fixed_int_vector(value); + self.mock_writer_.expect_write_fixed_int_vector_(value); + end + + function write_fixed_simple_record_vector_(self, value) + self.writer_.write_fixed_simple_record_vector(value); + self.mock_writer_.expect_write_fixed_simple_record_vector_(value); + end + + function write_fixed_record_with_vlens_vector_(self, value) + self.writer_.write_fixed_record_with_vlens_vector(value); + self.mock_writer_.expect_write_fixed_record_with_vlens_vector_(value); + end + + function write_record_with_fixed_vectors_(self, value) + self.writer_.write_record_with_fixed_vectors(value); + self.mock_writer_.expect_write_record_with_fixed_vectors_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestFlagsWriter.m b/matlab/generated/+test_model/+testing/TestFlagsWriter.m new file mode 100644 index 00000000..30ccd756 --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestFlagsWriter.m @@ -0,0 +1,76 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestFlagsWriter < test_model.FlagsWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestFlagsWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockFlagsWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestFlagsWriter' to verify mocks")); + end + end + function end_days(self) + end_days@test_model.FlagsWriterBase(self); + self.writer_.end_days(); + end + + function end_formats(self) + end_formats@test_model.FlagsWriterBase(self); + self.writer_.end_formats(); + end + + end + + methods (Access=protected) + function write_days_(self, value) + self.writer_.write_days(value); + self.mock_writer_.expect_write_days_(value); + end + + function write_formats_(self, value) + self.writer_.write_formats(value); + self.mock_writer_.expect_write_formats_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestMapsWriter.m b/matlab/generated/+test_model/+testing/TestMapsWriter.m new file mode 100644 index 00000000..6eb76054 --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestMapsWriter.m @@ -0,0 +1,76 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestMapsWriter < test_model.MapsWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestMapsWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockMapsWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestMapsWriter' to verify mocks")); + end + end + end + + methods (Access=protected) + function write_string_to_int_(self, value) + self.writer_.write_string_to_int(value); + self.mock_writer_.expect_write_string_to_int_(value); + end + + function write_int_to_string_(self, value) + self.writer_.write_int_to_string(value); + self.mock_writer_.expect_write_int_to_string_(value); + end + + function write_string_to_union_(self, value) + self.writer_.write_string_to_union(value); + self.mock_writer_.expect_write_string_to_union_(value); + end + + function write_aliased_generic_(self, value) + self.writer_.write_aliased_generic(value); + self.mock_writer_.expect_write_aliased_generic_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestMultiDArraysWriter.m b/matlab/generated/+test_model/+testing/TestMultiDArraysWriter.m new file mode 100644 index 00000000..7b1ada06 --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestMultiDArraysWriter.m @@ -0,0 +1,76 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestMultiDArraysWriter < test_model.MultiDArraysWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestMultiDArraysWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockMultiDArraysWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestMultiDArraysWriter' to verify mocks")); + end + end + function end_images(self) + end_images@test_model.MultiDArraysWriterBase(self); + self.writer_.end_images(); + end + + function end_frames(self) + end_frames@test_model.MultiDArraysWriterBase(self); + self.writer_.end_frames(); + end + + end + + methods (Access=protected) + function write_images_(self, value) + self.writer_.write_images(value); + self.mock_writer_.expect_write_images_(value); + end + + function write_frames_(self, value) + self.writer_.write_frames(value); + self.mock_writer_.expect_write_frames_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestNDArraysSingleDimensionWriter.m b/matlab/generated/+test_model/+testing/TestNDArraysSingleDimensionWriter.m new file mode 100644 index 00000000..75ddaafe --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestNDArraysSingleDimensionWriter.m @@ -0,0 +1,76 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestNDArraysSingleDimensionWriter < test_model.NDArraysSingleDimensionWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestNDArraysSingleDimensionWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockNDArraysSingleDimensionWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestNDArraysSingleDimensionWriter' to verify mocks")); + end + end + end + + methods (Access=protected) + function write_ints_(self, value) + self.writer_.write_ints(value); + self.mock_writer_.expect_write_ints_(value); + end + + function write_simple_record_array_(self, value) + self.writer_.write_simple_record_array(value); + self.mock_writer_.expect_write_simple_record_array_(value); + end + + function write_record_with_vlens_array_(self, value) + self.writer_.write_record_with_vlens_array(value); + self.mock_writer_.expect_write_record_with_vlens_array_(value); + end + + function write_record_with_nd_arrays_(self, value) + self.writer_.write_record_with_nd_arrays(value); + self.mock_writer_.expect_write_record_with_nd_arrays_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestNDArraysWriter.m b/matlab/generated/+test_model/+testing/TestNDArraysWriter.m new file mode 100644 index 00000000..2e24fd6d --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestNDArraysWriter.m @@ -0,0 +1,81 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestNDArraysWriter < test_model.NDArraysWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestNDArraysWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockNDArraysWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestNDArraysWriter' to verify mocks")); + end + end + end + + methods (Access=protected) + function write_ints_(self, value) + self.writer_.write_ints(value); + self.mock_writer_.expect_write_ints_(value); + end + + function write_simple_record_array_(self, value) + self.writer_.write_simple_record_array(value); + self.mock_writer_.expect_write_simple_record_array_(value); + end + + function write_record_with_vlens_array_(self, value) + self.writer_.write_record_with_vlens_array(value); + self.mock_writer_.expect_write_record_with_vlens_array_(value); + end + + function write_record_with_nd_arrays_(self, value) + self.writer_.write_record_with_nd_arrays(value); + self.mock_writer_.expect_write_record_with_nd_arrays_(value); + end + + function write_named_array_(self, value) + self.writer_.write_named_array(value); + self.mock_writer_.expect_write_named_array_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestNestedRecordsWriter.m b/matlab/generated/+test_model/+testing/TestNestedRecordsWriter.m new file mode 100644 index 00000000..93ca596e --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestNestedRecordsWriter.m @@ -0,0 +1,61 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestNestedRecordsWriter < test_model.NestedRecordsWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestNestedRecordsWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockNestedRecordsWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestNestedRecordsWriter' to verify mocks")); + end + end + end + + methods (Access=protected) + function write_tuple_with_records_(self, value) + self.writer_.write_tuple_with_records(value); + self.mock_writer_.expect_write_tuple_with_records_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestOptionalVectorsWriter.m b/matlab/generated/+test_model/+testing/TestOptionalVectorsWriter.m new file mode 100644 index 00000000..2eefe3a6 --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestOptionalVectorsWriter.m @@ -0,0 +1,61 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestOptionalVectorsWriter < test_model.OptionalVectorsWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestOptionalVectorsWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockOptionalVectorsWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestOptionalVectorsWriter' to verify mocks")); + end + end + end + + methods (Access=protected) + function write_record_with_optional_vector_(self, value) + self.writer_.write_record_with_optional_vector(value); + self.mock_writer_.expect_write_record_with_optional_vector_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestProtocolWithComputedFieldsWriter.m b/matlab/generated/+test_model/+testing/TestProtocolWithComputedFieldsWriter.m new file mode 100644 index 00000000..4201ad0c --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestProtocolWithComputedFieldsWriter.m @@ -0,0 +1,61 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestProtocolWithComputedFieldsWriter < test_model.ProtocolWithComputedFieldsWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestProtocolWithComputedFieldsWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockProtocolWithComputedFieldsWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestProtocolWithComputedFieldsWriter' to verify mocks")); + end + end + end + + methods (Access=protected) + function write_record_with_computed_fields_(self, value) + self.writer_.write_record_with_computed_fields(value); + self.mock_writer_.expect_write_record_with_computed_fields_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestProtocolWithKeywordStepsWriter.m b/matlab/generated/+test_model/+testing/TestProtocolWithKeywordStepsWriter.m new file mode 100644 index 00000000..6e6f4117 --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestProtocolWithKeywordStepsWriter.m @@ -0,0 +1,71 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestProtocolWithKeywordStepsWriter < test_model.ProtocolWithKeywordStepsWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestProtocolWithKeywordStepsWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockProtocolWithKeywordStepsWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestProtocolWithKeywordStepsWriter' to verify mocks")); + end + end + function end_int(self) + end_int@test_model.ProtocolWithKeywordStepsWriterBase(self); + self.writer_.end_int(); + end + + end + + methods (Access=protected) + function write_int_(self, value) + self.writer_.write_int(value); + self.mock_writer_.expect_write_int_(value); + end + + function write_float_(self, value) + self.writer_.write_float(value); + self.mock_writer_.expect_write_float_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestScalarOptionalsWriter.m b/matlab/generated/+test_model/+testing/TestScalarOptionalsWriter.m new file mode 100644 index 00000000..c19f6f6d --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestScalarOptionalsWriter.m @@ -0,0 +1,76 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestScalarOptionalsWriter < test_model.ScalarOptionalsWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestScalarOptionalsWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockScalarOptionalsWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestScalarOptionalsWriter' to verify mocks")); + end + end + end + + methods (Access=protected) + function write_optional_int_(self, value) + self.writer_.write_optional_int(value); + self.mock_writer_.expect_write_optional_int_(value); + end + + function write_optional_record_(self, value) + self.writer_.write_optional_record(value); + self.mock_writer_.expect_write_optional_record_(value); + end + + function write_record_with_optional_fields_(self, value) + self.writer_.write_record_with_optional_fields(value); + self.mock_writer_.expect_write_record_with_optional_fields_(value); + end + + function write_optional_record_with_optional_fields_(self, value) + self.writer_.write_optional_record_with_optional_fields(value); + self.mock_writer_.expect_write_optional_record_with_optional_fields_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestScalarsWriter.m b/matlab/generated/+test_model/+testing/TestScalarsWriter.m new file mode 100644 index 00000000..e1e571c6 --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestScalarsWriter.m @@ -0,0 +1,66 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestScalarsWriter < test_model.ScalarsWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestScalarsWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockScalarsWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestScalarsWriter' to verify mocks")); + end + end + end + + methods (Access=protected) + function write_int32_(self, value) + self.writer_.write_int32(value); + self.mock_writer_.expect_write_int32_(value); + end + + function write_record_(self, value) + self.writer_.write_record(value); + self.mock_writer_.expect_write_record_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestSimpleGenericsWriter.m b/matlab/generated/+test_model/+testing/TestSimpleGenericsWriter.m new file mode 100644 index 00000000..73d19bc2 --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestSimpleGenericsWriter.m @@ -0,0 +1,106 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestSimpleGenericsWriter < test_model.SimpleGenericsWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestSimpleGenericsWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockSimpleGenericsWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestSimpleGenericsWriter' to verify mocks")); + end + end + function end_stream_of_type_variants(self) + end_stream_of_type_variants@test_model.SimpleGenericsWriterBase(self); + self.writer_.end_stream_of_type_variants(); + end + + end + + methods (Access=protected) + function write_float_image_(self, value) + self.writer_.write_float_image(value); + self.mock_writer_.expect_write_float_image_(value); + end + + function write_int_image_(self, value) + self.writer_.write_int_image(value); + self.mock_writer_.expect_write_int_image_(value); + end + + function write_int_image_alternate_syntax_(self, value) + self.writer_.write_int_image_alternate_syntax(value); + self.mock_writer_.expect_write_int_image_alternate_syntax_(value); + end + + function write_string_image_(self, value) + self.writer_.write_string_image(value); + self.mock_writer_.expect_write_string_image_(value); + end + + function write_int_float_tuple_(self, value) + self.writer_.write_int_float_tuple(value); + self.mock_writer_.expect_write_int_float_tuple_(value); + end + + function write_float_float_tuple_(self, value) + self.writer_.write_float_float_tuple(value); + self.mock_writer_.expect_write_float_float_tuple_(value); + end + + function write_int_float_tuple_alternate_syntax_(self, value) + self.writer_.write_int_float_tuple_alternate_syntax(value); + self.mock_writer_.expect_write_int_float_tuple_alternate_syntax_(value); + end + + function write_int_string_tuple_(self, value) + self.writer_.write_int_string_tuple(value); + self.mock_writer_.expect_write_int_string_tuple_(value); + end + + function write_stream_of_type_variants_(self, value) + self.writer_.write_stream_of_type_variants(value); + self.mock_writer_.expect_write_stream_of_type_variants_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestStateTestWriter.m b/matlab/generated/+test_model/+testing/TestStateTestWriter.m new file mode 100644 index 00000000..38e6dbe0 --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestStateTestWriter.m @@ -0,0 +1,76 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestStateTestWriter < test_model.StateTestWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestStateTestWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockStateTestWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestStateTestWriter' to verify mocks")); + end + end + function end_a_stream(self) + end_a_stream@test_model.StateTestWriterBase(self); + self.writer_.end_a_stream(); + end + + end + + methods (Access=protected) + function write_an_int_(self, value) + self.writer_.write_an_int(value); + self.mock_writer_.expect_write_an_int_(value); + end + + function write_a_stream_(self, value) + self.writer_.write_a_stream(value); + self.mock_writer_.expect_write_a_stream_(value); + end + + function write_another_int_(self, value) + self.writer_.write_another_int(value); + self.mock_writer_.expect_write_another_int_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestStreamsOfAliasedUnionsWriter.m b/matlab/generated/+test_model/+testing/TestStreamsOfAliasedUnionsWriter.m new file mode 100644 index 00000000..a4a599c0 --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestStreamsOfAliasedUnionsWriter.m @@ -0,0 +1,76 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestStreamsOfAliasedUnionsWriter < test_model.StreamsOfAliasedUnionsWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestStreamsOfAliasedUnionsWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockStreamsOfAliasedUnionsWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestStreamsOfAliasedUnionsWriter' to verify mocks")); + end + end + function end_int_or_simple_record(self) + end_int_or_simple_record@test_model.StreamsOfAliasedUnionsWriterBase(self); + self.writer_.end_int_or_simple_record(); + end + + function end_nullable_int_or_simple_record(self) + end_nullable_int_or_simple_record@test_model.StreamsOfAliasedUnionsWriterBase(self); + self.writer_.end_nullable_int_or_simple_record(); + end + + end + + methods (Access=protected) + function write_int_or_simple_record_(self, value) + self.writer_.write_int_or_simple_record(value); + self.mock_writer_.expect_write_int_or_simple_record_(value); + end + + function write_nullable_int_or_simple_record_(self, value) + self.writer_.write_nullable_int_or_simple_record(value); + self.mock_writer_.expect_write_nullable_int_or_simple_record_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestStreamsOfUnionsWriter.m b/matlab/generated/+test_model/+testing/TestStreamsOfUnionsWriter.m new file mode 100644 index 00000000..067e8bcf --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestStreamsOfUnionsWriter.m @@ -0,0 +1,76 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestStreamsOfUnionsWriter < test_model.StreamsOfUnionsWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestStreamsOfUnionsWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockStreamsOfUnionsWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestStreamsOfUnionsWriter' to verify mocks")); + end + end + function end_int_or_simple_record(self) + end_int_or_simple_record@test_model.StreamsOfUnionsWriterBase(self); + self.writer_.end_int_or_simple_record(); + end + + function end_nullable_int_or_simple_record(self) + end_nullable_int_or_simple_record@test_model.StreamsOfUnionsWriterBase(self); + self.writer_.end_nullable_int_or_simple_record(); + end + + end + + methods (Access=protected) + function write_int_or_simple_record_(self, value) + self.writer_.write_int_or_simple_record(value); + self.mock_writer_.expect_write_int_or_simple_record_(value); + end + + function write_nullable_int_or_simple_record_(self, value) + self.writer_.write_nullable_int_or_simple_record(value); + self.mock_writer_.expect_write_nullable_int_or_simple_record_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestStreamsWriter.m b/matlab/generated/+test_model/+testing/TestStreamsWriter.m new file mode 100644 index 00000000..29cbc5bd --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestStreamsWriter.m @@ -0,0 +1,96 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestStreamsWriter < test_model.StreamsWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestStreamsWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockStreamsWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestStreamsWriter' to verify mocks")); + end + end + function end_int_data(self) + end_int_data@test_model.StreamsWriterBase(self); + self.writer_.end_int_data(); + end + + function end_optional_int_data(self) + end_optional_int_data@test_model.StreamsWriterBase(self); + self.writer_.end_optional_int_data(); + end + + function end_record_with_optional_vector_data(self) + end_record_with_optional_vector_data@test_model.StreamsWriterBase(self); + self.writer_.end_record_with_optional_vector_data(); + end + + function end_fixed_vector(self) + end_fixed_vector@test_model.StreamsWriterBase(self); + self.writer_.end_fixed_vector(); + end + + end + + methods (Access=protected) + function write_int_data_(self, value) + self.writer_.write_int_data(value); + self.mock_writer_.expect_write_int_data_(value); + end + + function write_optional_int_data_(self, value) + self.writer_.write_optional_int_data(value); + self.mock_writer_.expect_write_optional_int_data_(value); + end + + function write_record_with_optional_vector_data_(self, value) + self.writer_.write_record_with_optional_vector_data(value); + self.mock_writer_.expect_write_record_with_optional_vector_data_(value); + end + + function write_fixed_vector_(self, value) + self.writer_.write_fixed_vector(value); + self.mock_writer_.expect_write_fixed_vector_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestStringsWriter.m b/matlab/generated/+test_model/+testing/TestStringsWriter.m new file mode 100644 index 00000000..9b7e8b01 --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestStringsWriter.m @@ -0,0 +1,66 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestStringsWriter < test_model.StringsWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestStringsWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockStringsWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestStringsWriter' to verify mocks")); + end + end + end + + methods (Access=protected) + function write_single_string_(self, value) + self.writer_.write_single_string(value); + self.mock_writer_.expect_write_single_string_(value); + end + + function write_rec_with_string_(self, value) + self.writer_.write_rec_with_string(value); + self.mock_writer_.expect_write_rec_with_string_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestSubarraysInRecordsWriter.m b/matlab/generated/+test_model/+testing/TestSubarraysInRecordsWriter.m new file mode 100644 index 00000000..d49337e4 --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestSubarraysInRecordsWriter.m @@ -0,0 +1,66 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestSubarraysInRecordsWriter < test_model.SubarraysInRecordsWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestSubarraysInRecordsWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockSubarraysInRecordsWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestSubarraysInRecordsWriter' to verify mocks")); + end + end + end + + methods (Access=protected) + function write_with_fixed_subarrays_(self, value) + self.writer_.write_with_fixed_subarrays(value); + self.mock_writer_.expect_write_with_fixed_subarrays_(value); + end + + function write_with_vlen_subarrays_(self, value) + self.writer_.write_with_vlen_subarrays(value); + self.mock_writer_.expect_write_with_vlen_subarrays_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestSubarraysWriter.m b/matlab/generated/+test_model/+testing/TestSubarraysWriter.m new file mode 100644 index 00000000..1774d956 --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestSubarraysWriter.m @@ -0,0 +1,101 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestSubarraysWriter < test_model.SubarraysWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestSubarraysWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockSubarraysWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestSubarraysWriter' to verify mocks")); + end + end + end + + methods (Access=protected) + function write_dynamic_with_fixed_int_subarray_(self, value) + self.writer_.write_dynamic_with_fixed_int_subarray(value); + self.mock_writer_.expect_write_dynamic_with_fixed_int_subarray_(value); + end + + function write_dynamic_with_fixed_float_subarray_(self, value) + self.writer_.write_dynamic_with_fixed_float_subarray(value); + self.mock_writer_.expect_write_dynamic_with_fixed_float_subarray_(value); + end + + function write_known_dim_count_with_fixed_int_subarray_(self, value) + self.writer_.write_known_dim_count_with_fixed_int_subarray(value); + self.mock_writer_.expect_write_known_dim_count_with_fixed_int_subarray_(value); + end + + function write_known_dim_count_with_fixed_float_subarray_(self, value) + self.writer_.write_known_dim_count_with_fixed_float_subarray(value); + self.mock_writer_.expect_write_known_dim_count_with_fixed_float_subarray_(value); + end + + function write_fixed_with_fixed_int_subarray_(self, value) + self.writer_.write_fixed_with_fixed_int_subarray(value); + self.mock_writer_.expect_write_fixed_with_fixed_int_subarray_(value); + end + + function write_fixed_with_fixed_float_subarray_(self, value) + self.writer_.write_fixed_with_fixed_float_subarray(value); + self.mock_writer_.expect_write_fixed_with_fixed_float_subarray_(value); + end + + function write_nested_subarray_(self, value) + self.writer_.write_nested_subarray(value); + self.mock_writer_.expect_write_nested_subarray_(value); + end + + function write_dynamic_with_fixed_vector_subarray_(self, value) + self.writer_.write_dynamic_with_fixed_vector_subarray(value); + self.mock_writer_.expect_write_dynamic_with_fixed_vector_subarray_(value); + end + + function write_generic_subarray_(self, value) + self.writer_.write_generic_subarray(value); + self.mock_writer_.expect_write_generic_subarray_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestUnionsWriter.m b/matlab/generated/+test_model/+testing/TestUnionsWriter.m new file mode 100644 index 00000000..e4018521 --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestUnionsWriter.m @@ -0,0 +1,76 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestUnionsWriter < test_model.UnionsWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestUnionsWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockUnionsWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestUnionsWriter' to verify mocks")); + end + end + end + + methods (Access=protected) + function write_int_or_simple_record_(self, value) + self.writer_.write_int_or_simple_record(value); + self.mock_writer_.expect_write_int_or_simple_record_(value); + end + + function write_int_or_record_with_vlens_(self, value) + self.writer_.write_int_or_record_with_vlens(value); + self.mock_writer_.expect_write_int_or_record_with_vlens_(value); + end + + function write_monosotate_or_int_or_simple_record_(self, value) + self.writer_.write_monosotate_or_int_or_simple_record(value); + self.mock_writer_.expect_write_monosotate_or_int_or_simple_record_(value); + end + + function write_record_with_unions_(self, value) + self.writer_.write_record_with_unions(value); + self.mock_writer_.expect_write_record_with_unions_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/+testing/TestVlensWriter.m b/matlab/generated/+test_model/+testing/TestVlensWriter.m new file mode 100644 index 00000000..3f27ee3e --- /dev/null +++ b/matlab/generated/+test_model/+testing/TestVlensWriter.m @@ -0,0 +1,76 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TestVlensWriter < test_model.VlensWriterBase + properties (Access = private) + writer_ + create_reader_ + mock_writer_ + close_called_ + filename_ + format_ + end + + methods + function self = TestVlensWriter(testCase, format, create_writer, create_reader) + self.filename_ = tempname(); + self.format_ = format; + self.writer_ = create_writer(self.filename_); + self.create_reader_ = create_reader; + self.mock_writer_ = test_model.testing.MockVlensWriter(testCase); + self.close_called_ = false; + end + + function delete(self) + delete(self.filename_); + if ~self.close_called_ + % ADD_FAILURE() << ...; + throw(yardl.RuntimeError("Close() must be called on 'TestVlensWriter' to verify mocks")); + end + end + end + + methods (Access=protected) + function write_int_vector_(self, value) + self.writer_.write_int_vector(value); + self.mock_writer_.expect_write_int_vector_(value); + end + + function write_complex_vector_(self, value) + self.writer_.write_complex_vector(value); + self.mock_writer_.expect_write_complex_vector_(value); + end + + function write_record_with_vlens_(self, value) + self.writer_.write_record_with_vlens(value); + self.mock_writer_.expect_write_record_with_vlens_(value); + end + + function write_vlen_of_record_with_vlens_(self, value) + self.writer_.write_vlen_of_record_with_vlens(value); + self.mock_writer_.expect_write_vlen_of_record_with_vlens_(value); + end + + function close_(self) + self.close_called_ = true; + self.writer_.close(); + mock_copy = copy(self.mock_writer_); + + reader = self.create_reader_(self.filename_); + reader.copy_to(self.mock_writer_); + reader.close(); + self.mock_writer_.verify(); + self.mock_writer_.close(); + + translated = invoke_translator(self.filename_, self.format_, self.format_); + reader = self.create_reader_(translated); + reader.copy_to(mock_copy); + reader.close(); + mock_copy.verify(); + mock_copy.close(); + delete(translated); + end + + function end_stream_(self) + end + end +end diff --git a/matlab/generated/+test_model/AcquisitionOrImage.m b/matlab/generated/+test_model/AcquisitionOrImage.m new file mode 100644 index 00000000..25da646e --- /dev/null +++ b/matlab/generated/+test_model/AcquisitionOrImage.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef AcquisitionOrImage < yardl.Union + methods (Static) + function res = Acquisition(value) + res = test_model.AcquisitionOrImage(1, value); + end + + function res = Image(value) + res = test_model.AcquisitionOrImage(2, value); + end + + function z = zeros(varargin) + elem = test_model.AcquisitionOrImage(0, yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function res = isAcquisition(self) + res = self.index == 1; + end + + function res = isImage(self) + res = self.index == 2; + end + + function eq = eq(self, other) + eq = isa(other, "test_model.AcquisitionOrImage") && isequal(self.index, other.index) && isequal(self.value, other.value); + end + + function ne = ne(self, other) + ne = ~self.eq(other); + end + + function t = tag(self) + tags_ = ["Acquisition", "Image"]; + t = tags_(self.index_); + end + end +end diff --git a/matlab/generated/+test_model/AdvancedGenericsReaderBase.m b/matlab/generated/+test_model/AdvancedGenericsReaderBase.m new file mode 100644 index 00000000..d0de2026 --- /dev/null +++ b/matlab/generated/+test_model/AdvancedGenericsReaderBase.m @@ -0,0 +1,119 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef AdvancedGenericsReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = AdvancedGenericsReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 5 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function value = read_float_image_image(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_float_image_image_(); + self.state_ = 1; + end + + % Ordinal 1 + function value = read_generic_record_1(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_generic_record_1_(); + self.state_ = 2; + end + + % Ordinal 2 + function value = read_tuple_of_optionals(self) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + value = self.read_tuple_of_optionals_(); + self.state_ = 3; + end + + % Ordinal 3 + function value = read_tuple_of_optionals_alternate_syntax(self) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + value = self.read_tuple_of_optionals_alternate_syntax_(); + self.state_ = 4; + end + + % Ordinal 4 + function value = read_tuple_of_vectors(self) + if self.state_ ~= 4 + self.raise_unexpected_state_(4); + end + + value = self.read_tuple_of_vectors_(); + self.state_ = 5; + end + + function copy_to(self, writer) + writer.write_float_image_image(self.read_float_image_image()); + writer.write_generic_record_1(self.read_generic_record_1()); + writer.write_tuple_of_optionals(self.read_tuple_of_optionals()); + writer.write_tuple_of_optionals_alternate_syntax(self.read_tuple_of_optionals_alternate_syntax()); + writer.write_tuple_of_vectors(self.read_tuple_of_vectors()); + end + end + + methods (Static) + function res = schema() + res = test_model.AdvancedGenericsWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + read_float_image_image_(self) + read_generic_record_1_(self) + read_tuple_of_optionals_(self) + read_tuple_of_optionals_alternate_syntax_(self) + read_tuple_of_vectors_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_float_image_image"; + elseif state == 1 + name = "read_generic_record_1"; + elseif state == 2 + name = "read_tuple_of_optionals"; + elseif state == 3 + name = "read_tuple_of_optionals_alternate_syntax"; + elseif state == 4 + name = "read_tuple_of_vectors"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/AdvancedGenericsWriterBase.m b/matlab/generated/+test_model/AdvancedGenericsWriterBase.m new file mode 100644 index 00000000..c62c2188 --- /dev/null +++ b/matlab/generated/+test_model/AdvancedGenericsWriterBase.m @@ -0,0 +1,113 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol AdvancedGenerics +classdef (Abstract) AdvancedGenericsWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = AdvancedGenericsWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 5 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_float_image_image(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_float_image_image_(value); + self.state_ = 1; + end + + % Ordinal 1 + function write_generic_record_1(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_generic_record_1_(value); + self.state_ = 2; + end + + % Ordinal 2 + function write_tuple_of_optionals(self, value) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + self.write_tuple_of_optionals_(value); + self.state_ = 3; + end + + % Ordinal 3 + function write_tuple_of_optionals_alternate_syntax(self, value) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + self.write_tuple_of_optionals_alternate_syntax_(value); + self.state_ = 4; + end + + % Ordinal 4 + function write_tuple_of_vectors(self, value) + if self.state_ ~= 4 + self.raise_unexpected_state_(4); + end + + self.write_tuple_of_vectors_(value); + self.state_ = 5; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"AdvancedGenerics","sequence":[{"name":"floatImageImage","type":{"name":"TestModel.Image","typeArguments":[{"name":"TestModel.Image","typeArguments":["float32"]}]}},{"name":"genericRecord1","type":{"name":"TestModel.GenericRecord","typeArguments":["int32","string"]}},{"name":"tupleOfOptionals","type":{"name":"TestModel.MyTuple","typeArguments":[[null,"int32"],[null,"string"]]}},{"name":"tupleOfOptionalsAlternateSyntax","type":{"name":"TestModel.MyTuple","typeArguments":[[null,"int32"],[null,"string"]]}},{"name":"tupleOfVectors","type":{"name":"TestModel.MyTuple","typeArguments":[{"vector":{"items":"int32"}},{"vector":{"items":"float32"}}]}}]},"types":[{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"Tuples.Tuple","typeArguments":["T1","T2"]}},{"name":"Image","typeParameters":["T"],"type":{"array":{"items":"T","dimensions":[{"name":"x"},{"name":"y"}]}}},{"name":"GenericRecord","typeParameters":["T1","T2"],"fields":[{"name":"scalar1","type":"T1"},{"name":"scalar2","type":"T2"},{"name":"vector1","type":{"vector":{"items":"T1"}}},{"name":"image2","type":{"name":"TestModel.Image","typeArguments":["T2"]}}]},{"name":"Image","typeParameters":["T"],"type":{"name":"Image.Image","typeArguments":["T"]}},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"BasicTypes.MyTuple","typeArguments":["T1","T2"]}},{"name":"Tuple","typeParameters":["T1","T2"],"fields":[{"name":"v1","type":"T1"},{"name":"v2","type":"T2"}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_float_image_image_(self, value) + write_generic_record_1_(self, value) + write_tuple_of_optionals_(self, value) + write_tuple_of_optionals_alternate_syntax_(self, value) + write_tuple_of_vectors_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_float_image_image"; + elseif state == 1 + name = "write_generic_record_1"; + elseif state == 2 + name = "write_tuple_of_optionals"; + elseif state == 3 + name = "write_tuple_of_optionals_alternate_syntax"; + elseif state == 4 + name = "write_tuple_of_vectors"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/AliasedClosedGeneric.m b/matlab/generated/+test_model/AliasedClosedGeneric.m new file mode 100644 index 00000000..546b8395 --- /dev/null +++ b/matlab/generated/+test_model/AliasedClosedGeneric.m @@ -0,0 +1,5 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function c = AliasedClosedGeneric(varargin) + c = test_model.AliasedTuple(varargin{:}); +end diff --git a/matlab/generated/+test_model/AliasedEnum.m b/matlab/generated/+test_model/AliasedEnum.m new file mode 100644 index 00000000..08737fc3 --- /dev/null +++ b/matlab/generated/+test_model/AliasedEnum.m @@ -0,0 +1,4 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef AliasedEnum < test_model.Fruits +end diff --git a/matlab/generated/+test_model/AliasedGenericDynamicArray.m b/matlab/generated/+test_model/AliasedGenericDynamicArray.m new file mode 100644 index 00000000..6163aeb5 --- /dev/null +++ b/matlab/generated/+test_model/AliasedGenericDynamicArray.m @@ -0,0 +1,5 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function a = AliasedGenericDynamicArray(array) + a = array; +end diff --git a/matlab/generated/+test_model/AliasedGenericFixedArray.m b/matlab/generated/+test_model/AliasedGenericFixedArray.m new file mode 100644 index 00000000..d5eb14ba --- /dev/null +++ b/matlab/generated/+test_model/AliasedGenericFixedArray.m @@ -0,0 +1,5 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function a = AliasedGenericFixedArray(array) + a = array; +end diff --git a/matlab/generated/+test_model/AliasedGenericFixedVector.m b/matlab/generated/+test_model/AliasedGenericFixedVector.m new file mode 100644 index 00000000..c246fa3e --- /dev/null +++ b/matlab/generated/+test_model/AliasedGenericFixedVector.m @@ -0,0 +1,5 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function a = AliasedGenericFixedVector(array) + a = array; +end diff --git a/matlab/generated/+test_model/AliasedGenericOptional.m b/matlab/generated/+test_model/AliasedGenericOptional.m new file mode 100644 index 00000000..522e4e60 --- /dev/null +++ b/matlab/generated/+test_model/AliasedGenericOptional.m @@ -0,0 +1,5 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function o = AliasedGenericOptional(value) + o = yardl.Optional(value); +end diff --git a/matlab/generated/+test_model/AliasedGenericRank2Array.m b/matlab/generated/+test_model/AliasedGenericRank2Array.m new file mode 100644 index 00000000..ba481775 --- /dev/null +++ b/matlab/generated/+test_model/AliasedGenericRank2Array.m @@ -0,0 +1,5 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function a = AliasedGenericRank2Array(array) + a = array; +end diff --git a/matlab/generated/+test_model/AliasedGenericUnion2.m b/matlab/generated/+test_model/AliasedGenericUnion2.m new file mode 100644 index 00000000..fadecd6c --- /dev/null +++ b/matlab/generated/+test_model/AliasedGenericUnion2.m @@ -0,0 +1,4 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef AliasedGenericUnion2 < basic_types.GenericUnion2 +end diff --git a/matlab/generated/+test_model/AliasedGenericVector.m b/matlab/generated/+test_model/AliasedGenericVector.m new file mode 100644 index 00000000..c6931967 --- /dev/null +++ b/matlab/generated/+test_model/AliasedGenericVector.m @@ -0,0 +1,5 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function a = AliasedGenericVector(array) + a = array; +end diff --git a/matlab/generated/+test_model/AliasedIntOrSimpleRecord.m b/matlab/generated/+test_model/AliasedIntOrSimpleRecord.m new file mode 100644 index 00000000..6bd66c2a --- /dev/null +++ b/matlab/generated/+test_model/AliasedIntOrSimpleRecord.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef AliasedIntOrSimpleRecord < yardl.Union + methods (Static) + function res = Int32(value) + res = test_model.AliasedIntOrSimpleRecord(1, value); + end + + function res = SimpleRecord(value) + res = test_model.AliasedIntOrSimpleRecord(2, value); + end + + function z = zeros(varargin) + elem = test_model.AliasedIntOrSimpleRecord(0, yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function res = isInt32(self) + res = self.index == 1; + end + + function res = isSimpleRecord(self) + res = self.index == 2; + end + + function eq = eq(self, other) + eq = isa(other, "test_model.AliasedIntOrSimpleRecord") && isequal(self.index, other.index) && isequal(self.value, other.value); + end + + function ne = ne(self, other) + ne = ~self.eq(other); + end + + function t = tag(self) + tags_ = ["Int32", "SimpleRecord"]; + t = tags_(self.index_); + end + end +end diff --git a/matlab/generated/+test_model/AliasedMap.m b/matlab/generated/+test_model/AliasedMap.m new file mode 100644 index 00000000..fd5134dd --- /dev/null +++ b/matlab/generated/+test_model/AliasedMap.m @@ -0,0 +1,5 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function m = AliasedMap(varargin) + m = basic_types.AliasedMap(varargin{:}); +end diff --git a/matlab/generated/+test_model/AliasedMultiGenericOptional.m b/matlab/generated/+test_model/AliasedMultiGenericOptional.m new file mode 100644 index 00000000..508d75ae --- /dev/null +++ b/matlab/generated/+test_model/AliasedMultiGenericOptional.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef AliasedMultiGenericOptional < yardl.Union + methods (Static) + function res = T(value) + res = test_model.AliasedMultiGenericOptional(1, value); + end + + function res = U(value) + res = test_model.AliasedMultiGenericOptional(2, value); + end + + function z = zeros(varargin) + elem = test_model.AliasedMultiGenericOptional(0, yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function res = isT(self) + res = self.index == 1; + end + + function res = isU(self) + res = self.index == 2; + end + + function eq = eq(self, other) + eq = isa(other, "test_model.AliasedMultiGenericOptional") && isequal(self.index, other.index) && isequal(self.value, other.value); + end + + function ne = ne(self, other) + ne = ~self.eq(other); + end + + function t = tag(self) + tags_ = ["T", "U"]; + t = tags_(self.index_); + end + end +end diff --git a/matlab/generated/+test_model/AliasedNullableIntSimpleRecord.m b/matlab/generated/+test_model/AliasedNullableIntSimpleRecord.m new file mode 100644 index 00000000..bba1a9e6 --- /dev/null +++ b/matlab/generated/+test_model/AliasedNullableIntSimpleRecord.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef AliasedNullableIntSimpleRecord < yardl.Union + methods (Static) + function res = Int32(value) + res = test_model.AliasedNullableIntSimpleRecord(1, value); + end + + function res = SimpleRecord(value) + res = test_model.AliasedNullableIntSimpleRecord(2, value); + end + + function z = zeros(varargin) + elem = test_model.AliasedNullableIntSimpleRecord(0, yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function res = isInt32(self) + res = self.index == 1; + end + + function res = isSimpleRecord(self) + res = self.index == 2; + end + + function eq = eq(self, other) + eq = isa(other, "test_model.AliasedNullableIntSimpleRecord") && isequal(self.index, other.index) && isequal(self.value, other.value); + end + + function ne = ne(self, other) + ne = ~self.eq(other); + end + + function t = tag(self) + tags_ = ["Int32", "SimpleRecord"]; + t = tags_(self.index_); + end + end +end diff --git a/matlab/generated/+test_model/AliasedOpenGeneric.m b/matlab/generated/+test_model/AliasedOpenGeneric.m new file mode 100644 index 00000000..75685264 --- /dev/null +++ b/matlab/generated/+test_model/AliasedOpenGeneric.m @@ -0,0 +1,5 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function c = AliasedOpenGeneric(varargin) + c = test_model.AliasedTuple(varargin{:}); +end diff --git a/matlab/generated/+test_model/AliasedOptional.m b/matlab/generated/+test_model/AliasedOptional.m new file mode 100644 index 00000000..f80a59db --- /dev/null +++ b/matlab/generated/+test_model/AliasedOptional.m @@ -0,0 +1,8 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function o = AliasedOptional(value) + arguments + value int32 + end + o = yardl.Optional(value); +end diff --git a/matlab/generated/+test_model/AliasedString.m b/matlab/generated/+test_model/AliasedString.m new file mode 100644 index 00000000..34c1c4ab --- /dev/null +++ b/matlab/generated/+test_model/AliasedString.m @@ -0,0 +1,5 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function s = AliasedString(varargin) + s = string(varargin{:}); +end diff --git a/matlab/generated/+test_model/AliasedTuple.m b/matlab/generated/+test_model/AliasedTuple.m new file mode 100644 index 00000000..752b1420 --- /dev/null +++ b/matlab/generated/+test_model/AliasedTuple.m @@ -0,0 +1,5 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function c = AliasedTuple(varargin) + c = test_model.MyTuple(varargin{:}); +end diff --git a/matlab/generated/+test_model/AliasedVectorOfGenericRecords.m b/matlab/generated/+test_model/AliasedVectorOfGenericRecords.m new file mode 100644 index 00000000..fed1676b --- /dev/null +++ b/matlab/generated/+test_model/AliasedVectorOfGenericRecords.m @@ -0,0 +1,5 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function a = AliasedVectorOfGenericRecords(array) + a = array; +end diff --git a/matlab/generated/+test_model/AliasesReaderBase.m b/matlab/generated/+test_model/AliasesReaderBase.m new file mode 100644 index 00000000..20a783ae --- /dev/null +++ b/matlab/generated/+test_model/AliasesReaderBase.m @@ -0,0 +1,204 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef AliasesReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = AliasesReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 10 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function value = read_aliased_string(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_aliased_string_(); + self.state_ = 1; + end + + % Ordinal 1 + function value = read_aliased_enum(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_aliased_enum_(); + self.state_ = 2; + end + + % Ordinal 2 + function value = read_aliased_open_generic(self) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + value = self.read_aliased_open_generic_(); + self.state_ = 3; + end + + % Ordinal 3 + function value = read_aliased_closed_generic(self) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + value = self.read_aliased_closed_generic_(); + self.state_ = 4; + end + + % Ordinal 4 + function value = read_aliased_optional(self) + if self.state_ ~= 4 + self.raise_unexpected_state_(4); + end + + value = self.read_aliased_optional_(); + self.state_ = 5; + end + + % Ordinal 5 + function value = read_aliased_generic_optional(self) + if self.state_ ~= 5 + self.raise_unexpected_state_(5); + end + + value = self.read_aliased_generic_optional_(); + self.state_ = 6; + end + + % Ordinal 6 + function value = read_aliased_generic_union_2(self) + if self.state_ ~= 6 + self.raise_unexpected_state_(6); + end + + value = self.read_aliased_generic_union_2_(); + self.state_ = 7; + end + + % Ordinal 7 + function value = read_aliased_generic_vector(self) + if self.state_ ~= 7 + self.raise_unexpected_state_(7); + end + + value = self.read_aliased_generic_vector_(); + self.state_ = 8; + end + + % Ordinal 8 + function value = read_aliased_generic_fixed_vector(self) + if self.state_ ~= 8 + self.raise_unexpected_state_(8); + end + + value = self.read_aliased_generic_fixed_vector_(); + self.state_ = 9; + end + + % Ordinal 9 + function more = has_stream_of_aliased_generic_union_2(self) + if self.state_ ~= 9 + self.raise_unexpected_state_(9); + end + + more = self.has_stream_of_aliased_generic_union_2_(); + if ~more + self.state_ = 10; + end + end + + function value = read_stream_of_aliased_generic_union_2(self) + if self.state_ ~= 9 + self.raise_unexpected_state_(9); + end + + value = self.read_stream_of_aliased_generic_union_2_(); + end + + function copy_to(self, writer) + writer.write_aliased_string(self.read_aliased_string()); + writer.write_aliased_enum(self.read_aliased_enum()); + writer.write_aliased_open_generic(self.read_aliased_open_generic()); + writer.write_aliased_closed_generic(self.read_aliased_closed_generic()); + writer.write_aliased_optional(self.read_aliased_optional()); + writer.write_aliased_generic_optional(self.read_aliased_generic_optional()); + writer.write_aliased_generic_union_2(self.read_aliased_generic_union_2()); + writer.write_aliased_generic_vector(self.read_aliased_generic_vector()); + writer.write_aliased_generic_fixed_vector(self.read_aliased_generic_fixed_vector()); + while self.has_stream_of_aliased_generic_union_2() + item = self.read_stream_of_aliased_generic_union_2(); + writer.write_stream_of_aliased_generic_union_2({item}); + end + writer.end_stream_of_aliased_generic_union_2(); + end + end + + methods (Static) + function res = schema() + res = test_model.AliasesWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + read_aliased_string_(self) + read_aliased_enum_(self) + read_aliased_open_generic_(self) + read_aliased_closed_generic_(self) + read_aliased_optional_(self) + read_aliased_generic_optional_(self) + read_aliased_generic_union_2_(self) + read_aliased_generic_vector_(self) + read_aliased_generic_fixed_vector_(self) + has_stream_of_aliased_generic_union_2_(self) + read_stream_of_aliased_generic_union_2_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_aliased_string"; + elseif state == 1 + name = "read_aliased_enum"; + elseif state == 2 + name = "read_aliased_open_generic"; + elseif state == 3 + name = "read_aliased_closed_generic"; + elseif state == 4 + name = "read_aliased_optional"; + elseif state == 5 + name = "read_aliased_generic_optional"; + elseif state == 6 + name = "read_aliased_generic_union_2"; + elseif state == 7 + name = "read_aliased_generic_vector"; + elseif state == 8 + name = "read_aliased_generic_fixed_vector"; + elseif state == 9 + name = "read_stream_of_aliased_generic_union_2"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/AliasesWriterBase.m b/matlab/generated/+test_model/AliasesWriterBase.m new file mode 100644 index 00000000..2ac21fc5 --- /dev/null +++ b/matlab/generated/+test_model/AliasesWriterBase.m @@ -0,0 +1,186 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol Aliases +classdef (Abstract) AliasesWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = AliasesWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 10 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_aliased_string(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_aliased_string_(value); + self.state_ = 1; + end + + % Ordinal 1 + function write_aliased_enum(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_aliased_enum_(value); + self.state_ = 2; + end + + % Ordinal 2 + function write_aliased_open_generic(self, value) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + self.write_aliased_open_generic_(value); + self.state_ = 3; + end + + % Ordinal 3 + function write_aliased_closed_generic(self, value) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + self.write_aliased_closed_generic_(value); + self.state_ = 4; + end + + % Ordinal 4 + function write_aliased_optional(self, value) + if self.state_ ~= 4 + self.raise_unexpected_state_(4); + end + + self.write_aliased_optional_(value); + self.state_ = 5; + end + + % Ordinal 5 + function write_aliased_generic_optional(self, value) + if self.state_ ~= 5 + self.raise_unexpected_state_(5); + end + + self.write_aliased_generic_optional_(value); + self.state_ = 6; + end + + % Ordinal 6 + function write_aliased_generic_union_2(self, value) + if self.state_ ~= 6 + self.raise_unexpected_state_(6); + end + + self.write_aliased_generic_union_2_(value); + self.state_ = 7; + end + + % Ordinal 7 + function write_aliased_generic_vector(self, value) + if self.state_ ~= 7 + self.raise_unexpected_state_(7); + end + + self.write_aliased_generic_vector_(value); + self.state_ = 8; + end + + % Ordinal 8 + function write_aliased_generic_fixed_vector(self, value) + if self.state_ ~= 8 + self.raise_unexpected_state_(8); + end + + self.write_aliased_generic_fixed_vector_(value); + self.state_ = 9; + end + + % Ordinal 9 + function write_stream_of_aliased_generic_union_2(self, value) + if self.state_ ~= 9 + self.raise_unexpected_state_(9); + end + + self.write_stream_of_aliased_generic_union_2_(value); + end + + function end_stream_of_aliased_generic_union_2(self) + if self.state_ ~= 9 + self.raise_unexpected_state_(9); + end + + self.end_stream_(); + self.state_ = 10; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"Aliases","sequence":[{"name":"aliasedString","type":"TestModel.AliasedString"},{"name":"aliasedEnum","type":"TestModel.AliasedEnum"},{"name":"aliasedOpenGeneric","type":{"name":"TestModel.AliasedOpenGeneric","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}},{"name":"aliasedClosedGeneric","type":"TestModel.AliasedClosedGeneric"},{"name":"aliasedOptional","type":"TestModel.AliasedOptional"},{"name":"aliasedGenericOptional","type":{"name":"TestModel.AliasedGenericOptional","typeArguments":["float32"]}},{"name":"aliasedGenericUnion2","type":{"name":"TestModel.AliasedGenericUnion2","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}},{"name":"aliasedGenericVector","type":{"name":"TestModel.AliasedGenericVector","typeArguments":["float32"]}},{"name":"aliasedGenericFixedVector","type":{"name":"TestModel.AliasedGenericFixedVector","typeArguments":["float32"]}},{"name":"streamOfAliasedGenericUnion2","type":{"stream":{"items":{"name":"TestModel.AliasedGenericUnion2","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}}}}]},"types":[{"name":"Fruits","values":[{"symbol":"apple","value":0},{"symbol":"banana","value":1},{"symbol":"pear","value":2}]},{"name":"GenericUnion2","typeParameters":["T1","T2"],"type":[{"tag":"T1","type":"T1"},{"tag":"T2","type":"T2"}]},{"name":"GenericVector","typeParameters":["T"],"type":{"vector":{"items":"T"}}},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"Tuples.Tuple","typeArguments":["T1","T2"]}},{"name":"AliasedClosedGeneric","type":{"name":"TestModel.AliasedTuple","typeArguments":["TestModel.AliasedString","TestModel.AliasedEnum"]}},{"name":"AliasedEnum","type":"TestModel.Fruits"},{"name":"AliasedGenericFixedVector","typeParameters":["T"],"type":{"vector":{"items":"T","length":3}}},{"name":"AliasedGenericOptional","typeParameters":["T"],"type":[null,"T"]},{"name":"AliasedGenericUnion2","typeParameters":["T1","T2"],"type":{"name":"BasicTypes.GenericUnion2","typeArguments":["T1","T2"]}},{"name":"AliasedGenericVector","typeParameters":["T"],"type":{"name":"BasicTypes.GenericVector","typeArguments":["T"]}},{"name":"AliasedOpenGeneric","typeParameters":["T1","T2"],"type":{"name":"TestModel.AliasedTuple","typeArguments":["T1","T2"]}},{"name":"AliasedOptional","type":[null,"int32"]},{"name":"AliasedString","type":"string"},{"name":"AliasedTuple","typeParameters":["T1","T2"],"type":{"name":"TestModel.MyTuple","typeArguments":["T1","T2"]}},{"name":"Fruits","type":"BasicTypes.Fruits"},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"BasicTypes.MyTuple","typeArguments":["T1","T2"]}},{"name":"Tuple","typeParameters":["T1","T2"],"fields":[{"name":"v1","type":"T1"},{"name":"v2","type":"T2"}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_aliased_string_(self, value) + write_aliased_enum_(self, value) + write_aliased_open_generic_(self, value) + write_aliased_closed_generic_(self, value) + write_aliased_optional_(self, value) + write_aliased_generic_optional_(self, value) + write_aliased_generic_union_2_(self, value) + write_aliased_generic_vector_(self, value) + write_aliased_generic_fixed_vector_(self, value) + write_stream_of_aliased_generic_union_2_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_aliased_string"; + elseif state == 1 + name = "write_aliased_enum"; + elseif state == 2 + name = "write_aliased_open_generic"; + elseif state == 3 + name = "write_aliased_closed_generic"; + elseif state == 4 + name = "write_aliased_optional"; + elseif state == 5 + name = "write_aliased_generic_optional"; + elseif state == 6 + name = "write_aliased_generic_union_2"; + elseif state == 7 + name = "write_aliased_generic_vector"; + elseif state == 8 + name = "write_aliased_generic_fixed_vector"; + elseif state == 9 + name = "write_stream_of_aliased_generic_union_2 or end_stream_of_aliased_generic_union_2"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/ArrayOrScalar.m b/matlab/generated/+test_model/ArrayOrScalar.m new file mode 100644 index 00000000..e756b2ee --- /dev/null +++ b/matlab/generated/+test_model/ArrayOrScalar.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef ArrayOrScalar < yardl.Union + methods (Static) + function res = Array(value) + res = test_model.ArrayOrScalar(1, value); + end + + function res = Scalar(value) + res = test_model.ArrayOrScalar(2, value); + end + + function z = zeros(varargin) + elem = test_model.ArrayOrScalar(0, yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function res = isArray(self) + res = self.index == 1; + end + + function res = isScalar(self) + res = self.index == 2; + end + + function eq = eq(self, other) + eq = isa(other, "test_model.ArrayOrScalar") && isequal(self.index, other.index) && isequal(self.value, other.value); + end + + function ne = ne(self, other) + ne = ~self.eq(other); + end + + function t = tag(self) + tags_ = ["Array", "Scalar"]; + t = tags_(self.index_); + end + end +end diff --git a/matlab/generated/+test_model/ArrayWithKeywordDimensionNames.m b/matlab/generated/+test_model/ArrayWithKeywordDimensionNames.m new file mode 100644 index 00000000..bf2391e8 --- /dev/null +++ b/matlab/generated/+test_model/ArrayWithKeywordDimensionNames.m @@ -0,0 +1,8 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function a = ArrayWithKeywordDimensionNames(array) + arguments + array int32 + end + a = array; +end diff --git a/matlab/generated/+test_model/BenchmarkFloat256x256ReaderBase.m b/matlab/generated/+test_model/BenchmarkFloat256x256ReaderBase.m new file mode 100644 index 00000000..80aa258a --- /dev/null +++ b/matlab/generated/+test_model/BenchmarkFloat256x256ReaderBase.m @@ -0,0 +1,78 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef BenchmarkFloat256x256ReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = BenchmarkFloat256x256ReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 1 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function more = has_float256x256(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + more = self.has_float256x256_(); + if ~more + self.state_ = 1; + end + end + + function value = read_float256x256(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_float256x256_(); + end + + function copy_to(self, writer) + while self.has_float256x256() + item = self.read_float256x256(); + writer.write_float256x256({item}); + end + writer.end_float256x256(); + end + end + + methods (Static) + function res = schema() + res = test_model.BenchmarkFloat256x256WriterBase.schema; + end + end + + methods (Abstract, Access=protected) + has_float256x256_(self) + read_float256x256_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_float256x256"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/BenchmarkFloat256x256WriterBase.m b/matlab/generated/+test_model/BenchmarkFloat256x256WriterBase.m new file mode 100644 index 00000000..81128c89 --- /dev/null +++ b/matlab/generated/+test_model/BenchmarkFloat256x256WriterBase.m @@ -0,0 +1,69 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol BenchmarkFloat256x256 +classdef (Abstract) BenchmarkFloat256x256WriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = BenchmarkFloat256x256WriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 1 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_float256x256(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_float256x256_(value); + end + + function end_float256x256(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.end_stream_(); + self.state_ = 1; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"BenchmarkFloat256x256","sequence":[{"name":"float256x256","type":{"stream":{"items":{"array":{"items":"float32","dimensions":[{"length":256},{"length":256}]}}}}}]},"types":null}'); + end + end + + methods (Abstract, Access=protected) + write_float256x256_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_float256x256 or end_float256x256"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/BenchmarkFloatVlenReaderBase.m b/matlab/generated/+test_model/BenchmarkFloatVlenReaderBase.m new file mode 100644 index 00000000..f92c84c3 --- /dev/null +++ b/matlab/generated/+test_model/BenchmarkFloatVlenReaderBase.m @@ -0,0 +1,78 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef BenchmarkFloatVlenReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = BenchmarkFloatVlenReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 1 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function more = has_float_array(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + more = self.has_float_array_(); + if ~more + self.state_ = 1; + end + end + + function value = read_float_array(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_float_array_(); + end + + function copy_to(self, writer) + while self.has_float_array() + item = self.read_float_array(); + writer.write_float_array({item}); + end + writer.end_float_array(); + end + end + + methods (Static) + function res = schema() + res = test_model.BenchmarkFloatVlenWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + has_float_array_(self) + read_float_array_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_float_array"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/BenchmarkFloatVlenWriterBase.m b/matlab/generated/+test_model/BenchmarkFloatVlenWriterBase.m new file mode 100644 index 00000000..acb85a59 --- /dev/null +++ b/matlab/generated/+test_model/BenchmarkFloatVlenWriterBase.m @@ -0,0 +1,69 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol BenchmarkFloatVlen +classdef (Abstract) BenchmarkFloatVlenWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = BenchmarkFloatVlenWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 1 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_float_array(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_float_array_(value); + end + + function end_float_array(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.end_stream_(); + self.state_ = 1; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"BenchmarkFloatVlen","sequence":[{"name":"floatArray","type":{"stream":{"items":{"array":{"items":"float32","dimensions":2}}}}}]},"types":null}'); + end + end + + methods (Abstract, Access=protected) + write_float_array_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_float_array or end_float_array"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/BenchmarkInt256x256ReaderBase.m b/matlab/generated/+test_model/BenchmarkInt256x256ReaderBase.m new file mode 100644 index 00000000..103766a0 --- /dev/null +++ b/matlab/generated/+test_model/BenchmarkInt256x256ReaderBase.m @@ -0,0 +1,78 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef BenchmarkInt256x256ReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = BenchmarkInt256x256ReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 1 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function more = has_int256x256(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + more = self.has_int256x256_(); + if ~more + self.state_ = 1; + end + end + + function value = read_int256x256(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_int256x256_(); + end + + function copy_to(self, writer) + while self.has_int256x256() + item = self.read_int256x256(); + writer.write_int256x256({item}); + end + writer.end_int256x256(); + end + end + + methods (Static) + function res = schema() + res = test_model.BenchmarkInt256x256WriterBase.schema; + end + end + + methods (Abstract, Access=protected) + has_int256x256_(self) + read_int256x256_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_int256x256"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/BenchmarkInt256x256WriterBase.m b/matlab/generated/+test_model/BenchmarkInt256x256WriterBase.m new file mode 100644 index 00000000..ccf6c330 --- /dev/null +++ b/matlab/generated/+test_model/BenchmarkInt256x256WriterBase.m @@ -0,0 +1,69 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol BenchmarkInt256x256 +classdef (Abstract) BenchmarkInt256x256WriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = BenchmarkInt256x256WriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 1 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_int256x256(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_int256x256_(value); + end + + function end_int256x256(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.end_stream_(); + self.state_ = 1; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"BenchmarkInt256x256","sequence":[{"name":"int256x256","type":{"stream":{"items":{"array":{"items":"int32","dimensions":[{"length":256},{"length":256}]}}}}}]},"types":null}'); + end + end + + methods (Abstract, Access=protected) + write_int256x256_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_int256x256 or end_int256x256"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/BenchmarkSimpleMrdReaderBase.m b/matlab/generated/+test_model/BenchmarkSimpleMrdReaderBase.m new file mode 100644 index 00000000..90ea028c --- /dev/null +++ b/matlab/generated/+test_model/BenchmarkSimpleMrdReaderBase.m @@ -0,0 +1,78 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef BenchmarkSimpleMrdReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = BenchmarkSimpleMrdReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 1 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function more = has_data(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + more = self.has_data_(); + if ~more + self.state_ = 1; + end + end + + function value = read_data(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_data_(); + end + + function copy_to(self, writer) + while self.has_data() + item = self.read_data(); + writer.write_data({item}); + end + writer.end_data(); + end + end + + methods (Static) + function res = schema() + res = test_model.BenchmarkSimpleMrdWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + has_data_(self) + read_data_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_data"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/BenchmarkSimpleMrdWriterBase.m b/matlab/generated/+test_model/BenchmarkSimpleMrdWriterBase.m new file mode 100644 index 00000000..6d546b6b --- /dev/null +++ b/matlab/generated/+test_model/BenchmarkSimpleMrdWriterBase.m @@ -0,0 +1,69 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol BenchmarkSimpleMrd +classdef (Abstract) BenchmarkSimpleMrdWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = BenchmarkSimpleMrdWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 1 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_data(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_data_(value); + end + + function end_data(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.end_stream_(); + self.state_ = 1; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"BenchmarkSimpleMrd","sequence":[{"name":"data","type":{"stream":{"items":[{"tag":"acquisition","explicitTag":true,"type":"TestModel.SimpleAcquisition"},{"tag":"image","explicitTag":true,"type":{"name":"Image.Image","typeArguments":["float32"]}}]}}}]},"types":[{"name":"Image","typeParameters":["T"],"type":{"array":{"items":"T","dimensions":[{"name":"x"},{"name":"y"}]}}},{"name":"SimpleAcquisition","fields":[{"name":"flags","type":"uint64"},{"name":"idx","type":"TestModel.SimpleEncodingCounters"},{"name":"data","type":{"array":{"items":"complexfloat32","dimensions":2}}},{"name":"trajectory","type":{"array":{"items":"float32","dimensions":2}}}]},{"name":"SimpleEncodingCounters","fields":[{"name":"e1","type":[null,"uint32"]},{"name":"e2","type":[null,"uint32"]},{"name":"slice","type":[null,"uint32"]},{"name":"repetition","type":[null,"uint32"]}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_data_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_data or end_data"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/BenchmarkSmallRecordReaderBase.m b/matlab/generated/+test_model/BenchmarkSmallRecordReaderBase.m new file mode 100644 index 00000000..f646f161 --- /dev/null +++ b/matlab/generated/+test_model/BenchmarkSmallRecordReaderBase.m @@ -0,0 +1,78 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef BenchmarkSmallRecordReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = BenchmarkSmallRecordReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 1 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function more = has_small_record(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + more = self.has_small_record_(); + if ~more + self.state_ = 1; + end + end + + function value = read_small_record(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_small_record_(); + end + + function copy_to(self, writer) + while self.has_small_record() + item = self.read_small_record(); + writer.write_small_record({item}); + end + writer.end_small_record(); + end + end + + methods (Static) + function res = schema() + res = test_model.BenchmarkSmallRecordWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + has_small_record_(self) + read_small_record_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_small_record"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/BenchmarkSmallRecordWithOptionalsReaderBase.m b/matlab/generated/+test_model/BenchmarkSmallRecordWithOptionalsReaderBase.m new file mode 100644 index 00000000..09cd351f --- /dev/null +++ b/matlab/generated/+test_model/BenchmarkSmallRecordWithOptionalsReaderBase.m @@ -0,0 +1,78 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef BenchmarkSmallRecordWithOptionalsReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = BenchmarkSmallRecordWithOptionalsReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 1 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function more = has_small_record(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + more = self.has_small_record_(); + if ~more + self.state_ = 1; + end + end + + function value = read_small_record(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_small_record_(); + end + + function copy_to(self, writer) + while self.has_small_record() + item = self.read_small_record(); + writer.write_small_record({item}); + end + writer.end_small_record(); + end + end + + methods (Static) + function res = schema() + res = test_model.BenchmarkSmallRecordWithOptionalsWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + has_small_record_(self) + read_small_record_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_small_record"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/BenchmarkSmallRecordWithOptionalsWriterBase.m b/matlab/generated/+test_model/BenchmarkSmallRecordWithOptionalsWriterBase.m new file mode 100644 index 00000000..f486af50 --- /dev/null +++ b/matlab/generated/+test_model/BenchmarkSmallRecordWithOptionalsWriterBase.m @@ -0,0 +1,69 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol BenchmarkSmallRecordWithOptionals +classdef (Abstract) BenchmarkSmallRecordWithOptionalsWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = BenchmarkSmallRecordWithOptionalsWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 1 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_small_record(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_small_record_(value); + end + + function end_small_record(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.end_stream_(); + self.state_ = 1; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"BenchmarkSmallRecordWithOptionals","sequence":[{"name":"smallRecord","type":{"stream":{"items":"TestModel.SimpleEncodingCounters"}}}]},"types":[{"name":"SimpleEncodingCounters","fields":[{"name":"e1","type":[null,"uint32"]},{"name":"e2","type":[null,"uint32"]},{"name":"slice","type":[null,"uint32"]},{"name":"repetition","type":[null,"uint32"]}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_small_record_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_small_record or end_small_record"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/BenchmarkSmallRecordWriterBase.m b/matlab/generated/+test_model/BenchmarkSmallRecordWriterBase.m new file mode 100644 index 00000000..6bb9d83f --- /dev/null +++ b/matlab/generated/+test_model/BenchmarkSmallRecordWriterBase.m @@ -0,0 +1,69 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol BenchmarkSmallRecord +classdef (Abstract) BenchmarkSmallRecordWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = BenchmarkSmallRecordWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 1 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_small_record(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_small_record_(value); + end + + function end_small_record(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.end_stream_(); + self.state_ = 1; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"BenchmarkSmallRecord","sequence":[{"name":"smallRecord","type":{"stream":{"items":"TestModel.SmallBenchmarkRecord"}}}]},"types":[{"name":"SmallBenchmarkRecord","fields":[{"name":"a","type":"float64"},{"name":"b","type":"float32"},{"name":"c","type":"float32"}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_small_record_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_small_record or end_small_record"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/DaysOfWeek.m b/matlab/generated/+test_model/DaysOfWeek.m new file mode 100644 index 00000000..800705d6 --- /dev/null +++ b/matlab/generated/+test_model/DaysOfWeek.m @@ -0,0 +1,4 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef DaysOfWeek < basic_types.DaysOfWeek +end diff --git a/matlab/generated/+test_model/DynamicNDArraysReaderBase.m b/matlab/generated/+test_model/DynamicNDArraysReaderBase.m new file mode 100644 index 00000000..3a02e898 --- /dev/null +++ b/matlab/generated/+test_model/DynamicNDArraysReaderBase.m @@ -0,0 +1,105 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef DynamicNDArraysReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = DynamicNDArraysReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 4 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function value = read_ints(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_ints_(); + self.state_ = 1; + end + + % Ordinal 1 + function value = read_simple_record_array(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_simple_record_array_(); + self.state_ = 2; + end + + % Ordinal 2 + function value = read_record_with_vlens_array(self) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + value = self.read_record_with_vlens_array_(); + self.state_ = 3; + end + + % Ordinal 3 + function value = read_record_with_dynamic_nd_arrays(self) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + value = self.read_record_with_dynamic_nd_arrays_(); + self.state_ = 4; + end + + function copy_to(self, writer) + writer.write_ints(self.read_ints()); + writer.write_simple_record_array(self.read_simple_record_array()); + writer.write_record_with_vlens_array(self.read_record_with_vlens_array()); + writer.write_record_with_dynamic_nd_arrays(self.read_record_with_dynamic_nd_arrays()); + end + end + + methods (Static) + function res = schema() + res = test_model.DynamicNDArraysWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + read_ints_(self) + read_simple_record_array_(self) + read_record_with_vlens_array_(self) + read_record_with_dynamic_nd_arrays_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_ints"; + elseif state == 1 + name = "read_simple_record_array"; + elseif state == 2 + name = "read_record_with_vlens_array"; + elseif state == 3 + name = "read_record_with_dynamic_nd_arrays"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/DynamicNDArraysWriterBase.m b/matlab/generated/+test_model/DynamicNDArraysWriterBase.m new file mode 100644 index 00000000..3dbbaf9e --- /dev/null +++ b/matlab/generated/+test_model/DynamicNDArraysWriterBase.m @@ -0,0 +1,100 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol DynamicNDArrays +classdef (Abstract) DynamicNDArraysWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = DynamicNDArraysWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 4 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_ints(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_ints_(value); + self.state_ = 1; + end + + % Ordinal 1 + function write_simple_record_array(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_simple_record_array_(value); + self.state_ = 2; + end + + % Ordinal 2 + function write_record_with_vlens_array(self, value) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + self.write_record_with_vlens_array_(value); + self.state_ = 3; + end + + % Ordinal 3 + function write_record_with_dynamic_nd_arrays(self, value) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + self.write_record_with_dynamic_nd_arrays_(value); + self.state_ = 4; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"DynamicNDArrays","sequence":[{"name":"ints","type":{"array":{"items":"int32"}}},{"name":"simpleRecordArray","type":{"array":{"items":"TestModel.SimpleRecord"}}},{"name":"recordWithVlensArray","type":{"array":{"items":"TestModel.RecordWithVlens"}}},{"name":"recordWithDynamicNDArrays","type":"TestModel.RecordWithDynamicNDArrays"}]},"types":[{"name":"IntArray","type":{"array":{"items":"int32"}}},{"name":"RecordWithDynamicNDArrays","fields":[{"name":"ints","type":"TestModel.IntArray"},{"name":"simpleRecordArray","type":{"array":{"items":"TestModel.SimpleRecord"}}},{"name":"recordWithVlensArray","type":{"array":{"items":"TestModel.RecordWithVlens"}}}]},{"name":"RecordWithVlens","fields":[{"name":"a","type":{"vector":{"items":"TestModel.SimpleRecord"}}},{"name":"b","type":"int32"},{"name":"c","type":"int32"}]},{"name":"SimpleRecord","fields":[{"name":"x","type":"int32"},{"name":"y","type":"int32"},{"name":"z","type":"int32"}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_ints_(self, value) + write_simple_record_array_(self, value) + write_record_with_vlens_array_(self, value) + write_record_with_dynamic_nd_arrays_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_ints"; + elseif state == 1 + name = "write_simple_record_array"; + elseif state == 2 + name = "write_record_with_vlens_array"; + elseif state == 3 + name = "write_record_with_dynamic_nd_arrays"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/EnumWithKeywordSymbols.m b/matlab/generated/+test_model/EnumWithKeywordSymbols.m new file mode 100644 index 00000000..e8fe230c --- /dev/null +++ b/matlab/generated/+test_model/EnumWithKeywordSymbols.m @@ -0,0 +1,25 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef EnumWithKeywordSymbols < uint64 + methods (Static) + function v = TRY + v = test_model.EnumWithKeywordSymbols(2); + end + function v = CATCH + v = test_model.EnumWithKeywordSymbols(1); + end + + function z = zeros(varargin) + elem = test_model.EnumWithKeywordSymbols(0); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/EnumsReaderBase.m b/matlab/generated/+test_model/EnumsReaderBase.m new file mode 100644 index 00000000..ec4da09a --- /dev/null +++ b/matlab/generated/+test_model/EnumsReaderBase.m @@ -0,0 +1,91 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef EnumsReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = EnumsReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 3 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function value = read_single(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_single_(); + self.state_ = 1; + end + + % Ordinal 1 + function value = read_vec(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_vec_(); + self.state_ = 2; + end + + % Ordinal 2 + function value = read_size(self) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + value = self.read_size_(); + self.state_ = 3; + end + + function copy_to(self, writer) + writer.write_single(self.read_single()); + writer.write_vec(self.read_vec()); + writer.write_size(self.read_size()); + end + end + + methods (Static) + function res = schema() + res = test_model.EnumsWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + read_single_(self) + read_vec_(self) + read_size_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_single"; + elseif state == 1 + name = "read_vec"; + elseif state == 2 + name = "read_size"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/EnumsWriterBase.m b/matlab/generated/+test_model/EnumsWriterBase.m new file mode 100644 index 00000000..21e4267e --- /dev/null +++ b/matlab/generated/+test_model/EnumsWriterBase.m @@ -0,0 +1,87 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol Enums +classdef (Abstract) EnumsWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = EnumsWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 3 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_single(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_single_(value); + self.state_ = 1; + end + + % Ordinal 1 + function write_vec(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_vec_(value); + self.state_ = 2; + end + + % Ordinal 2 + function write_size(self, value) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + self.write_size_(value); + self.state_ = 3; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"Enums","sequence":[{"name":"single","type":"TestModel.Fruits"},{"name":"vec","type":{"vector":{"items":"TestModel.Fruits"}}},{"name":"size","type":"TestModel.SizeBasedEnum"}]},"types":[{"name":"Fruits","values":[{"symbol":"apple","value":0},{"symbol":"banana","value":1},{"symbol":"pear","value":2}]},{"name":"Fruits","type":"BasicTypes.Fruits"},{"name":"SizeBasedEnum","base":"size","values":[{"symbol":"a","value":0},{"symbol":"b","value":1},{"symbol":"c","value":2}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_single_(self, value) + write_vec_(self, value) + write_size_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_single"; + elseif state == 1 + name = "write_vec"; + elseif state == 2 + name = "write_size"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/FixedArraysReaderBase.m b/matlab/generated/+test_model/FixedArraysReaderBase.m new file mode 100644 index 00000000..41944345 --- /dev/null +++ b/matlab/generated/+test_model/FixedArraysReaderBase.m @@ -0,0 +1,119 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef FixedArraysReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = FixedArraysReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 5 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function value = read_ints(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_ints_(); + self.state_ = 1; + end + + % Ordinal 1 + function value = read_fixed_simple_record_array(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_fixed_simple_record_array_(); + self.state_ = 2; + end + + % Ordinal 2 + function value = read_fixed_record_with_vlens_array(self) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + value = self.read_fixed_record_with_vlens_array_(); + self.state_ = 3; + end + + % Ordinal 3 + function value = read_record_with_fixed_arrays(self) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + value = self.read_record_with_fixed_arrays_(); + self.state_ = 4; + end + + % Ordinal 4 + function value = read_named_array(self) + if self.state_ ~= 4 + self.raise_unexpected_state_(4); + end + + value = self.read_named_array_(); + self.state_ = 5; + end + + function copy_to(self, writer) + writer.write_ints(self.read_ints()); + writer.write_fixed_simple_record_array(self.read_fixed_simple_record_array()); + writer.write_fixed_record_with_vlens_array(self.read_fixed_record_with_vlens_array()); + writer.write_record_with_fixed_arrays(self.read_record_with_fixed_arrays()); + writer.write_named_array(self.read_named_array()); + end + end + + methods (Static) + function res = schema() + res = test_model.FixedArraysWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + read_ints_(self) + read_fixed_simple_record_array_(self) + read_fixed_record_with_vlens_array_(self) + read_record_with_fixed_arrays_(self) + read_named_array_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_ints"; + elseif state == 1 + name = "read_fixed_simple_record_array"; + elseif state == 2 + name = "read_fixed_record_with_vlens_array"; + elseif state == 3 + name = "read_record_with_fixed_arrays"; + elseif state == 4 + name = "read_named_array"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/FixedArraysWriterBase.m b/matlab/generated/+test_model/FixedArraysWriterBase.m new file mode 100644 index 00000000..07543395 --- /dev/null +++ b/matlab/generated/+test_model/FixedArraysWriterBase.m @@ -0,0 +1,113 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol FixedArrays +classdef (Abstract) FixedArraysWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = FixedArraysWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 5 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_ints(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_ints_(value); + self.state_ = 1; + end + + % Ordinal 1 + function write_fixed_simple_record_array(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_fixed_simple_record_array_(value); + self.state_ = 2; + end + + % Ordinal 2 + function write_fixed_record_with_vlens_array(self, value) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + self.write_fixed_record_with_vlens_array_(value); + self.state_ = 3; + end + + % Ordinal 3 + function write_record_with_fixed_arrays(self, value) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + self.write_record_with_fixed_arrays_(value); + self.state_ = 4; + end + + % Ordinal 4 + function write_named_array(self, value) + if self.state_ ~= 4 + self.raise_unexpected_state_(4); + end + + self.write_named_array_(value); + self.state_ = 5; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"FixedArrays","sequence":[{"name":"ints","type":{"array":{"items":"int32","dimensions":[{"length":2},{"length":3}]}}},{"name":"fixedSimpleRecordArray","type":{"array":{"items":"TestModel.SimpleRecord","dimensions":[{"length":3},{"length":2}]}}},{"name":"fixedRecordWithVlensArray","type":{"array":{"items":"TestModel.RecordWithVlens","dimensions":[{"length":2},{"length":2}]}}},{"name":"recordWithFixedArrays","type":"TestModel.RecordWithFixedArrays"},{"name":"namedArray","type":"TestModel.NamedFixedNDArray"}]},"types":[{"name":"NamedFixedNDArray","type":{"array":{"items":"int32","dimensions":[{"name":"dimA","length":2},{"name":"dimB","length":4}]}}},{"name":"RecordWithFixedArrays","fields":[{"name":"ints","type":{"array":{"items":"int32","dimensions":[{"length":2},{"length":3}]}}},{"name":"fixedSimpleRecordArray","type":{"array":{"items":"TestModel.SimpleRecord","dimensions":[{"length":3},{"length":2}]}}},{"name":"fixedRecordWithVlensArray","type":{"array":{"items":"TestModel.RecordWithVlens","dimensions":[{"length":2},{"length":2}]}}}]},{"name":"RecordWithVlens","fields":[{"name":"a","type":{"vector":{"items":"TestModel.SimpleRecord"}}},{"name":"b","type":"int32"},{"name":"c","type":"int32"}]},{"name":"SimpleRecord","fields":[{"name":"x","type":"int32"},{"name":"y","type":"int32"},{"name":"z","type":"int32"}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_ints_(self, value) + write_fixed_simple_record_array_(self, value) + write_fixed_record_with_vlens_array_(self, value) + write_record_with_fixed_arrays_(self, value) + write_named_array_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_ints"; + elseif state == 1 + name = "write_fixed_simple_record_array"; + elseif state == 2 + name = "write_fixed_record_with_vlens_array"; + elseif state == 3 + name = "write_record_with_fixed_arrays"; + elseif state == 4 + name = "write_named_array"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/FixedVectorsReaderBase.m b/matlab/generated/+test_model/FixedVectorsReaderBase.m new file mode 100644 index 00000000..a70601d0 --- /dev/null +++ b/matlab/generated/+test_model/FixedVectorsReaderBase.m @@ -0,0 +1,105 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef FixedVectorsReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = FixedVectorsReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 4 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function value = read_fixed_int_vector(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_fixed_int_vector_(); + self.state_ = 1; + end + + % Ordinal 1 + function value = read_fixed_simple_record_vector(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_fixed_simple_record_vector_(); + self.state_ = 2; + end + + % Ordinal 2 + function value = read_fixed_record_with_vlens_vector(self) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + value = self.read_fixed_record_with_vlens_vector_(); + self.state_ = 3; + end + + % Ordinal 3 + function value = read_record_with_fixed_vectors(self) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + value = self.read_record_with_fixed_vectors_(); + self.state_ = 4; + end + + function copy_to(self, writer) + writer.write_fixed_int_vector(self.read_fixed_int_vector()); + writer.write_fixed_simple_record_vector(self.read_fixed_simple_record_vector()); + writer.write_fixed_record_with_vlens_vector(self.read_fixed_record_with_vlens_vector()); + writer.write_record_with_fixed_vectors(self.read_record_with_fixed_vectors()); + end + end + + methods (Static) + function res = schema() + res = test_model.FixedVectorsWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + read_fixed_int_vector_(self) + read_fixed_simple_record_vector_(self) + read_fixed_record_with_vlens_vector_(self) + read_record_with_fixed_vectors_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_fixed_int_vector"; + elseif state == 1 + name = "read_fixed_simple_record_vector"; + elseif state == 2 + name = "read_fixed_record_with_vlens_vector"; + elseif state == 3 + name = "read_record_with_fixed_vectors"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/FixedVectorsWriterBase.m b/matlab/generated/+test_model/FixedVectorsWriterBase.m new file mode 100644 index 00000000..828e597c --- /dev/null +++ b/matlab/generated/+test_model/FixedVectorsWriterBase.m @@ -0,0 +1,100 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol FixedVectors +classdef (Abstract) FixedVectorsWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = FixedVectorsWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 4 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_fixed_int_vector(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_fixed_int_vector_(value); + self.state_ = 1; + end + + % Ordinal 1 + function write_fixed_simple_record_vector(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_fixed_simple_record_vector_(value); + self.state_ = 2; + end + + % Ordinal 2 + function write_fixed_record_with_vlens_vector(self, value) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + self.write_fixed_record_with_vlens_vector_(value); + self.state_ = 3; + end + + % Ordinal 3 + function write_record_with_fixed_vectors(self, value) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + self.write_record_with_fixed_vectors_(value); + self.state_ = 4; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"FixedVectors","sequence":[{"name":"fixedIntVector","type":{"vector":{"items":"int32","length":5}}},{"name":"fixedSimpleRecordVector","type":{"vector":{"items":"TestModel.SimpleRecord","length":3}}},{"name":"fixedRecordWithVlensVector","type":{"vector":{"items":"TestModel.RecordWithVlens","length":2}}},{"name":"recordWithFixedVectors","type":"TestModel.RecordWithFixedVectors"}]},"types":[{"name":"RecordWithFixedVectors","fields":[{"name":"fixedIntVector","type":{"vector":{"items":"int32","length":5}}},{"name":"fixedSimpleRecordVector","type":{"vector":{"items":"TestModel.SimpleRecord","length":3}}},{"name":"fixedRecordWithVlensVector","type":{"vector":{"items":"TestModel.RecordWithVlens","length":2}}}]},{"name":"RecordWithVlens","fields":[{"name":"a","type":{"vector":{"items":"TestModel.SimpleRecord"}}},{"name":"b","type":"int32"},{"name":"c","type":"int32"}]},{"name":"SimpleRecord","fields":[{"name":"x","type":"int32"},{"name":"y","type":"int32"},{"name":"z","type":"int32"}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_fixed_int_vector_(self, value) + write_fixed_simple_record_vector_(self, value) + write_fixed_record_with_vlens_vector_(self, value) + write_record_with_fixed_vectors_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_fixed_int_vector"; + elseif state == 1 + name = "write_fixed_simple_record_vector"; + elseif state == 2 + name = "write_fixed_record_with_vlens_vector"; + elseif state == 3 + name = "write_record_with_fixed_vectors"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/FlagsReaderBase.m b/matlab/generated/+test_model/FlagsReaderBase.m new file mode 100644 index 00000000..b88407d9 --- /dev/null +++ b/matlab/generated/+test_model/FlagsReaderBase.m @@ -0,0 +1,107 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef FlagsReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = FlagsReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 2 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function more = has_days(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + more = self.has_days_(); + if ~more + self.state_ = 1; + end + end + + function value = read_days(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_days_(); + end + + % Ordinal 1 + function more = has_formats(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + more = self.has_formats_(); + if ~more + self.state_ = 2; + end + end + + function value = read_formats(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_formats_(); + end + + function copy_to(self, writer) + while self.has_days() + item = self.read_days(); + writer.write_days({item}); + end + writer.end_days(); + while self.has_formats() + item = self.read_formats(); + writer.write_formats({item}); + end + writer.end_formats(); + end + end + + methods (Static) + function res = schema() + res = test_model.FlagsWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + has_days_(self) + read_days_(self) + has_formats_(self) + read_formats_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_days"; + elseif state == 1 + name = "read_formats"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/FlagsWriterBase.m b/matlab/generated/+test_model/FlagsWriterBase.m new file mode 100644 index 00000000..57842e28 --- /dev/null +++ b/matlab/generated/+test_model/FlagsWriterBase.m @@ -0,0 +1,90 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol Flags +classdef (Abstract) FlagsWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = FlagsWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 2 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_days(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_days_(value); + end + + function end_days(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.end_stream_(); + self.state_ = 1; + end + + % Ordinal 1 + function write_formats(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_formats_(value); + end + + function end_formats(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.end_stream_(); + self.state_ = 2; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"Flags","sequence":[{"name":"days","type":{"stream":{"items":"TestModel.DaysOfWeek"}}},{"name":"formats","type":{"stream":{"items":"TestModel.TextFormat"}}}]},"types":[{"name":"DaysOfWeek","values":[{"symbol":"monday","value":1},{"symbol":"tuesday","value":2},{"symbol":"wednesday","value":4},{"symbol":"thursday","value":8},{"symbol":"friday","value":16},{"symbol":"saturday","value":32},{"symbol":"sunday","value":64}]},{"name":"TextFormat","base":"uint64","values":[{"symbol":"regular","value":0},{"symbol":"bold","value":1},{"symbol":"italic","value":2},{"symbol":"underline","value":4},{"symbol":"strikethrough","value":8}]},{"name":"DaysOfWeek","type":"BasicTypes.DaysOfWeek"},{"name":"TextFormat","type":"BasicTypes.TextFormat"}]}'); + end + end + + methods (Abstract, Access=protected) + write_days_(self, value) + write_formats_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_days or end_days"; + elseif state == 1 + name = "write_formats or end_formats"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/Fruits.m b/matlab/generated/+test_model/Fruits.m new file mode 100644 index 00000000..e8b62e65 --- /dev/null +++ b/matlab/generated/+test_model/Fruits.m @@ -0,0 +1,4 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef Fruits < basic_types.Fruits +end diff --git a/matlab/generated/+test_model/GenericRecord.m b/matlab/generated/+test_model/GenericRecord.m new file mode 100644 index 00000000..7286f700 --- /dev/null +++ b/matlab/generated/+test_model/GenericRecord.m @@ -0,0 +1,51 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef GenericRecord < handle + properties + scalar_1 + scalar_2 + vector_1 + image_2 + end + + methods + function self = GenericRecord(kwargs) + arguments + kwargs.scalar_1; + kwargs.scalar_2; + kwargs.vector_1; + kwargs.image_2; + end + if ~isfield(kwargs, "scalar_1") + throw(yardl.TypeError("Missing required keyword argument 'scalar_1'")) + end + self.scalar_1 = kwargs.scalar_1; + if ~isfield(kwargs, "scalar_2") + throw(yardl.TypeError("Missing required keyword argument 'scalar_2'")) + end + self.scalar_2 = kwargs.scalar_2; + if ~isfield(kwargs, "vector_1") + throw(yardl.TypeError("Missing required keyword argument 'vector_1'")) + end + self.vector_1 = kwargs.vector_1; + if ~isfield(kwargs, "image_2") + throw(yardl.TypeError("Missing required keyword argument 'image_2'")) + end + self.image_2 = kwargs.image_2; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.GenericRecord") && ... + isequal(self.scalar_1, other.scalar_1) && ... + isequal(self.scalar_2, other.scalar_2) && ... + isequal(self.vector_1, other.vector_1) && ... + isequal(self.image_2, other.image_2); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + +end diff --git a/matlab/generated/+test_model/GenericUnion3.m b/matlab/generated/+test_model/GenericUnion3.m new file mode 100644 index 00000000..802ca942 --- /dev/null +++ b/matlab/generated/+test_model/GenericUnion3.m @@ -0,0 +1,57 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef GenericUnion3 < yardl.Union + methods (Static) + function res = T(value) + res = test_model.GenericUnion3(1, value); + end + + function res = U(value) + res = test_model.GenericUnion3(2, value); + end + + function res = V(value) + res = test_model.GenericUnion3(3, value); + end + + function z = zeros(varargin) + elem = test_model.GenericUnion3(0, yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function res = isT(self) + res = self.index == 1; + end + + function res = isU(self) + res = self.index == 2; + end + + function res = isV(self) + res = self.index == 3; + end + + function eq = eq(self, other) + eq = isa(other, "test_model.GenericUnion3") && isequal(self.index, other.index) && isequal(self.value, other.value); + end + + function ne = ne(self, other) + ne = ~self.eq(other); + end + + function t = tag(self) + tags_ = ["T", "U", "V"]; + t = tags_(self.index_); + end + end +end diff --git a/matlab/generated/+test_model/GenericUnion3Alternate.m b/matlab/generated/+test_model/GenericUnion3Alternate.m new file mode 100644 index 00000000..ad7f4a1f --- /dev/null +++ b/matlab/generated/+test_model/GenericUnion3Alternate.m @@ -0,0 +1,57 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef GenericUnion3Alternate < yardl.Union + methods (Static) + function res = U(value) + res = test_model.GenericUnion3Alternate(1, value); + end + + function res = V(value) + res = test_model.GenericUnion3Alternate(2, value); + end + + function res = W(value) + res = test_model.GenericUnion3Alternate(3, value); + end + + function z = zeros(varargin) + elem = test_model.GenericUnion3Alternate(0, yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function res = isU(self) + res = self.index == 1; + end + + function res = isV(self) + res = self.index == 2; + end + + function res = isW(self) + res = self.index == 3; + end + + function eq = eq(self, other) + eq = isa(other, "test_model.GenericUnion3Alternate") && isequal(self.index, other.index) && isequal(self.value, other.value); + end + + function ne = ne(self, other) + ne = ~self.eq(other); + end + + function t = tag(self) + tags_ = ["U", "V", "W"]; + t = tags_(self.index_); + end + end +end diff --git a/matlab/generated/+test_model/GenericUnionWithRepeatedTypeParameters.m b/matlab/generated/+test_model/GenericUnionWithRepeatedTypeParameters.m new file mode 100644 index 00000000..40797c2c --- /dev/null +++ b/matlab/generated/+test_model/GenericUnionWithRepeatedTypeParameters.m @@ -0,0 +1,57 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef GenericUnionWithRepeatedTypeParameters < yardl.Union + methods (Static) + function res = T(value) + res = test_model.GenericUnionWithRepeatedTypeParameters(1, value); + end + + function res = Tv(value) + res = test_model.GenericUnionWithRepeatedTypeParameters(2, value); + end + + function res = Ta(value) + res = test_model.GenericUnionWithRepeatedTypeParameters(3, value); + end + + function z = zeros(varargin) + elem = test_model.GenericUnionWithRepeatedTypeParameters(0, yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function res = isT(self) + res = self.index == 1; + end + + function res = isTv(self) + res = self.index == 2; + end + + function res = isTa(self) + res = self.index == 3; + end + + function eq = eq(self, other) + eq = isa(other, "test_model.GenericUnionWithRepeatedTypeParameters") && isequal(self.index, other.index) && isequal(self.value, other.value); + end + + function ne = ne(self, other) + ne = ~self.eq(other); + end + + function t = tag(self) + tags_ = ["T", "Tv", "Ta"]; + t = tags_(self.index_); + end + end +end diff --git a/matlab/generated/+test_model/Image.m b/matlab/generated/+test_model/Image.m new file mode 100644 index 00000000..0332777d --- /dev/null +++ b/matlab/generated/+test_model/Image.m @@ -0,0 +1,5 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function a = Image(array) + a = array; +end diff --git a/matlab/generated/+test_model/ImageFloatOrImageDouble.m b/matlab/generated/+test_model/ImageFloatOrImageDouble.m new file mode 100644 index 00000000..4d03fd94 --- /dev/null +++ b/matlab/generated/+test_model/ImageFloatOrImageDouble.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef ImageFloatOrImageDouble < yardl.Union + methods (Static) + function res = ImageFloat(value) + res = test_model.ImageFloatOrImageDouble(1, value); + end + + function res = ImageDouble(value) + res = test_model.ImageFloatOrImageDouble(2, value); + end + + function z = zeros(varargin) + elem = test_model.ImageFloatOrImageDouble(0, yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function res = isImageFloat(self) + res = self.index == 1; + end + + function res = isImageDouble(self) + res = self.index == 2; + end + + function eq = eq(self, other) + eq = isa(other, "test_model.ImageFloatOrImageDouble") && isequal(self.index, other.index) && isequal(self.value, other.value); + end + + function ne = ne(self, other) + ne = ~self.eq(other); + end + + function t = tag(self) + tags_ = ["ImageFloat", "ImageDouble"]; + t = tags_(self.index_); + end + end +end diff --git a/matlab/generated/+test_model/Int32OrFloat32.m b/matlab/generated/+test_model/Int32OrFloat32.m new file mode 100644 index 00000000..c29ac498 --- /dev/null +++ b/matlab/generated/+test_model/Int32OrFloat32.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef Int32OrFloat32 < yardl.Union + methods (Static) + function res = Int32(value) + res = test_model.Int32OrFloat32(1, value); + end + + function res = Float32(value) + res = test_model.Int32OrFloat32(2, value); + end + + function z = zeros(varargin) + elem = test_model.Int32OrFloat32(0, yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function res = isInt32(self) + res = self.index == 1; + end + + function res = isFloat32(self) + res = self.index == 2; + end + + function eq = eq(self, other) + eq = isa(other, "test_model.Int32OrFloat32") && isequal(self.index, other.index) && isequal(self.value, other.value); + end + + function ne = ne(self, other) + ne = ~self.eq(other); + end + + function t = tag(self) + tags_ = ["Int32", "Float32"]; + t = tags_(self.index_); + end + end +end diff --git a/matlab/generated/+test_model/Int32OrRecordWithVlens.m b/matlab/generated/+test_model/Int32OrRecordWithVlens.m new file mode 100644 index 00000000..1371fe86 --- /dev/null +++ b/matlab/generated/+test_model/Int32OrRecordWithVlens.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef Int32OrRecordWithVlens < yardl.Union + methods (Static) + function res = Int32(value) + res = test_model.Int32OrRecordWithVlens(1, value); + end + + function res = RecordWithVlens(value) + res = test_model.Int32OrRecordWithVlens(2, value); + end + + function z = zeros(varargin) + elem = test_model.Int32OrRecordWithVlens(0, yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function res = isInt32(self) + res = self.index == 1; + end + + function res = isRecordWithVlens(self) + res = self.index == 2; + end + + function eq = eq(self, other) + eq = isa(other, "test_model.Int32OrRecordWithVlens") && isequal(self.index, other.index) && isequal(self.value, other.value); + end + + function ne = ne(self, other) + ne = ~self.eq(other); + end + + function t = tag(self) + tags_ = ["Int32", "RecordWithVlens"]; + t = tags_(self.index_); + end + end +end diff --git a/matlab/generated/+test_model/Int32OrSimpleRecord.m b/matlab/generated/+test_model/Int32OrSimpleRecord.m new file mode 100644 index 00000000..d12cd188 --- /dev/null +++ b/matlab/generated/+test_model/Int32OrSimpleRecord.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef Int32OrSimpleRecord < yardl.Union + methods (Static) + function res = Int32(value) + res = test_model.Int32OrSimpleRecord(1, value); + end + + function res = SimpleRecord(value) + res = test_model.Int32OrSimpleRecord(2, value); + end + + function z = zeros(varargin) + elem = test_model.Int32OrSimpleRecord(0, yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function res = isInt32(self) + res = self.index == 1; + end + + function res = isSimpleRecord(self) + res = self.index == 2; + end + + function eq = eq(self, other) + eq = isa(other, "test_model.Int32OrSimpleRecord") && isequal(self.index, other.index) && isequal(self.value, other.value); + end + + function ne = ne(self, other) + ne = ~self.eq(other); + end + + function t = tag(self) + tags_ = ["Int32", "SimpleRecord"]; + t = tags_(self.index_); + end + end +end diff --git a/matlab/generated/+test_model/Int64Enum.m b/matlab/generated/+test_model/Int64Enum.m new file mode 100644 index 00000000..da7457c6 --- /dev/null +++ b/matlab/generated/+test_model/Int64Enum.m @@ -0,0 +1,22 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef Int64Enum < int64 + methods (Static) + function v = B + v = test_model.Int64Enum(-4611686018427387904); + end + + function z = zeros(varargin) + elem = test_model.Int64Enum(0); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/IntArray.m b/matlab/generated/+test_model/IntArray.m new file mode 100644 index 00000000..56fc2e5b --- /dev/null +++ b/matlab/generated/+test_model/IntArray.m @@ -0,0 +1,8 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function a = IntArray(array) + arguments + array int32 + end + a = array; +end diff --git a/matlab/generated/+test_model/IntFixedArray.m b/matlab/generated/+test_model/IntFixedArray.m new file mode 100644 index 00000000..c4da18be --- /dev/null +++ b/matlab/generated/+test_model/IntFixedArray.m @@ -0,0 +1,8 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function a = IntFixedArray(array) + arguments + array int32 + end + a = array; +end diff --git a/matlab/generated/+test_model/IntOrGenericRecordWithComputedFields.m b/matlab/generated/+test_model/IntOrGenericRecordWithComputedFields.m new file mode 100644 index 00000000..304e05e1 --- /dev/null +++ b/matlab/generated/+test_model/IntOrGenericRecordWithComputedFields.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef IntOrGenericRecordWithComputedFields < yardl.Union + methods (Static) + function res = Int(value) + res = test_model.IntOrGenericRecordWithComputedFields(1, value); + end + + function res = GenericRecordWithComputedFields(value) + res = test_model.IntOrGenericRecordWithComputedFields(2, value); + end + + function z = zeros(varargin) + elem = test_model.IntOrGenericRecordWithComputedFields(0, yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function res = isInt(self) + res = self.index == 1; + end + + function res = isGenericRecordWithComputedFields(self) + res = self.index == 2; + end + + function eq = eq(self, other) + eq = isa(other, "test_model.IntOrGenericRecordWithComputedFields") && isequal(self.index, other.index) && isequal(self.value, other.value); + end + + function ne = ne(self, other) + ne = ~self.eq(other); + end + + function t = tag(self) + tags_ = ["Int", "GenericRecordWithComputedFields"]; + t = tags_(self.index_); + end + end +end diff --git a/matlab/generated/+test_model/IntRank2Array.m b/matlab/generated/+test_model/IntRank2Array.m new file mode 100644 index 00000000..c043e267 --- /dev/null +++ b/matlab/generated/+test_model/IntRank2Array.m @@ -0,0 +1,8 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function a = IntRank2Array(array) + arguments + array int32 + end + a = array; +end diff --git a/matlab/generated/+test_model/MapOrScalar.m b/matlab/generated/+test_model/MapOrScalar.m new file mode 100644 index 00000000..6770a2de --- /dev/null +++ b/matlab/generated/+test_model/MapOrScalar.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MapOrScalar < yardl.Union + methods (Static) + function res = Map(value) + res = test_model.MapOrScalar(1, value); + end + + function res = Scalar(value) + res = test_model.MapOrScalar(2, value); + end + + function z = zeros(varargin) + elem = test_model.MapOrScalar(0, yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function res = isMap(self) + res = self.index == 1; + end + + function res = isScalar(self) + res = self.index == 2; + end + + function eq = eq(self, other) + eq = isa(other, "test_model.MapOrScalar") && isequal(self.index, other.index) && isequal(self.value, other.value); + end + + function ne = ne(self, other) + ne = ~self.eq(other); + end + + function t = tag(self) + tags_ = ["Map", "Scalar"]; + t = tags_(self.index_); + end + end +end diff --git a/matlab/generated/+test_model/MapsReaderBase.m b/matlab/generated/+test_model/MapsReaderBase.m new file mode 100644 index 00000000..05f9b0f3 --- /dev/null +++ b/matlab/generated/+test_model/MapsReaderBase.m @@ -0,0 +1,105 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MapsReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = MapsReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 4 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function value = read_string_to_int(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_string_to_int_(); + self.state_ = 1; + end + + % Ordinal 1 + function value = read_int_to_string(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_int_to_string_(); + self.state_ = 2; + end + + % Ordinal 2 + function value = read_string_to_union(self) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + value = self.read_string_to_union_(); + self.state_ = 3; + end + + % Ordinal 3 + function value = read_aliased_generic(self) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + value = self.read_aliased_generic_(); + self.state_ = 4; + end + + function copy_to(self, writer) + writer.write_string_to_int(self.read_string_to_int()); + writer.write_int_to_string(self.read_int_to_string()); + writer.write_string_to_union(self.read_string_to_union()); + writer.write_aliased_generic(self.read_aliased_generic()); + end + end + + methods (Static) + function res = schema() + res = test_model.MapsWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + read_string_to_int_(self) + read_int_to_string_(self) + read_string_to_union_(self) + read_aliased_generic_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_string_to_int"; + elseif state == 1 + name = "read_int_to_string"; + elseif state == 2 + name = "read_string_to_union"; + elseif state == 3 + name = "read_aliased_generic"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/MapsWriterBase.m b/matlab/generated/+test_model/MapsWriterBase.m new file mode 100644 index 00000000..ec91d127 --- /dev/null +++ b/matlab/generated/+test_model/MapsWriterBase.m @@ -0,0 +1,100 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol Maps +classdef (Abstract) MapsWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = MapsWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 4 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_string_to_int(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_string_to_int_(value); + self.state_ = 1; + end + + % Ordinal 1 + function write_int_to_string(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_int_to_string_(value); + self.state_ = 2; + end + + % Ordinal 2 + function write_string_to_union(self, value) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + self.write_string_to_union_(value); + self.state_ = 3; + end + + % Ordinal 3 + function write_aliased_generic(self, value) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + self.write_aliased_generic_(value); + self.state_ = 4; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"Maps","sequence":[{"name":"stringToInt","type":{"map":{"keys":"string","values":"int32"}}},{"name":"intToString","type":{"map":{"keys":"int32","values":"string"}}},{"name":"stringToUnion","type":{"map":{"keys":"string","values":[{"tag":"string","type":"string"},{"tag":"int32","type":"int32"}]}}},{"name":"aliasedGeneric","type":{"name":"BasicTypes.AliasedMap","typeArguments":["string","int32"]}}]},"types":[{"name":"AliasedMap","typeParameters":["K","V"],"type":{"map":{"keys":"K","values":"V"}}}]}'); + end + end + + methods (Abstract, Access=protected) + write_string_to_int_(self, value) + write_int_to_string_(self, value) + write_string_to_union_(self, value) + write_aliased_generic_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_string_to_int"; + elseif state == 1 + name = "write_int_to_string"; + elseif state == 2 + name = "write_string_to_union"; + elseif state == 3 + name = "write_aliased_generic"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/MultiDArraysReaderBase.m b/matlab/generated/+test_model/MultiDArraysReaderBase.m new file mode 100644 index 00000000..b6f4fe52 --- /dev/null +++ b/matlab/generated/+test_model/MultiDArraysReaderBase.m @@ -0,0 +1,107 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef MultiDArraysReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = MultiDArraysReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 2 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function more = has_images(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + more = self.has_images_(); + if ~more + self.state_ = 1; + end + end + + function value = read_images(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_images_(); + end + + % Ordinal 1 + function more = has_frames(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + more = self.has_frames_(); + if ~more + self.state_ = 2; + end + end + + function value = read_frames(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_frames_(); + end + + function copy_to(self, writer) + while self.has_images() + item = self.read_images(); + writer.write_images({item}); + end + writer.end_images(); + while self.has_frames() + item = self.read_frames(); + writer.write_frames({item}); + end + writer.end_frames(); + end + end + + methods (Static) + function res = schema() + res = test_model.MultiDArraysWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + has_images_(self) + read_images_(self) + has_frames_(self) + read_frames_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_images"; + elseif state == 1 + name = "read_frames"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/MultiDArraysWriterBase.m b/matlab/generated/+test_model/MultiDArraysWriterBase.m new file mode 100644 index 00000000..56d68085 --- /dev/null +++ b/matlab/generated/+test_model/MultiDArraysWriterBase.m @@ -0,0 +1,90 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol MultiDArrays +classdef (Abstract) MultiDArraysWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = MultiDArraysWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 2 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_images(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_images_(value); + end + + function end_images(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.end_stream_(); + self.state_ = 1; + end + + % Ordinal 1 + function write_frames(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_frames_(value); + end + + function end_frames(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.end_stream_(); + self.state_ = 2; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"MultiDArrays","sequence":[{"name":"images","type":{"stream":{"items":{"array":{"items":"float32","dimensions":[{"name":"ch"},{"name":"z"},{"name":"y"},{"name":"x"}]}}}}},{"name":"frames","type":{"stream":{"items":{"array":{"items":"float32","dimensions":[{"name":"ch","length":1},{"name":"z","length":1},{"name":"y","length":64},{"name":"x","length":32}]}}}}}]},"types":null}'); + end + end + + methods (Abstract, Access=protected) + write_images_(self, value) + write_frames_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_images or end_images"; + elseif state == 1 + name = "write_frames or end_frames"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/MyTuple.m b/matlab/generated/+test_model/MyTuple.m new file mode 100644 index 00000000..bb03cdf3 --- /dev/null +++ b/matlab/generated/+test_model/MyTuple.m @@ -0,0 +1,5 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function c = MyTuple(varargin) + c = basic_types.MyTuple(varargin{:}); +end diff --git a/matlab/generated/+test_model/NDArraysReaderBase.m b/matlab/generated/+test_model/NDArraysReaderBase.m new file mode 100644 index 00000000..b36dc83a --- /dev/null +++ b/matlab/generated/+test_model/NDArraysReaderBase.m @@ -0,0 +1,119 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef NDArraysReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = NDArraysReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 5 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function value = read_ints(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_ints_(); + self.state_ = 1; + end + + % Ordinal 1 + function value = read_simple_record_array(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_simple_record_array_(); + self.state_ = 2; + end + + % Ordinal 2 + function value = read_record_with_vlens_array(self) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + value = self.read_record_with_vlens_array_(); + self.state_ = 3; + end + + % Ordinal 3 + function value = read_record_with_nd_arrays(self) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + value = self.read_record_with_nd_arrays_(); + self.state_ = 4; + end + + % Ordinal 4 + function value = read_named_array(self) + if self.state_ ~= 4 + self.raise_unexpected_state_(4); + end + + value = self.read_named_array_(); + self.state_ = 5; + end + + function copy_to(self, writer) + writer.write_ints(self.read_ints()); + writer.write_simple_record_array(self.read_simple_record_array()); + writer.write_record_with_vlens_array(self.read_record_with_vlens_array()); + writer.write_record_with_nd_arrays(self.read_record_with_nd_arrays()); + writer.write_named_array(self.read_named_array()); + end + end + + methods (Static) + function res = schema() + res = test_model.NDArraysWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + read_ints_(self) + read_simple_record_array_(self) + read_record_with_vlens_array_(self) + read_record_with_nd_arrays_(self) + read_named_array_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_ints"; + elseif state == 1 + name = "read_simple_record_array"; + elseif state == 2 + name = "read_record_with_vlens_array"; + elseif state == 3 + name = "read_record_with_nd_arrays"; + elseif state == 4 + name = "read_named_array"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/NDArraysSingleDimensionReaderBase.m b/matlab/generated/+test_model/NDArraysSingleDimensionReaderBase.m new file mode 100644 index 00000000..52ff5c90 --- /dev/null +++ b/matlab/generated/+test_model/NDArraysSingleDimensionReaderBase.m @@ -0,0 +1,105 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef NDArraysSingleDimensionReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = NDArraysSingleDimensionReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 4 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function value = read_ints(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_ints_(); + self.state_ = 1; + end + + % Ordinal 1 + function value = read_simple_record_array(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_simple_record_array_(); + self.state_ = 2; + end + + % Ordinal 2 + function value = read_record_with_vlens_array(self) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + value = self.read_record_with_vlens_array_(); + self.state_ = 3; + end + + % Ordinal 3 + function value = read_record_with_nd_arrays(self) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + value = self.read_record_with_nd_arrays_(); + self.state_ = 4; + end + + function copy_to(self, writer) + writer.write_ints(self.read_ints()); + writer.write_simple_record_array(self.read_simple_record_array()); + writer.write_record_with_vlens_array(self.read_record_with_vlens_array()); + writer.write_record_with_nd_arrays(self.read_record_with_nd_arrays()); + end + end + + methods (Static) + function res = schema() + res = test_model.NDArraysSingleDimensionWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + read_ints_(self) + read_simple_record_array_(self) + read_record_with_vlens_array_(self) + read_record_with_nd_arrays_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_ints"; + elseif state == 1 + name = "read_simple_record_array"; + elseif state == 2 + name = "read_record_with_vlens_array"; + elseif state == 3 + name = "read_record_with_nd_arrays"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/NDArraysSingleDimensionWriterBase.m b/matlab/generated/+test_model/NDArraysSingleDimensionWriterBase.m new file mode 100644 index 00000000..5b1dbb9a --- /dev/null +++ b/matlab/generated/+test_model/NDArraysSingleDimensionWriterBase.m @@ -0,0 +1,100 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol NDArraysSingleDimension +classdef (Abstract) NDArraysSingleDimensionWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = NDArraysSingleDimensionWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 4 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_ints(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_ints_(value); + self.state_ = 1; + end + + % Ordinal 1 + function write_simple_record_array(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_simple_record_array_(value); + self.state_ = 2; + end + + % Ordinal 2 + function write_record_with_vlens_array(self, value) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + self.write_record_with_vlens_array_(value); + self.state_ = 3; + end + + % Ordinal 3 + function write_record_with_nd_arrays(self, value) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + self.write_record_with_nd_arrays_(value); + self.state_ = 4; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"NDArraysSingleDimension","sequence":[{"name":"ints","type":{"array":{"items":"int32","dimensions":1}}},{"name":"simpleRecordArray","type":{"array":{"items":"TestModel.SimpleRecord","dimensions":1}}},{"name":"recordWithVlensArray","type":{"array":{"items":"TestModel.RecordWithVlens","dimensions":1}}},{"name":"recordWithNDArrays","type":"TestModel.RecordWithNDArraysSingleDimension"}]},"types":[{"name":"RecordWithNDArraysSingleDimension","fields":[{"name":"ints","type":{"array":{"items":"int32","dimensions":1}}},{"name":"fixedSimpleRecordArray","type":{"array":{"items":"TestModel.SimpleRecord","dimensions":1}}},{"name":"fixedRecordWithVlensArray","type":{"array":{"items":"TestModel.RecordWithVlens","dimensions":1}}}]},{"name":"RecordWithVlens","fields":[{"name":"a","type":{"vector":{"items":"TestModel.SimpleRecord"}}},{"name":"b","type":"int32"},{"name":"c","type":"int32"}]},{"name":"SimpleRecord","fields":[{"name":"x","type":"int32"},{"name":"y","type":"int32"},{"name":"z","type":"int32"}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_ints_(self, value) + write_simple_record_array_(self, value) + write_record_with_vlens_array_(self, value) + write_record_with_nd_arrays_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_ints"; + elseif state == 1 + name = "write_simple_record_array"; + elseif state == 2 + name = "write_record_with_vlens_array"; + elseif state == 3 + name = "write_record_with_nd_arrays"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/NDArraysWriterBase.m b/matlab/generated/+test_model/NDArraysWriterBase.m new file mode 100644 index 00000000..d8ed7e3b --- /dev/null +++ b/matlab/generated/+test_model/NDArraysWriterBase.m @@ -0,0 +1,113 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol NDArrays +classdef (Abstract) NDArraysWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = NDArraysWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 5 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_ints(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_ints_(value); + self.state_ = 1; + end + + % Ordinal 1 + function write_simple_record_array(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_simple_record_array_(value); + self.state_ = 2; + end + + % Ordinal 2 + function write_record_with_vlens_array(self, value) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + self.write_record_with_vlens_array_(value); + self.state_ = 3; + end + + % Ordinal 3 + function write_record_with_nd_arrays(self, value) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + self.write_record_with_nd_arrays_(value); + self.state_ = 4; + end + + % Ordinal 4 + function write_named_array(self, value) + if self.state_ ~= 4 + self.raise_unexpected_state_(4); + end + + self.write_named_array_(value); + self.state_ = 5; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"NDArrays","sequence":[{"name":"ints","type":{"array":{"items":"int32","dimensions":2}}},{"name":"simpleRecordArray","type":{"array":{"items":"TestModel.SimpleRecord","dimensions":2}}},{"name":"recordWithVlensArray","type":{"array":{"items":"TestModel.RecordWithVlens","dimensions":2}}},{"name":"recordWithNDArrays","type":"TestModel.RecordWithNDArrays"},{"name":"namedArray","type":"TestModel.NamedNDArray"}]},"types":[{"name":"NamedNDArray","type":{"array":{"items":"int32","dimensions":[{"name":"dimA"},{"name":"dimB"}]}}},{"name":"RecordWithNDArrays","fields":[{"name":"ints","type":{"array":{"items":"int32","dimensions":2}}},{"name":"fixedSimpleRecordArray","type":{"array":{"items":"TestModel.SimpleRecord","dimensions":2}}},{"name":"fixedRecordWithVlensArray","type":{"array":{"items":"TestModel.RecordWithVlens","dimensions":2}}}]},{"name":"RecordWithVlens","fields":[{"name":"a","type":{"vector":{"items":"TestModel.SimpleRecord"}}},{"name":"b","type":"int32"},{"name":"c","type":"int32"}]},{"name":"SimpleRecord","fields":[{"name":"x","type":"int32"},{"name":"y","type":"int32"},{"name":"z","type":"int32"}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_ints_(self, value) + write_simple_record_array_(self, value) + write_record_with_vlens_array_(self, value) + write_record_with_nd_arrays_(self, value) + write_named_array_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_ints"; + elseif state == 1 + name = "write_simple_record_array"; + elseif state == 2 + name = "write_record_with_vlens_array"; + elseif state == 3 + name = "write_record_with_nd_arrays"; + elseif state == 4 + name = "write_named_array"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/NamedFixedNDArray.m b/matlab/generated/+test_model/NamedFixedNDArray.m new file mode 100644 index 00000000..ea3bd33d --- /dev/null +++ b/matlab/generated/+test_model/NamedFixedNDArray.m @@ -0,0 +1,8 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function a = NamedFixedNDArray(array) + arguments + array int32 + end + a = array; +end diff --git a/matlab/generated/+test_model/NamedNDArray.m b/matlab/generated/+test_model/NamedNDArray.m new file mode 100644 index 00000000..95fd517d --- /dev/null +++ b/matlab/generated/+test_model/NamedNDArray.m @@ -0,0 +1,8 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function a = NamedNDArray(array) + arguments + array int32 + end + a = array; +end diff --git a/matlab/generated/+test_model/NestedRecordsReaderBase.m b/matlab/generated/+test_model/NestedRecordsReaderBase.m new file mode 100644 index 00000000..4267b57b --- /dev/null +++ b/matlab/generated/+test_model/NestedRecordsReaderBase.m @@ -0,0 +1,63 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef NestedRecordsReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = NestedRecordsReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 1 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function value = read_tuple_with_records(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_tuple_with_records_(); + self.state_ = 1; + end + + function copy_to(self, writer) + writer.write_tuple_with_records(self.read_tuple_with_records()); + end + end + + methods (Static) + function res = schema() + res = test_model.NestedRecordsWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + read_tuple_with_records_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_tuple_with_records"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/NestedRecordsWriterBase.m b/matlab/generated/+test_model/NestedRecordsWriterBase.m new file mode 100644 index 00000000..2751f5ef --- /dev/null +++ b/matlab/generated/+test_model/NestedRecordsWriterBase.m @@ -0,0 +1,61 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol NestedRecords +classdef (Abstract) NestedRecordsWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = NestedRecordsWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 1 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_tuple_with_records(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_tuple_with_records_(value); + self.state_ = 1; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"NestedRecords","sequence":[{"name":"tupleWithRecords","type":"TestModel.TupleWithRecords"}]},"types":[{"name":"SimpleRecord","fields":[{"name":"x","type":"int32"},{"name":"y","type":"int32"},{"name":"z","type":"int32"}]},{"name":"TupleWithRecords","fields":[{"name":"a","type":"TestModel.SimpleRecord"},{"name":"b","type":"TestModel.SimpleRecord"}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_tuple_with_records_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_tuple_with_records"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/OptionalVectorsReaderBase.m b/matlab/generated/+test_model/OptionalVectorsReaderBase.m new file mode 100644 index 00000000..73d65774 --- /dev/null +++ b/matlab/generated/+test_model/OptionalVectorsReaderBase.m @@ -0,0 +1,63 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef OptionalVectorsReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = OptionalVectorsReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 1 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function value = read_record_with_optional_vector(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_record_with_optional_vector_(); + self.state_ = 1; + end + + function copy_to(self, writer) + writer.write_record_with_optional_vector(self.read_record_with_optional_vector()); + end + end + + methods (Static) + function res = schema() + res = test_model.OptionalVectorsWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + read_record_with_optional_vector_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_record_with_optional_vector"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/OptionalVectorsWriterBase.m b/matlab/generated/+test_model/OptionalVectorsWriterBase.m new file mode 100644 index 00000000..be314f03 --- /dev/null +++ b/matlab/generated/+test_model/OptionalVectorsWriterBase.m @@ -0,0 +1,61 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol OptionalVectors +classdef (Abstract) OptionalVectorsWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = OptionalVectorsWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 1 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_record_with_optional_vector(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_record_with_optional_vector_(value); + self.state_ = 1; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"OptionalVectors","sequence":[{"name":"recordWithOptionalVector","type":"TestModel.RecordWithOptionalVector"}]},"types":[{"name":"RecordWithOptionalVector","fields":[{"name":"optionalVector","type":[null,{"vector":{"items":"int32"}}]}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_record_with_optional_vector_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_record_with_optional_vector"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/ProtocolWithComputedFieldsReaderBase.m b/matlab/generated/+test_model/ProtocolWithComputedFieldsReaderBase.m new file mode 100644 index 00000000..1619dea3 --- /dev/null +++ b/matlab/generated/+test_model/ProtocolWithComputedFieldsReaderBase.m @@ -0,0 +1,63 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef ProtocolWithComputedFieldsReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = ProtocolWithComputedFieldsReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 1 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function value = read_record_with_computed_fields(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_record_with_computed_fields_(); + self.state_ = 1; + end + + function copy_to(self, writer) + writer.write_record_with_computed_fields(self.read_record_with_computed_fields()); + end + end + + methods (Static) + function res = schema() + res = test_model.ProtocolWithComputedFieldsWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + read_record_with_computed_fields_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_record_with_computed_fields"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/ProtocolWithComputedFieldsWriterBase.m b/matlab/generated/+test_model/ProtocolWithComputedFieldsWriterBase.m new file mode 100644 index 00000000..83d59ee2 --- /dev/null +++ b/matlab/generated/+test_model/ProtocolWithComputedFieldsWriterBase.m @@ -0,0 +1,61 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol ProtocolWithComputedFields +classdef (Abstract) ProtocolWithComputedFieldsWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = ProtocolWithComputedFieldsWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 1 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_record_with_computed_fields(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_record_with_computed_fields_(value); + self.state_ = 1; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"ProtocolWithComputedFields","sequence":[{"name":"recordWithComputedFields","type":"TestModel.RecordWithComputedFields"}]},"types":[{"name":"GenericRecordWithComputedFields","typeParameters":["T0","T1"],"fields":[{"name":"f1","type":[{"tag":"T0","type":"T0"},{"tag":"T1","type":"T1"}]}]},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"Tuples.Tuple","typeArguments":["T1","T2"]}},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"BasicTypes.MyTuple","typeArguments":["T1","T2"]}},{"name":"NamedNDArray","type":{"array":{"items":"int32","dimensions":[{"name":"dimA"},{"name":"dimB"}]}}},{"name":"RecordWithComputedFields","fields":[{"name":"arrayField","type":{"array":{"items":"int32","dimensions":[{"name":"x"},{"name":"y"}]}}},{"name":"arrayFieldMapDimensions","type":{"array":{"items":"int32","dimensions":[{"name":"x"},{"name":"y"}]}}},{"name":"dynamicArrayField","type":{"array":{"items":"int32"}}},{"name":"fixedArrayField","type":{"array":{"items":"int32","dimensions":[{"name":"x","length":3},{"name":"y","length":4}]}}},{"name":"intField","type":"int32"},{"name":"int8Field","type":"int8"},{"name":"uint8Field","type":"uint8"},{"name":"int16Field","type":"int16"},{"name":"uint16Field","type":"uint16"},{"name":"uint32Field","type":"uint32"},{"name":"int64Field","type":"int64"},{"name":"uint64Field","type":"uint64"},{"name":"sizeField","type":"size"},{"name":"float32Field","type":"float32"},{"name":"float64Field","type":"float64"},{"name":"complexfloat32Field","type":"complexfloat32"},{"name":"complexfloat64Field","type":"complexfloat64"},{"name":"stringField","type":"string"},{"name":"tupleField","type":{"name":"TestModel.MyTuple","typeArguments":["int32","int32"]}},{"name":"vectorField","type":{"vector":{"items":"int32"}}},{"name":"vectorOfVectorsField","type":{"vector":{"items":{"vector":{"items":"int32"}}}}},{"name":"fixedVectorField","type":{"vector":{"items":"int32","length":3}}},{"name":"fixedVectorOfVectorsField","type":{"vector":{"items":{"vector":{"items":"int32","length":3}},"length":2}}},{"name":"optionalNamedArray","type":[null,"TestModel.NamedNDArray"]},{"name":"intFloatUnion","type":[{"tag":"int32","type":"int32"},{"tag":"float32","type":"float32"}]},{"name":"nullableIntFloatUnion","type":[null,{"tag":"int32","type":"int32"},{"tag":"float32","type":"float32"}]},{"name":"unionWithNestedGenericUnion","type":[{"tag":"int","explicitTag":true,"type":"int32"},{"tag":"genericRecordWithComputedFields","explicitTag":true,"type":{"name":"BasicTypes.GenericRecordWithComputedFields","typeArguments":["string","float32"]}}]},{"name":"mapField","type":{"map":{"keys":"string","values":"string"}}}]},{"name":"Tuple","typeParameters":["T1","T2"],"fields":[{"name":"v1","type":"T1"},{"name":"v2","type":"T2"}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_record_with_computed_fields_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_record_with_computed_fields"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/ProtocolWithKeywordStepsReaderBase.m b/matlab/generated/+test_model/ProtocolWithKeywordStepsReaderBase.m new file mode 100644 index 00000000..55fbe654 --- /dev/null +++ b/matlab/generated/+test_model/ProtocolWithKeywordStepsReaderBase.m @@ -0,0 +1,92 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef ProtocolWithKeywordStepsReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = ProtocolWithKeywordStepsReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 2 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function more = has_int(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + more = self.has_int_(); + if ~more + self.state_ = 1; + end + end + + function value = read_int(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_int_(); + end + + % Ordinal 1 + function value = read_float(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_float_(); + self.state_ = 2; + end + + function copy_to(self, writer) + while self.has_int() + item = self.read_int(); + writer.write_int({item}); + end + writer.end_int(); + writer.write_float(self.read_float()); + end + end + + methods (Static) + function res = schema() + res = test_model.ProtocolWithKeywordStepsWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + has_int_(self) + read_int_(self) + read_float_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_int"; + elseif state == 1 + name = "read_float"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/ProtocolWithKeywordStepsWriterBase.m b/matlab/generated/+test_model/ProtocolWithKeywordStepsWriterBase.m new file mode 100644 index 00000000..ea5b7476 --- /dev/null +++ b/matlab/generated/+test_model/ProtocolWithKeywordStepsWriterBase.m @@ -0,0 +1,82 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol ProtocolWithKeywordSteps +classdef (Abstract) ProtocolWithKeywordStepsWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = ProtocolWithKeywordStepsWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 2 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_int(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_int_(value); + end + + function end_int(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.end_stream_(); + self.state_ = 1; + end + + % Ordinal 1 + function write_float(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_float_(value); + self.state_ = 2; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"ProtocolWithKeywordSteps","sequence":[{"name":"int","type":{"stream":{"items":"TestModel.RecordWithKeywordFields"}}},{"name":"float","type":"TestModel.EnumWithKeywordSymbols"}]},"types":[{"name":"ArrayWithKeywordDimensionNames","type":{"array":{"items":"int32","dimensions":[{"name":"while"},{"name":"do"}]}}},{"name":"EnumWithKeywordSymbols","values":[{"symbol":"try","value":2},{"symbol":"catch","value":1}]},{"name":"RecordWithKeywordFields","fields":[{"name":"int","type":"string"},{"name":"sizeof","type":"TestModel.ArrayWithKeywordDimensionNames"},{"name":"if","type":"TestModel.EnumWithKeywordSymbols"}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_int_(self, value) + write_float_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_int or end_int"; + elseif state == 1 + name = "write_float"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/RecordContainingGenericRecords.m b/matlab/generated/+test_model/RecordContainingGenericRecords.m new file mode 100644 index 00000000..9633ba75 --- /dev/null +++ b/matlab/generated/+test_model/RecordContainingGenericRecords.m @@ -0,0 +1,78 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordContainingGenericRecords < handle + properties + g1 + g1a + g2 + g2a + g3 + g3a + g4 + g5 + g6 + g7 + end + + methods + function self = RecordContainingGenericRecords(kwargs) + arguments + kwargs.g1 = test_model.RecordWithOptionalGenericField(); + kwargs.g1a = test_model.RecordWithAliasedOptionalGenericField(); + kwargs.g2 = test_model.RecordWithOptionalGenericUnionField(); + kwargs.g2a = test_model.RecordWithAliasedOptionalGenericUnionField(); + kwargs.g3; + kwargs.g3a; + kwargs.g4; + kwargs.g5; + kwargs.g6; + kwargs.g7 = test_model.RecordWithGenericMaps(); + end + self.g1 = kwargs.g1; + self.g1a = kwargs.g1a; + self.g2 = kwargs.g2; + self.g2a = kwargs.g2a; + if ~isfield(kwargs, "g3") + throw(yardl.TypeError("Missing required keyword argument 'g3'")) + end + self.g3 = kwargs.g3; + if ~isfield(kwargs, "g3a") + throw(yardl.TypeError("Missing required keyword argument 'g3a'")) + end + self.g3a = kwargs.g3a; + if ~isfield(kwargs, "g4") + throw(yardl.TypeError("Missing required keyword argument 'g4'")) + end + self.g4 = kwargs.g4; + if ~isfield(kwargs, "g5") + throw(yardl.TypeError("Missing required keyword argument 'g5'")) + end + self.g5 = kwargs.g5; + if ~isfield(kwargs, "g6") + throw(yardl.TypeError("Missing required keyword argument 'g6'")) + end + self.g6 = kwargs.g6; + self.g7 = kwargs.g7; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordContainingGenericRecords") && ... + isequal(self.g1, other.g1) && ... + isequal(self.g1a, other.g1a) && ... + isequal(self.g2, other.g2) && ... + isequal(self.g2a, other.g2a) && ... + isequal(self.g3, other.g3) && ... + isequal(self.g3a, other.g3a) && ... + isequal(self.g4, other.g4) && ... + isequal(self.g5, other.g5) && ... + isequal(self.g6, other.g6) && ... + isequal(self.g7, other.g7); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + +end diff --git a/matlab/generated/+test_model/RecordContainingNestedGenericRecords.m b/matlab/generated/+test_model/RecordContainingNestedGenericRecords.m new file mode 100644 index 00000000..aeaa92b3 --- /dev/null +++ b/matlab/generated/+test_model/RecordContainingNestedGenericRecords.m @@ -0,0 +1,57 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordContainingNestedGenericRecords < handle + properties + f1 + f1a + f2 + f2a + nested + end + + methods + function self = RecordContainingNestedGenericRecords(kwargs) + arguments + kwargs.f1 = test_model.RecordWithOptionalGenericField(); + kwargs.f1a = test_model.RecordWithAliasedOptionalGenericField(); + kwargs.f2 = test_model.RecordWithOptionalGenericUnionField(); + kwargs.f2a = test_model.RecordWithAliasedOptionalGenericUnionField(); + kwargs.nested = test_model.RecordContainingGenericRecords(g3=tuples.Tuple(v1="", v2=int32(0)), g3a=tuples.Tuple(v1="", v2=int32(0)), g4=test_model.RecordWithGenericVectors(v=int32.empty(), av=int32.empty()), g5=test_model.RecordWithGenericFixedVectors(fv=repelem(int32(0), 3), afv=repelem(int32(0), 3)), g6=test_model.RecordWithGenericArrays(nd=int32.empty(0, 0), fixed_nd=repelem(int32(0), 8, 16), dynamic_nd=int32.empty(), aliased_nd=int32.empty(0, 0), aliased_fixed_nd=repelem(int32(0), 8, 16), aliased_dynamic_nd=int32.empty())); + end + self.f1 = kwargs.f1; + self.f1a = kwargs.f1a; + self.f2 = kwargs.f2; + self.f2a = kwargs.f2a; + self.nested = kwargs.nested; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordContainingNestedGenericRecords") && ... + isequal(self.f1, other.f1) && ... + isequal(self.f1a, other.f1a) && ... + isequal(self.f2, other.f2) && ... + isequal(self.f2a, other.f2a) && ... + isequal(self.nested, other.nested); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordContainingNestedGenericRecords(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordNotUsedInProtocol.m b/matlab/generated/+test_model/RecordNotUsedInProtocol.m new file mode 100644 index 00000000..53cdef1c --- /dev/null +++ b/matlab/generated/+test_model/RecordNotUsedInProtocol.m @@ -0,0 +1,45 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordNotUsedInProtocol < handle + properties + u1 + u2 + end + + methods + function self = RecordNotUsedInProtocol(kwargs) + arguments + kwargs.u1 = test_model.GenericUnion3.T(int32(0)); + kwargs.u2 = test_model.GenericUnion3Alternate.U(int32(0)); + end + self.u1 = kwargs.u1; + self.u2 = kwargs.u2; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordNotUsedInProtocol") && ... + isequal(self.u1, other.u1) && ... + isequal(self.u2, other.u2); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordNotUsedInProtocol(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithAliasedGenerics.m b/matlab/generated/+test_model/RecordWithAliasedGenerics.m new file mode 100644 index 00000000..68c0e8cc --- /dev/null +++ b/matlab/generated/+test_model/RecordWithAliasedGenerics.m @@ -0,0 +1,45 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithAliasedGenerics < handle + properties + my_strings + aliased_strings + end + + methods + function self = RecordWithAliasedGenerics(kwargs) + arguments + kwargs.my_strings = tuples.Tuple(v1="", v2=""); + kwargs.aliased_strings = tuples.Tuple(v1="", v2=""); + end + self.my_strings = kwargs.my_strings; + self.aliased_strings = kwargs.aliased_strings; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithAliasedGenerics") && ... + isequal(self.my_strings, other.my_strings) && ... + isequal(self.aliased_strings, other.aliased_strings); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithAliasedGenerics(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithAliasedOptionalGenericField.m b/matlab/generated/+test_model/RecordWithAliasedOptionalGenericField.m new file mode 100644 index 00000000..da3619e2 --- /dev/null +++ b/matlab/generated/+test_model/RecordWithAliasedOptionalGenericField.m @@ -0,0 +1,41 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithAliasedOptionalGenericField < handle + properties + v + end + + methods + function self = RecordWithAliasedOptionalGenericField(kwargs) + arguments + kwargs.v = yardl.None; + end + self.v = kwargs.v; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithAliasedOptionalGenericField") && ... + isequal(self.v, other.v); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithAliasedOptionalGenericField(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithAliasedOptionalGenericUnionField.m b/matlab/generated/+test_model/RecordWithAliasedOptionalGenericUnionField.m new file mode 100644 index 00000000..d4ff5cbe --- /dev/null +++ b/matlab/generated/+test_model/RecordWithAliasedOptionalGenericUnionField.m @@ -0,0 +1,41 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithAliasedOptionalGenericUnionField < handle + properties + v + end + + methods + function self = RecordWithAliasedOptionalGenericUnionField(kwargs) + arguments + kwargs.v = yardl.None; + end + self.v = kwargs.v; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithAliasedOptionalGenericUnionField") && ... + isequal(self.v, other.v); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithAliasedOptionalGenericUnionField(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithArrays.m b/matlab/generated/+test_model/RecordWithArrays.m new file mode 100644 index 00000000..1302988f --- /dev/null +++ b/matlab/generated/+test_model/RecordWithArrays.m @@ -0,0 +1,73 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithArrays < handle + properties + default_array + default_array_with_empty_dimension + rank_1_array + rank_2_array + rank_2_array_with_named_dimensions + rank_2_fixed_array + rank_2_fixed_array_with_named_dimensions + dynamic_array + array_of_vectors + end + + methods + function self = RecordWithArrays(kwargs) + arguments + kwargs.default_array = int32.empty(); + kwargs.default_array_with_empty_dimension = int32.empty(); + kwargs.rank_1_array = int32.empty(0); + kwargs.rank_2_array = int32.empty(0, 0); + kwargs.rank_2_array_with_named_dimensions = int32.empty(0, 0); + kwargs.rank_2_fixed_array = repelem(int32(0), 4, 3); + kwargs.rank_2_fixed_array_with_named_dimensions = repelem(int32(0), 4, 3); + kwargs.dynamic_array = int32.empty(); + kwargs.array_of_vectors = repelem(repelem(int32(0), 4), 5, 1); + end + self.default_array = kwargs.default_array; + self.default_array_with_empty_dimension = kwargs.default_array_with_empty_dimension; + self.rank_1_array = kwargs.rank_1_array; + self.rank_2_array = kwargs.rank_2_array; + self.rank_2_array_with_named_dimensions = kwargs.rank_2_array_with_named_dimensions; + self.rank_2_fixed_array = kwargs.rank_2_fixed_array; + self.rank_2_fixed_array_with_named_dimensions = kwargs.rank_2_fixed_array_with_named_dimensions; + self.dynamic_array = kwargs.dynamic_array; + self.array_of_vectors = kwargs.array_of_vectors; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithArrays") && ... + isequal(self.default_array, other.default_array) && ... + isequal(self.default_array_with_empty_dimension, other.default_array_with_empty_dimension) && ... + isequal(self.rank_1_array, other.rank_1_array) && ... + isequal(self.rank_2_array, other.rank_2_array) && ... + isequal(self.rank_2_array_with_named_dimensions, other.rank_2_array_with_named_dimensions) && ... + isequal(self.rank_2_fixed_array, other.rank_2_fixed_array) && ... + isequal(self.rank_2_fixed_array_with_named_dimensions, other.rank_2_fixed_array_with_named_dimensions) && ... + isequal(self.dynamic_array, other.dynamic_array) && ... + isequal(self.array_of_vectors, other.array_of_vectors); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithArrays(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithArraysSimpleSyntax.m b/matlab/generated/+test_model/RecordWithArraysSimpleSyntax.m new file mode 100644 index 00000000..8a3a6d2d --- /dev/null +++ b/matlab/generated/+test_model/RecordWithArraysSimpleSyntax.m @@ -0,0 +1,73 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithArraysSimpleSyntax < handle + properties + default_array + default_array_with_empty_dimension + rank_1_array + rank_2_array + rank_2_array_with_named_dimensions + rank_2_fixed_array + rank_2_fixed_array_with_named_dimensions + dynamic_array + array_of_vectors + end + + methods + function self = RecordWithArraysSimpleSyntax(kwargs) + arguments + kwargs.default_array = int32.empty(); + kwargs.default_array_with_empty_dimension = int32.empty(); + kwargs.rank_1_array = int32.empty(0); + kwargs.rank_2_array = int32.empty(0, 0); + kwargs.rank_2_array_with_named_dimensions = int32.empty(0, 0); + kwargs.rank_2_fixed_array = repelem(int32(0), 4, 3); + kwargs.rank_2_fixed_array_with_named_dimensions = repelem(int32(0), 4, 3); + kwargs.dynamic_array = int32.empty(); + kwargs.array_of_vectors = repelem(repelem(int32(0), 4), 5, 1); + end + self.default_array = kwargs.default_array; + self.default_array_with_empty_dimension = kwargs.default_array_with_empty_dimension; + self.rank_1_array = kwargs.rank_1_array; + self.rank_2_array = kwargs.rank_2_array; + self.rank_2_array_with_named_dimensions = kwargs.rank_2_array_with_named_dimensions; + self.rank_2_fixed_array = kwargs.rank_2_fixed_array; + self.rank_2_fixed_array_with_named_dimensions = kwargs.rank_2_fixed_array_with_named_dimensions; + self.dynamic_array = kwargs.dynamic_array; + self.array_of_vectors = kwargs.array_of_vectors; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithArraysSimpleSyntax") && ... + isequal(self.default_array, other.default_array) && ... + isequal(self.default_array_with_empty_dimension, other.default_array_with_empty_dimension) && ... + isequal(self.rank_1_array, other.rank_1_array) && ... + isequal(self.rank_2_array, other.rank_2_array) && ... + isequal(self.rank_2_array_with_named_dimensions, other.rank_2_array_with_named_dimensions) && ... + isequal(self.rank_2_fixed_array, other.rank_2_fixed_array) && ... + isequal(self.rank_2_fixed_array_with_named_dimensions, other.rank_2_fixed_array_with_named_dimensions) && ... + isequal(self.dynamic_array, other.dynamic_array) && ... + isequal(self.array_of_vectors, other.array_of_vectors); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithArraysSimpleSyntax(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithComputedFields.m b/matlab/generated/+test_model/RecordWithComputedFields.m new file mode 100644 index 00000000..a278ba6a --- /dev/null +++ b/matlab/generated/+test_model/RecordWithComputedFields.m @@ -0,0 +1,579 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithComputedFields < handle + properties + array_field + array_field_map_dimensions + dynamic_array_field + fixed_array_field + int_field + int8_field + uint8_field + int16_field + uint16_field + uint32_field + int64_field + uint64_field + size_field + float32_field + float64_field + complexfloat32_field + complexfloat64_field + string_field + tuple_field + vector_field + vector_of_vectors_field + fixed_vector_field + fixed_vector_of_vectors_field + optional_named_array + int_float_union + nullable_int_float_union + union_with_nested_generic_union + map_field + end + + methods + function self = RecordWithComputedFields(kwargs) + arguments + kwargs.array_field = int32.empty(0, 0); + kwargs.array_field_map_dimensions = int32.empty(0, 0); + kwargs.dynamic_array_field = int32.empty(); + kwargs.fixed_array_field = repelem(int32(0), 4, 3); + kwargs.int_field = int32(0); + kwargs.int8_field = int8(0); + kwargs.uint8_field = uint8(0); + kwargs.int16_field = int16(0); + kwargs.uint16_field = uint16(0); + kwargs.uint32_field = uint32(0); + kwargs.int64_field = int64(0); + kwargs.uint64_field = uint64(0); + kwargs.size_field = uint64(0); + kwargs.float32_field = single(0); + kwargs.float64_field = double(0); + kwargs.complexfloat32_field = complex(single(0)); + kwargs.complexfloat64_field = complex(0); + kwargs.string_field = ""; + kwargs.tuple_field = tuples.Tuple(v1=int32(0), v2=int32(0)); + kwargs.vector_field = int32.empty(); + kwargs.vector_of_vectors_field = int32.empty(); + kwargs.fixed_vector_field = repelem(int32(0), 3); + kwargs.fixed_vector_of_vectors_field = repelem({repelem(int32(0), 3)}, 2); + kwargs.optional_named_array = yardl.None; + kwargs.int_float_union = test_model.Int32OrFloat32.Int32(int32(0)); + kwargs.nullable_int_float_union = yardl.None; + kwargs.union_with_nested_generic_union = test_model.IntOrGenericRecordWithComputedFields.Int(int32(0)); + kwargs.map_field = dictionary; + end + self.array_field = kwargs.array_field; + self.array_field_map_dimensions = kwargs.array_field_map_dimensions; + self.dynamic_array_field = kwargs.dynamic_array_field; + self.fixed_array_field = kwargs.fixed_array_field; + self.int_field = kwargs.int_field; + self.int8_field = kwargs.int8_field; + self.uint8_field = kwargs.uint8_field; + self.int16_field = kwargs.int16_field; + self.uint16_field = kwargs.uint16_field; + self.uint32_field = kwargs.uint32_field; + self.int64_field = kwargs.int64_field; + self.uint64_field = kwargs.uint64_field; + self.size_field = kwargs.size_field; + self.float32_field = kwargs.float32_field; + self.float64_field = kwargs.float64_field; + self.complexfloat32_field = kwargs.complexfloat32_field; + self.complexfloat64_field = kwargs.complexfloat64_field; + self.string_field = kwargs.string_field; + self.tuple_field = kwargs.tuple_field; + self.vector_field = kwargs.vector_field; + self.vector_of_vectors_field = kwargs.vector_of_vectors_field; + self.fixed_vector_field = kwargs.fixed_vector_field; + self.fixed_vector_of_vectors_field = kwargs.fixed_vector_of_vectors_field; + self.optional_named_array = kwargs.optional_named_array; + self.int_float_union = kwargs.int_float_union; + self.nullable_int_float_union = kwargs.nullable_int_float_union; + self.union_with_nested_generic_union = kwargs.union_with_nested_generic_union; + self.map_field = kwargs.map_field; + end + + function res = int_literal(self) + res = 42; + return + end + + function res = large_negative_int64_literal(self) + res = -4611686018427387904; + return + end + + function res = large_u_int64_literal(self) + res = 9223372036854775808; + return + end + + function res = string_literal(self) + res = "hello"; + return + end + + function res = string_literal_2(self) + res = "hello"; + return + end + + function res = string_literal_3(self) + res = "hello"; + return + end + + function res = string_literal_4(self) + res = "hello"; + return + end + + function res = access_other_computed_field(self) + res = self.int_field; + return + end + + function res = access_int_field(self) + res = self.int_field; + return + end + + function res = access_string_field(self) + res = self.string_field; + return + end + + function res = access_tuple_field(self) + res = self.tuple_field; + return + end + + function res = access_nested_tuple_field(self) + res = self.tuple_field.v2; + return + end + + function res = access_array_field(self) + res = self.array_field; + return + end + + function res = access_array_field_element(self) + res = self.array_field(1+1, 1+0); + return + end + + function res = access_array_field_element_by_name(self) + res = self.array_field(1+1, 1+0); + return + end + + function res = access_vector_field(self) + res = self.vector_field; + return + end + + function res = access_vector_field_element(self) + res = self.vector_field(1+1); + return + end + + function res = access_vector_of_vectors_field(self) + res = self.vector_of_vectors_field(1+2, 1+1); + return + end + + function res = access_fixed_vector_of_vectors_field(self) + res = self.fixed_vector_of_vectors_field(1+2, 1+1); + return + end + + function res = array_size(self) + res = numel(self.array_field); + return + end + + function res = array_x_size(self) + res = size(self.array_field, ndims(self.array_field)-(0)); + return + end + + function res = array_y_size(self) + res = size(self.array_field, ndims(self.array_field)-(1)); + return + end + + function res = array_0_size(self) + res = size(self.array_field, ndims(self.array_field)-(0)); + return + end + + function res = array_1_size(self) + res = size(self.array_field, ndims(self.array_field)-(1)); + return + end + + function res = array_size_from_int_field(self) + res = size(self.array_field, ndims(self.array_field)-(self.int_field)); + return + end + + function res = array_size_from_string_field(self) + function dim = helper_0_(dim_name) + if dim_name == "x" + dim = 0; + elseif dim_name == "y" + dim = 1; + else + throw(yardl.ValueError("Unknown dimension name: '%s'", dim_name)); + end + + end + res = size(self.array_field, ndims(self.array_field)-(helper_0_(self.string_field))); + return + end + + function res = array_size_from_nested_int_field(self) + res = size(self.array_field, ndims(self.array_field)-(self.tuple_field.v1)); + return + end + + function res = array_field_map_dimensions_x_size(self) + res = size(self.array_field_map_dimensions, ndims(self.array_field_map_dimensions)-(0)); + return + end + + function res = fixed_array_size(self) + res = 12; + return + end + + function res = fixed_array_x_size(self) + res = 3; + return + end + + function res = fixed_array_0_size(self) + res = 3; + return + end + + function res = vector_size(self) + res = length(self.vector_field); + return + end + + function res = fixed_vector_size(self) + res = 3; + return + end + + function res = fixed_vector_of_vectors_size(self) + res = 2; + return + end + + function res = array_dimension_x_index(self) + res = 0; + return + end + + function res = array_dimension_y_index(self) + res = 1; + return + end + + function res = array_dimension_index_from_string_field(self) + function dim = helper_0_(dim_name) + if dim_name == "x" + dim = 0; + elseif dim_name == "y" + dim = 1; + else + throw(yardl.ValueError("Unknown dimension name: '%s'", dim_name)); + end + + end + res = helper_0_(self.string_field); + return + end + + function res = array_dimension_count(self) + res = 2; + return + end + + function res = dynamic_array_dimension_count(self) + res = yardl.dimension_count(self.dynamic_array_field); + return + end + + function res = access_map(self) + res = self.map_field; + return + end + + function res = map_size(self) + res = numEntries(self.map_field); + return + end + + function res = access_map_entry(self) + res = self.map_field("hello"); + return + end + + function res = string_computed_field(self) + res = "hello"; + return + end + + function res = access_map_entry_with_computed_field(self) + res = self.map_field(self.string_computed_field()); + return + end + + function res = access_map_entry_with_computed_field_nested(self) + res = self.map_field(self.map_field(self.string_computed_field())); + return + end + + function res = access_missing_map_entry(self) + res = self.map_field("missing"); + return + end + + function res = optional_named_array_length(self) + var1 = self.optional_named_array; + if var1 ~= yardl.None + arr = var1; + res = numel(arr); + return + end + res = 0; + return + end + + function res = optional_named_array_length_with_discard(self) + var1 = self.optional_named_array; + if var1 ~= yardl.None + arr = var1; + res = numel(arr); + return + end + res = 0; + return + end + + function res = int_float_union_as_float(self) + var1 = self.int_float_union; + if isa(var1, "test_model.Int32OrFloat32") && var1.index == 1 + i_foo = var1.value; + res = single(i_foo); + return + end + if isa(var1, "test_model.Int32OrFloat32") && var1.index == 2 + f = var1.value; + res = f; + return + end + throw(yardl.RuntimeError("Unexpected union case")) + end + + function res = nullable_int_float_union_string(self) + var1 = self.nullable_int_float_union; + if var1 == yardl.None + res = "null"; + return + end + if isa(var1, "test_model.Int32OrFloat32") && var1.index == 1 + res = "int"; + return + end + res = "float"; + return + end + + function res = nested_switch(self) + var1 = self.union_with_nested_generic_union; + if isa(var1, "test_model.IntOrGenericRecordWithComputedFields") && var1.index == 1 + res = -1; + return + end + if isa(var1, "test_model.IntOrGenericRecordWithComputedFields") && var1.index == 2 + rec = var1.value; + var2 = rec.f1; + if isa(var2, "basic_types.T0OrT1") && var2.index == 2 + res = int32(20); + return + end + if isa(var2, "basic_types.T0OrT1") && var2.index == 1 + res = int32(10); + return + end + throw(yardl.RuntimeError("Unexpected union case")) + end + throw(yardl.RuntimeError("Unexpected union case")) + end + + function res = use_nested_computed_field(self) + var1 = self.union_with_nested_generic_union; + if isa(var1, "test_model.IntOrGenericRecordWithComputedFields") && var1.index == 1 + res = -1; + return + end + if isa(var1, "test_model.IntOrGenericRecordWithComputedFields") && var1.index == 2 + rec = var1.value; + res = int32(rec.type_index()); + return + end + throw(yardl.RuntimeError("Unexpected union case")) + end + + function res = switch_over_single_value(self) + var1 = self.int_field; + i = var1; + res = i; + return + end + + function res = arithmetic_1(self) + res = 1 + 2; + return + end + + function res = arithmetic_2(self) + res = 1 + 2 .* 3 + 4; + return + end + + function res = arithmetic_3(self) + res = (1 + 2) .* 3 + 4; + return + end + + function res = arithmetic_4(self) + res = self.array_size_from_int_field() + 2; + return + end + + function res = arithmetic_5(self) + res = size(self.array_field, ndims(self.array_field)-(2 - 1)); + return + end + + function res = arithmetic_6(self) + res = 7 ./ 2; + return + end + + function res = arithmetic_7(self) + res = double(7) ^ double(2); + return + end + + function res = arithmetic8(self) + res = self.complexfloat32_field .* complex(single(single(3))); + return + end + + function res = arithmetic_9(self) + res = 1.2 + double(1); + return + end + + function res = arithmetic_10(self) + res = 1e10 + 9e9; + return + end + + function res = arithmetic_11(self) + res = -(4.3 + double(1)); + return + end + + function res = cast_int_to_float(self) + res = single(self.int_field); + return + end + + function res = cast_float_to_int(self) + res = int32(self.float32_field); + return + end + + function res = cast_power(self) + res = int32(double(7) ^ double(2)); + return + end + + function res = cast_complex32_to_complex64(self) + res = complex(double(self.complexfloat32_field)); + return + end + + function res = cast_complex64_to_complex32(self) + res = complex(single(self.complexfloat64_field)); + return + end + + function res = cast_float_to_complex(self) + res = complex(single(66.6)); + return + end + + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithComputedFields") && ... + isequal(self.array_field, other.array_field) && ... + isequal(self.array_field_map_dimensions, other.array_field_map_dimensions) && ... + isequal(self.dynamic_array_field, other.dynamic_array_field) && ... + isequal(self.fixed_array_field, other.fixed_array_field) && ... + isequal(self.int_field, other.int_field) && ... + isequal(self.int8_field, other.int8_field) && ... + isequal(self.uint8_field, other.uint8_field) && ... + isequal(self.int16_field, other.int16_field) && ... + isequal(self.uint16_field, other.uint16_field) && ... + isequal(self.uint32_field, other.uint32_field) && ... + isequal(self.int64_field, other.int64_field) && ... + isequal(self.uint64_field, other.uint64_field) && ... + isequal(self.size_field, other.size_field) && ... + isequal(self.float32_field, other.float32_field) && ... + isequal(self.float64_field, other.float64_field) && ... + isequal(self.complexfloat32_field, other.complexfloat32_field) && ... + isequal(self.complexfloat64_field, other.complexfloat64_field) && ... + isequal(self.string_field, other.string_field) && ... + isequal(self.tuple_field, other.tuple_field) && ... + isequal(self.vector_field, other.vector_field) && ... + isequal(self.vector_of_vectors_field, other.vector_of_vectors_field) && ... + isequal(self.fixed_vector_field, other.fixed_vector_field) && ... + isequal(self.fixed_vector_of_vectors_field, other.fixed_vector_of_vectors_field) && ... + isequal(self.optional_named_array, other.optional_named_array) && ... + isequal(self.int_float_union, other.int_float_union) && ... + isequal(self.nullable_int_float_union, other.nullable_int_float_union) && ... + isequal(self.union_with_nested_generic_union, other.union_with_nested_generic_union) && ... + isequal(self.map_field, other.map_field); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithComputedFields(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithDynamicNDArrays.m b/matlab/generated/+test_model/RecordWithDynamicNDArrays.m new file mode 100644 index 00000000..118cb61f --- /dev/null +++ b/matlab/generated/+test_model/RecordWithDynamicNDArrays.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithDynamicNDArrays < handle + properties + ints + simple_record_array + record_with_vlens_array + end + + methods + function self = RecordWithDynamicNDArrays(kwargs) + arguments + kwargs.ints = int32.empty(); + kwargs.simple_record_array = test_model.SimpleRecord.empty(); + kwargs.record_with_vlens_array = test_model.RecordWithVlens.empty(); + end + self.ints = kwargs.ints; + self.simple_record_array = kwargs.simple_record_array; + self.record_with_vlens_array = kwargs.record_with_vlens_array; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithDynamicNDArrays") && ... + isequal(self.ints, other.ints) && ... + isequal(self.simple_record_array, other.simple_record_array) && ... + isequal(self.record_with_vlens_array, other.record_with_vlens_array); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithDynamicNDArrays(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithEnums.m b/matlab/generated/+test_model/RecordWithEnums.m new file mode 100644 index 00000000..ab7b0a11 --- /dev/null +++ b/matlab/generated/+test_model/RecordWithEnums.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithEnums < handle + properties + enum + flags + flags_2 + end + + methods + function self = RecordWithEnums(kwargs) + arguments + kwargs.enum = basic_types.Fruits.APPLE; + kwargs.flags = basic_types.DaysOfWeek(0); + kwargs.flags_2 = basic_types.TextFormat.REGULAR; + end + self.enum = kwargs.enum; + self.flags = kwargs.flags; + self.flags_2 = kwargs.flags_2; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithEnums") && ... + isequal(self.enum, other.enum) && ... + isequal(self.flags, other.flags) && ... + isequal(self.flags_2, other.flags_2); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithEnums(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithFixedArrays.m b/matlab/generated/+test_model/RecordWithFixedArrays.m new file mode 100644 index 00000000..c60cd0d1 --- /dev/null +++ b/matlab/generated/+test_model/RecordWithFixedArrays.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithFixedArrays < handle + properties + ints + fixed_simple_record_array + fixed_record_with_vlens_array + end + + methods + function self = RecordWithFixedArrays(kwargs) + arguments + kwargs.ints = repelem(int32(0), 3, 2); + kwargs.fixed_simple_record_array = repelem(test_model.SimpleRecord(), 2, 3); + kwargs.fixed_record_with_vlens_array = repelem(test_model.RecordWithVlens(), 2, 2); + end + self.ints = kwargs.ints; + self.fixed_simple_record_array = kwargs.fixed_simple_record_array; + self.fixed_record_with_vlens_array = kwargs.fixed_record_with_vlens_array; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithFixedArrays") && ... + isequal(self.ints, other.ints) && ... + isequal(self.fixed_simple_record_array, other.fixed_simple_record_array) && ... + isequal(self.fixed_record_with_vlens_array, other.fixed_record_with_vlens_array); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithFixedArrays(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithFixedCollections.m b/matlab/generated/+test_model/RecordWithFixedCollections.m new file mode 100644 index 00000000..6f80c8ad --- /dev/null +++ b/matlab/generated/+test_model/RecordWithFixedCollections.m @@ -0,0 +1,45 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithFixedCollections < handle + properties + fixed_vector + fixed_array + end + + methods + function self = RecordWithFixedCollections(kwargs) + arguments + kwargs.fixed_vector = repelem(int32(0), 3); + kwargs.fixed_array = repelem(int32(0), 3, 2); + end + self.fixed_vector = kwargs.fixed_vector; + self.fixed_array = kwargs.fixed_array; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithFixedCollections") && ... + isequal(self.fixed_vector, other.fixed_vector) && ... + isequal(self.fixed_array, other.fixed_array); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithFixedCollections(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithFixedVectors.m b/matlab/generated/+test_model/RecordWithFixedVectors.m new file mode 100644 index 00000000..4d40cb05 --- /dev/null +++ b/matlab/generated/+test_model/RecordWithFixedVectors.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithFixedVectors < handle + properties + fixed_int_vector + fixed_simple_record_vector + fixed_record_with_vlens_vector + end + + methods + function self = RecordWithFixedVectors(kwargs) + arguments + kwargs.fixed_int_vector = repelem(int32(0), 5); + kwargs.fixed_simple_record_vector = repelem(test_model.SimpleRecord(), 3); + kwargs.fixed_record_with_vlens_vector = repelem(test_model.RecordWithVlens(), 2); + end + self.fixed_int_vector = kwargs.fixed_int_vector; + self.fixed_simple_record_vector = kwargs.fixed_simple_record_vector; + self.fixed_record_with_vlens_vector = kwargs.fixed_record_with_vlens_vector; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithFixedVectors") && ... + isequal(self.fixed_int_vector, other.fixed_int_vector) && ... + isequal(self.fixed_simple_record_vector, other.fixed_simple_record_vector) && ... + isequal(self.fixed_record_with_vlens_vector, other.fixed_record_with_vlens_vector); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithFixedVectors(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithGenericArrays.m b/matlab/generated/+test_model/RecordWithGenericArrays.m new file mode 100644 index 00000000..b66e3d75 --- /dev/null +++ b/matlab/generated/+test_model/RecordWithGenericArrays.m @@ -0,0 +1,65 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithGenericArrays < handle + properties + nd + fixed_nd + dynamic_nd + aliased_nd + aliased_fixed_nd + aliased_dynamic_nd + end + + methods + function self = RecordWithGenericArrays(kwargs) + arguments + kwargs.nd; + kwargs.fixed_nd; + kwargs.dynamic_nd; + kwargs.aliased_nd; + kwargs.aliased_fixed_nd; + kwargs.aliased_dynamic_nd; + end + if ~isfield(kwargs, "nd") + throw(yardl.TypeError("Missing required keyword argument 'nd'")) + end + self.nd = kwargs.nd; + if ~isfield(kwargs, "fixed_nd") + throw(yardl.TypeError("Missing required keyword argument 'fixed_nd'")) + end + self.fixed_nd = kwargs.fixed_nd; + if ~isfield(kwargs, "dynamic_nd") + throw(yardl.TypeError("Missing required keyword argument 'dynamic_nd'")) + end + self.dynamic_nd = kwargs.dynamic_nd; + if ~isfield(kwargs, "aliased_nd") + throw(yardl.TypeError("Missing required keyword argument 'aliased_nd'")) + end + self.aliased_nd = kwargs.aliased_nd; + if ~isfield(kwargs, "aliased_fixed_nd") + throw(yardl.TypeError("Missing required keyword argument 'aliased_fixed_nd'")) + end + self.aliased_fixed_nd = kwargs.aliased_fixed_nd; + if ~isfield(kwargs, "aliased_dynamic_nd") + throw(yardl.TypeError("Missing required keyword argument 'aliased_dynamic_nd'")) + end + self.aliased_dynamic_nd = kwargs.aliased_dynamic_nd; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithGenericArrays") && ... + isequal(self.nd, other.nd) && ... + isequal(self.fixed_nd, other.fixed_nd) && ... + isequal(self.dynamic_nd, other.dynamic_nd) && ... + isequal(self.aliased_nd, other.aliased_nd) && ... + isequal(self.aliased_fixed_nd, other.aliased_fixed_nd) && ... + isequal(self.aliased_dynamic_nd, other.aliased_dynamic_nd); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + +end diff --git a/matlab/generated/+test_model/RecordWithGenericFixedVectors.m b/matlab/generated/+test_model/RecordWithGenericFixedVectors.m new file mode 100644 index 00000000..f3298457 --- /dev/null +++ b/matlab/generated/+test_model/RecordWithGenericFixedVectors.m @@ -0,0 +1,37 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithGenericFixedVectors < handle + properties + fv + afv + end + + methods + function self = RecordWithGenericFixedVectors(kwargs) + arguments + kwargs.fv; + kwargs.afv; + end + if ~isfield(kwargs, "fv") + throw(yardl.TypeError("Missing required keyword argument 'fv'")) + end + self.fv = kwargs.fv; + if ~isfield(kwargs, "afv") + throw(yardl.TypeError("Missing required keyword argument 'afv'")) + end + self.afv = kwargs.afv; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithGenericFixedVectors") && ... + isequal(self.fv, other.fv) && ... + isequal(self.afv, other.afv); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + +end diff --git a/matlab/generated/+test_model/RecordWithGenericMaps.m b/matlab/generated/+test_model/RecordWithGenericMaps.m new file mode 100644 index 00000000..75598bd9 --- /dev/null +++ b/matlab/generated/+test_model/RecordWithGenericMaps.m @@ -0,0 +1,45 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithGenericMaps < handle + properties + m + am + end + + methods + function self = RecordWithGenericMaps(kwargs) + arguments + kwargs.m = dictionary; + kwargs.am = dictionary; + end + self.m = kwargs.m; + self.am = kwargs.am; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithGenericMaps") && ... + isequal(self.m, other.m) && ... + isequal(self.am, other.am); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithGenericMaps(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithGenericVectorOfRecords.m b/matlab/generated/+test_model/RecordWithGenericVectorOfRecords.m new file mode 100644 index 00000000..52be4792 --- /dev/null +++ b/matlab/generated/+test_model/RecordWithGenericVectorOfRecords.m @@ -0,0 +1,30 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithGenericVectorOfRecords < handle + properties + v + end + + methods + function self = RecordWithGenericVectorOfRecords(kwargs) + arguments + kwargs.v; + end + if ~isfield(kwargs, "v") + throw(yardl.TypeError("Missing required keyword argument 'v'")) + end + self.v = kwargs.v; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithGenericVectorOfRecords") && ... + isequal(self.v, other.v); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + +end diff --git a/matlab/generated/+test_model/RecordWithGenericVectors.m b/matlab/generated/+test_model/RecordWithGenericVectors.m new file mode 100644 index 00000000..5eb735c5 --- /dev/null +++ b/matlab/generated/+test_model/RecordWithGenericVectors.m @@ -0,0 +1,37 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithGenericVectors < handle + properties + v + av + end + + methods + function self = RecordWithGenericVectors(kwargs) + arguments + kwargs.v; + kwargs.av; + end + if ~isfield(kwargs, "v") + throw(yardl.TypeError("Missing required keyword argument 'v'")) + end + self.v = kwargs.v; + if ~isfield(kwargs, "av") + throw(yardl.TypeError("Missing required keyword argument 'av'")) + end + self.av = kwargs.av; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithGenericVectors") && ... + isequal(self.v, other.v) && ... + isequal(self.av, other.av); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + +end diff --git a/matlab/generated/+test_model/RecordWithKeywordFields.m b/matlab/generated/+test_model/RecordWithKeywordFields.m new file mode 100644 index 00000000..22ec5fa0 --- /dev/null +++ b/matlab/generated/+test_model/RecordWithKeywordFields.m @@ -0,0 +1,54 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithKeywordFields < handle + properties + int + sizeof + if_ + end + + methods + function self = RecordWithKeywordFields(kwargs) + arguments + kwargs.int = ""; + kwargs.sizeof = int32.empty(0, 0); + kwargs.if_; + end + self.int = kwargs.int; + self.sizeof = kwargs.sizeof; + if ~isfield(kwargs, "if_") + throw(yardl.TypeError("Missing required keyword argument 'if_'")) + end + self.if_ = kwargs.if_; + end + + function res = float(self) + res = self.int; + return + end + + function res = double(self) + res = self.float(); + return + end + + function res = return_(self) + res = self.sizeof(2, 1); + return + end + + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithKeywordFields") && ... + isequal(self.int, other.int) && ... + isequal(self.sizeof, other.sizeof) && ... + isequal(self.if_, other.if_); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + +end diff --git a/matlab/generated/+test_model/RecordWithNDArrays.m b/matlab/generated/+test_model/RecordWithNDArrays.m new file mode 100644 index 00000000..209161f9 --- /dev/null +++ b/matlab/generated/+test_model/RecordWithNDArrays.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithNDArrays < handle + properties + ints + fixed_simple_record_array + fixed_record_with_vlens_array + end + + methods + function self = RecordWithNDArrays(kwargs) + arguments + kwargs.ints = int32.empty(0, 0); + kwargs.fixed_simple_record_array = test_model.SimpleRecord.empty(0, 0); + kwargs.fixed_record_with_vlens_array = test_model.RecordWithVlens.empty(0, 0); + end + self.ints = kwargs.ints; + self.fixed_simple_record_array = kwargs.fixed_simple_record_array; + self.fixed_record_with_vlens_array = kwargs.fixed_record_with_vlens_array; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithNDArrays") && ... + isequal(self.ints, other.ints) && ... + isequal(self.fixed_simple_record_array, other.fixed_simple_record_array) && ... + isequal(self.fixed_record_with_vlens_array, other.fixed_record_with_vlens_array); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithNDArrays(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithNDArraysSingleDimension.m b/matlab/generated/+test_model/RecordWithNDArraysSingleDimension.m new file mode 100644 index 00000000..bb378d98 --- /dev/null +++ b/matlab/generated/+test_model/RecordWithNDArraysSingleDimension.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithNDArraysSingleDimension < handle + properties + ints + fixed_simple_record_array + fixed_record_with_vlens_array + end + + methods + function self = RecordWithNDArraysSingleDimension(kwargs) + arguments + kwargs.ints = int32.empty(0); + kwargs.fixed_simple_record_array = test_model.SimpleRecord.empty(0); + kwargs.fixed_record_with_vlens_array = test_model.RecordWithVlens.empty(0); + end + self.ints = kwargs.ints; + self.fixed_simple_record_array = kwargs.fixed_simple_record_array; + self.fixed_record_with_vlens_array = kwargs.fixed_record_with_vlens_array; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithNDArraysSingleDimension") && ... + isequal(self.ints, other.ints) && ... + isequal(self.fixed_simple_record_array, other.fixed_simple_record_array) && ... + isequal(self.fixed_record_with_vlens_array, other.fixed_record_with_vlens_array); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithNDArraysSingleDimension(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithNamedFixedArrays.m b/matlab/generated/+test_model/RecordWithNamedFixedArrays.m new file mode 100644 index 00000000..33e13d11 --- /dev/null +++ b/matlab/generated/+test_model/RecordWithNamedFixedArrays.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithNamedFixedArrays < handle + properties + ints + fixed_simple_record_array + fixed_record_with_vlens_array + end + + methods + function self = RecordWithNamedFixedArrays(kwargs) + arguments + kwargs.ints = repelem(int32(0), 3, 2); + kwargs.fixed_simple_record_array = repelem(test_model.SimpleRecord(), 2, 3); + kwargs.fixed_record_with_vlens_array = repelem(test_model.RecordWithVlens(), 2, 2); + end + self.ints = kwargs.ints; + self.fixed_simple_record_array = kwargs.fixed_simple_record_array; + self.fixed_record_with_vlens_array = kwargs.fixed_record_with_vlens_array; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithNamedFixedArrays") && ... + isequal(self.ints, other.ints) && ... + isequal(self.fixed_simple_record_array, other.fixed_simple_record_array) && ... + isequal(self.fixed_record_with_vlens_array, other.fixed_record_with_vlens_array); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithNamedFixedArrays(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithOptionalFields.m b/matlab/generated/+test_model/RecordWithOptionalFields.m new file mode 100644 index 00000000..bb159ff8 --- /dev/null +++ b/matlab/generated/+test_model/RecordWithOptionalFields.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithOptionalFields < handle + properties + optional_int + optional_int_alternate_syntax + optional_time + end + + methods + function self = RecordWithOptionalFields(kwargs) + arguments + kwargs.optional_int = yardl.None; + kwargs.optional_int_alternate_syntax = yardl.None; + kwargs.optional_time = yardl.None; + end + self.optional_int = kwargs.optional_int; + self.optional_int_alternate_syntax = kwargs.optional_int_alternate_syntax; + self.optional_time = kwargs.optional_time; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithOptionalFields") && ... + isequal(self.optional_int, other.optional_int) && ... + isequal(self.optional_int_alternate_syntax, other.optional_int_alternate_syntax) && ... + isequal(self.optional_time, other.optional_time); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithOptionalFields(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithOptionalGenericField.m b/matlab/generated/+test_model/RecordWithOptionalGenericField.m new file mode 100644 index 00000000..89088836 --- /dev/null +++ b/matlab/generated/+test_model/RecordWithOptionalGenericField.m @@ -0,0 +1,41 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithOptionalGenericField < handle + properties + v + end + + methods + function self = RecordWithOptionalGenericField(kwargs) + arguments + kwargs.v = yardl.None; + end + self.v = kwargs.v; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithOptionalGenericField") && ... + isequal(self.v, other.v); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithOptionalGenericField(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithOptionalGenericUnionField.m b/matlab/generated/+test_model/RecordWithOptionalGenericUnionField.m new file mode 100644 index 00000000..6c57abfd --- /dev/null +++ b/matlab/generated/+test_model/RecordWithOptionalGenericUnionField.m @@ -0,0 +1,41 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithOptionalGenericUnionField < handle + properties + v + end + + methods + function self = RecordWithOptionalGenericUnionField(kwargs) + arguments + kwargs.v = yardl.None; + end + self.v = kwargs.v; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithOptionalGenericUnionField") && ... + isequal(self.v, other.v); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithOptionalGenericUnionField(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithOptionalVector.m b/matlab/generated/+test_model/RecordWithOptionalVector.m new file mode 100644 index 00000000..14aab0bf --- /dev/null +++ b/matlab/generated/+test_model/RecordWithOptionalVector.m @@ -0,0 +1,41 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithOptionalVector < handle + properties + optional_vector + end + + methods + function self = RecordWithOptionalVector(kwargs) + arguments + kwargs.optional_vector = yardl.None; + end + self.optional_vector = kwargs.optional_vector; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithOptionalVector") && ... + isequal(self.optional_vector, other.optional_vector); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithOptionalVector(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithPrimitiveAliases.m b/matlab/generated/+test_model/RecordWithPrimitiveAliases.m new file mode 100644 index 00000000..3dd24585 --- /dev/null +++ b/matlab/generated/+test_model/RecordWithPrimitiveAliases.m @@ -0,0 +1,73 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithPrimitiveAliases < handle + properties + byte_field + int_field + uint_field + long_field + ulong_field + float_field + double_field + complexfloat_field + complexdouble_field + end + + methods + function self = RecordWithPrimitiveAliases(kwargs) + arguments + kwargs.byte_field = uint8(0); + kwargs.int_field = int32(0); + kwargs.uint_field = uint32(0); + kwargs.long_field = int64(0); + kwargs.ulong_field = uint64(0); + kwargs.float_field = single(0); + kwargs.double_field = double(0); + kwargs.complexfloat_field = complex(single(0)); + kwargs.complexdouble_field = complex(0); + end + self.byte_field = kwargs.byte_field; + self.int_field = kwargs.int_field; + self.uint_field = kwargs.uint_field; + self.long_field = kwargs.long_field; + self.ulong_field = kwargs.ulong_field; + self.float_field = kwargs.float_field; + self.double_field = kwargs.double_field; + self.complexfloat_field = kwargs.complexfloat_field; + self.complexdouble_field = kwargs.complexdouble_field; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithPrimitiveAliases") && ... + isequal(self.byte_field, other.byte_field) && ... + isequal(self.int_field, other.int_field) && ... + isequal(self.uint_field, other.uint_field) && ... + isequal(self.long_field, other.long_field) && ... + isequal(self.ulong_field, other.ulong_field) && ... + isequal(self.float_field, other.float_field) && ... + isequal(self.double_field, other.double_field) && ... + isequal(self.complexfloat_field, other.complexfloat_field) && ... + isequal(self.complexdouble_field, other.complexdouble_field); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithPrimitiveAliases(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithPrimitives.m b/matlab/generated/+test_model/RecordWithPrimitives.m new file mode 100644 index 00000000..07dc6d91 --- /dev/null +++ b/matlab/generated/+test_model/RecordWithPrimitives.m @@ -0,0 +1,105 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithPrimitives < handle + properties + bool_field + int8_field + uint8_field + int16_field + uint16_field + int32_field + uint32_field + int64_field + uint64_field + size_field + float32_field + float64_field + complexfloat32_field + complexfloat64_field + date_field + time_field + datetime_field + end + + methods + function self = RecordWithPrimitives(kwargs) + arguments + kwargs.bool_field = false; + kwargs.int8_field = int8(0); + kwargs.uint8_field = uint8(0); + kwargs.int16_field = int16(0); + kwargs.uint16_field = uint16(0); + kwargs.int32_field = int32(0); + kwargs.uint32_field = uint32(0); + kwargs.int64_field = int64(0); + kwargs.uint64_field = uint64(0); + kwargs.size_field = uint64(0); + kwargs.float32_field = single(0); + kwargs.float64_field = double(0); + kwargs.complexfloat32_field = complex(single(0)); + kwargs.complexfloat64_field = complex(0); + kwargs.date_field = yardl.Date(); + kwargs.time_field = yardl.Time(); + kwargs.datetime_field = yardl.DateTime(); + end + self.bool_field = kwargs.bool_field; + self.int8_field = kwargs.int8_field; + self.uint8_field = kwargs.uint8_field; + self.int16_field = kwargs.int16_field; + self.uint16_field = kwargs.uint16_field; + self.int32_field = kwargs.int32_field; + self.uint32_field = kwargs.uint32_field; + self.int64_field = kwargs.int64_field; + self.uint64_field = kwargs.uint64_field; + self.size_field = kwargs.size_field; + self.float32_field = kwargs.float32_field; + self.float64_field = kwargs.float64_field; + self.complexfloat32_field = kwargs.complexfloat32_field; + self.complexfloat64_field = kwargs.complexfloat64_field; + self.date_field = kwargs.date_field; + self.time_field = kwargs.time_field; + self.datetime_field = kwargs.datetime_field; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithPrimitives") && ... + isequal(self.bool_field, other.bool_field) && ... + isequal(self.int8_field, other.int8_field) && ... + isequal(self.uint8_field, other.uint8_field) && ... + isequal(self.int16_field, other.int16_field) && ... + isequal(self.uint16_field, other.uint16_field) && ... + isequal(self.int32_field, other.int32_field) && ... + isequal(self.uint32_field, other.uint32_field) && ... + isequal(self.int64_field, other.int64_field) && ... + isequal(self.uint64_field, other.uint64_field) && ... + isequal(self.size_field, other.size_field) && ... + isequal(self.float32_field, other.float32_field) && ... + isequal(self.float64_field, other.float64_field) && ... + isequal(self.complexfloat32_field, other.complexfloat32_field) && ... + isequal(self.complexfloat64_field, other.complexfloat64_field) && ... + isequal(self.date_field, other.date_field) && ... + isequal(self.time_field, other.time_field) && ... + isequal(self.datetime_field, other.datetime_field); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithPrimitives(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithStrings.m b/matlab/generated/+test_model/RecordWithStrings.m new file mode 100644 index 00000000..ffab134f --- /dev/null +++ b/matlab/generated/+test_model/RecordWithStrings.m @@ -0,0 +1,45 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithStrings < handle + properties + a + b + end + + methods + function self = RecordWithStrings(kwargs) + arguments + kwargs.a = ""; + kwargs.b = ""; + end + self.a = kwargs.a; + self.b = kwargs.b; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithStrings") && ... + isequal(self.a, other.a) && ... + isequal(self.b, other.b); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithStrings(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithUnionsOfContainers.m b/matlab/generated/+test_model/RecordWithUnionsOfContainers.m new file mode 100644 index 00000000..95858917 --- /dev/null +++ b/matlab/generated/+test_model/RecordWithUnionsOfContainers.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithUnionsOfContainers < handle + properties + map_or_scalar + vector_or_scalar + array_or_scalar + end + + methods + function self = RecordWithUnionsOfContainers(kwargs) + arguments + kwargs.map_or_scalar = test_model.MapOrScalar.Map(dictionary); + kwargs.vector_or_scalar = test_model.VectorOrScalar.Vector(int32.empty()); + kwargs.array_or_scalar = test_model.ArrayOrScalar.Array(int32.empty()); + end + self.map_or_scalar = kwargs.map_or_scalar; + self.vector_or_scalar = kwargs.vector_or_scalar; + self.array_or_scalar = kwargs.array_or_scalar; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithUnionsOfContainers") && ... + isequal(self.map_or_scalar, other.map_or_scalar) && ... + isequal(self.vector_or_scalar, other.vector_or_scalar) && ... + isequal(self.array_or_scalar, other.array_or_scalar); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithUnionsOfContainers(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithVectorOfTimes.m b/matlab/generated/+test_model/RecordWithVectorOfTimes.m new file mode 100644 index 00000000..25dc8d4a --- /dev/null +++ b/matlab/generated/+test_model/RecordWithVectorOfTimes.m @@ -0,0 +1,41 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithVectorOfTimes < handle + properties + times + end + + methods + function self = RecordWithVectorOfTimes(kwargs) + arguments + kwargs.times = yardl.Time.empty(); + end + self.times = kwargs.times; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithVectorOfTimes") && ... + isequal(self.times, other.times); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithVectorOfTimes(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithVectors.m b/matlab/generated/+test_model/RecordWithVectors.m new file mode 100644 index 00000000..fdfd681a --- /dev/null +++ b/matlab/generated/+test_model/RecordWithVectors.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithVectors < handle + properties + default_vector + default_vector_fixed_length + vector_of_vectors + end + + methods + function self = RecordWithVectors(kwargs) + arguments + kwargs.default_vector = int32.empty(); + kwargs.default_vector_fixed_length = repelem(int32(0), 3); + kwargs.vector_of_vectors = int32.empty(); + end + self.default_vector = kwargs.default_vector; + self.default_vector_fixed_length = kwargs.default_vector_fixed_length; + self.vector_of_vectors = kwargs.vector_of_vectors; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithVectors") && ... + isequal(self.default_vector, other.default_vector) && ... + isequal(self.default_vector_fixed_length, other.default_vector_fixed_length) && ... + isequal(self.vector_of_vectors, other.vector_of_vectors); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithVectors(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithVlenCollections.m b/matlab/generated/+test_model/RecordWithVlenCollections.m new file mode 100644 index 00000000..158f5550 --- /dev/null +++ b/matlab/generated/+test_model/RecordWithVlenCollections.m @@ -0,0 +1,45 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithVlenCollections < handle + properties + vector + array + end + + methods + function self = RecordWithVlenCollections(kwargs) + arguments + kwargs.vector = int32.empty(); + kwargs.array = int32.empty(0, 0); + end + self.vector = kwargs.vector; + self.array = kwargs.array; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithVlenCollections") && ... + isequal(self.vector, other.vector) && ... + isequal(self.array, other.array); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithVlenCollections(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithVlens.m b/matlab/generated/+test_model/RecordWithVlens.m new file mode 100644 index 00000000..6eb80c63 --- /dev/null +++ b/matlab/generated/+test_model/RecordWithVlens.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef RecordWithVlens < handle + properties + a + b + c + end + + methods + function self = RecordWithVlens(kwargs) + arguments + kwargs.a = test_model.SimpleRecord.empty(); + kwargs.b = int32(0); + kwargs.c = int32(0); + end + self.a = kwargs.a; + self.b = kwargs.b; + self.c = kwargs.c; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.RecordWithVlens") && ... + isequal(self.a, other.a) && ... + isequal(self.b, other.b) && ... + isequal(self.c, other.c); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.RecordWithVlens(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/RecordWithVlensFixedArray.m b/matlab/generated/+test_model/RecordWithVlensFixedArray.m new file mode 100644 index 00000000..f4015b1d --- /dev/null +++ b/matlab/generated/+test_model/RecordWithVlensFixedArray.m @@ -0,0 +1,8 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function a = RecordWithVlensFixedArray(array) + arguments + array test_model.RecordWithVlens + end + a = array; +end diff --git a/matlab/generated/+test_model/ScalarOptionalsReaderBase.m b/matlab/generated/+test_model/ScalarOptionalsReaderBase.m new file mode 100644 index 00000000..033483f7 --- /dev/null +++ b/matlab/generated/+test_model/ScalarOptionalsReaderBase.m @@ -0,0 +1,105 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef ScalarOptionalsReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = ScalarOptionalsReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 4 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function value = read_optional_int(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_optional_int_(); + self.state_ = 1; + end + + % Ordinal 1 + function value = read_optional_record(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_optional_record_(); + self.state_ = 2; + end + + % Ordinal 2 + function value = read_record_with_optional_fields(self) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + value = self.read_record_with_optional_fields_(); + self.state_ = 3; + end + + % Ordinal 3 + function value = read_optional_record_with_optional_fields(self) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + value = self.read_optional_record_with_optional_fields_(); + self.state_ = 4; + end + + function copy_to(self, writer) + writer.write_optional_int(self.read_optional_int()); + writer.write_optional_record(self.read_optional_record()); + writer.write_record_with_optional_fields(self.read_record_with_optional_fields()); + writer.write_optional_record_with_optional_fields(self.read_optional_record_with_optional_fields()); + end + end + + methods (Static) + function res = schema() + res = test_model.ScalarOptionalsWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + read_optional_int_(self) + read_optional_record_(self) + read_record_with_optional_fields_(self) + read_optional_record_with_optional_fields_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_optional_int"; + elseif state == 1 + name = "read_optional_record"; + elseif state == 2 + name = "read_record_with_optional_fields"; + elseif state == 3 + name = "read_optional_record_with_optional_fields"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/ScalarOptionalsWriterBase.m b/matlab/generated/+test_model/ScalarOptionalsWriterBase.m new file mode 100644 index 00000000..0a5a24ab --- /dev/null +++ b/matlab/generated/+test_model/ScalarOptionalsWriterBase.m @@ -0,0 +1,100 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol ScalarOptionals +classdef (Abstract) ScalarOptionalsWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = ScalarOptionalsWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 4 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_optional_int(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_optional_int_(value); + self.state_ = 1; + end + + % Ordinal 1 + function write_optional_record(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_optional_record_(value); + self.state_ = 2; + end + + % Ordinal 2 + function write_record_with_optional_fields(self, value) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + self.write_record_with_optional_fields_(value); + self.state_ = 3; + end + + % Ordinal 3 + function write_optional_record_with_optional_fields(self, value) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + self.write_optional_record_with_optional_fields_(value); + self.state_ = 4; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"ScalarOptionals","sequence":[{"name":"optionalInt","type":[null,"int32"]},{"name":"optionalRecord","type":[null,"TestModel.SimpleRecord"]},{"name":"recordWithOptionalFields","type":"TestModel.RecordWithOptionalFields"},{"name":"optionalRecordWithOptionalFields","type":[null,"TestModel.RecordWithOptionalFields"]}]},"types":[{"name":"RecordWithOptionalFields","fields":[{"name":"optionalInt","type":[null,"int32"]},{"name":"optionalIntAlternateSyntax","type":[null,"int32"]},{"name":"optionalTime","type":[null,"time"]}]},{"name":"SimpleRecord","fields":[{"name":"x","type":"int32"},{"name":"y","type":"int32"},{"name":"z","type":"int32"}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_optional_int_(self, value) + write_optional_record_(self, value) + write_record_with_optional_fields_(self, value) + write_optional_record_with_optional_fields_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_optional_int"; + elseif state == 1 + name = "write_optional_record"; + elseif state == 2 + name = "write_record_with_optional_fields"; + elseif state == 3 + name = "write_optional_record_with_optional_fields"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/ScalarsReaderBase.m b/matlab/generated/+test_model/ScalarsReaderBase.m new file mode 100644 index 00000000..54acf102 --- /dev/null +++ b/matlab/generated/+test_model/ScalarsReaderBase.m @@ -0,0 +1,77 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef ScalarsReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = ScalarsReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 2 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function value = read_int32(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_int32_(); + self.state_ = 1; + end + + % Ordinal 1 + function value = read_record(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_record_(); + self.state_ = 2; + end + + function copy_to(self, writer) + writer.write_int32(self.read_int32()); + writer.write_record(self.read_record()); + end + end + + methods (Static) + function res = schema() + res = test_model.ScalarsWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + read_int32_(self) + read_record_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_int32"; + elseif state == 1 + name = "read_record"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/ScalarsWriterBase.m b/matlab/generated/+test_model/ScalarsWriterBase.m new file mode 100644 index 00000000..fb95039d --- /dev/null +++ b/matlab/generated/+test_model/ScalarsWriterBase.m @@ -0,0 +1,74 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol Scalars +classdef (Abstract) ScalarsWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = ScalarsWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 2 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_int32(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_int32_(value); + self.state_ = 1; + end + + % Ordinal 1 + function write_record(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_record_(value); + self.state_ = 2; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"Scalars","sequence":[{"name":"int32","type":"int32"},{"name":"record","type":"TestModel.RecordWithPrimitives"}]},"types":[{"name":"RecordWithPrimitives","fields":[{"name":"boolField","type":"bool"},{"name":"int8Field","type":"int8"},{"name":"uint8Field","type":"uint8"},{"name":"int16Field","type":"int16"},{"name":"uint16Field","type":"uint16"},{"name":"int32Field","type":"int32"},{"name":"uint32Field","type":"uint32"},{"name":"int64Field","type":"int64"},{"name":"uint64Field","type":"uint64"},{"name":"sizeField","type":"size"},{"name":"float32Field","type":"float32"},{"name":"float64Field","type":"float64"},{"name":"complexfloat32Field","type":"complexfloat32"},{"name":"complexfloat64Field","type":"complexfloat64"},{"name":"dateField","type":"date"},{"name":"timeField","type":"time"},{"name":"datetimeField","type":"datetime"}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_int32_(self, value) + write_record_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_int32"; + elseif state == 1 + name = "write_record"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/SimpleAcquisition.m b/matlab/generated/+test_model/SimpleAcquisition.m new file mode 100644 index 00000000..3d502407 --- /dev/null +++ b/matlab/generated/+test_model/SimpleAcquisition.m @@ -0,0 +1,53 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef SimpleAcquisition < handle + properties + flags + idx + data + trajectory + end + + methods + function self = SimpleAcquisition(kwargs) + arguments + kwargs.flags = uint64(0); + kwargs.idx = test_model.SimpleEncodingCounters(); + kwargs.data = single.empty(0, 0); + kwargs.trajectory = single.empty(0, 0); + end + self.flags = kwargs.flags; + self.idx = kwargs.idx; + self.data = kwargs.data; + self.trajectory = kwargs.trajectory; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.SimpleAcquisition") && ... + isequal(self.flags, other.flags) && ... + isequal(self.idx, other.idx) && ... + isequal(self.data, other.data) && ... + isequal(self.trajectory, other.trajectory); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.SimpleAcquisition(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/SimpleEncodingCounters.m b/matlab/generated/+test_model/SimpleEncodingCounters.m new file mode 100644 index 00000000..2cdbe684 --- /dev/null +++ b/matlab/generated/+test_model/SimpleEncodingCounters.m @@ -0,0 +1,53 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef SimpleEncodingCounters < handle + properties + e1 + e2 + slice + repetition + end + + methods + function self = SimpleEncodingCounters(kwargs) + arguments + kwargs.e1 = yardl.None; + kwargs.e2 = yardl.None; + kwargs.slice = yardl.None; + kwargs.repetition = yardl.None; + end + self.e1 = kwargs.e1; + self.e2 = kwargs.e2; + self.slice = kwargs.slice; + self.repetition = kwargs.repetition; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.SimpleEncodingCounters") && ... + isequal(self.e1, other.e1) && ... + isequal(self.e2, other.e2) && ... + isequal(self.slice, other.slice) && ... + isequal(self.repetition, other.repetition); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.SimpleEncodingCounters(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/SimpleGenericsReaderBase.m b/matlab/generated/+test_model/SimpleGenericsReaderBase.m new file mode 100644 index 00000000..744c6936 --- /dev/null +++ b/matlab/generated/+test_model/SimpleGenericsReaderBase.m @@ -0,0 +1,190 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef SimpleGenericsReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = SimpleGenericsReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 9 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function value = read_float_image(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_float_image_(); + self.state_ = 1; + end + + % Ordinal 1 + function value = read_int_image(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_int_image_(); + self.state_ = 2; + end + + % Ordinal 2 + function value = read_int_image_alternate_syntax(self) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + value = self.read_int_image_alternate_syntax_(); + self.state_ = 3; + end + + % Ordinal 3 + function value = read_string_image(self) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + value = self.read_string_image_(); + self.state_ = 4; + end + + % Ordinal 4 + function value = read_int_float_tuple(self) + if self.state_ ~= 4 + self.raise_unexpected_state_(4); + end + + value = self.read_int_float_tuple_(); + self.state_ = 5; + end + + % Ordinal 5 + function value = read_float_float_tuple(self) + if self.state_ ~= 5 + self.raise_unexpected_state_(5); + end + + value = self.read_float_float_tuple_(); + self.state_ = 6; + end + + % Ordinal 6 + function value = read_int_float_tuple_alternate_syntax(self) + if self.state_ ~= 6 + self.raise_unexpected_state_(6); + end + + value = self.read_int_float_tuple_alternate_syntax_(); + self.state_ = 7; + end + + % Ordinal 7 + function value = read_int_string_tuple(self) + if self.state_ ~= 7 + self.raise_unexpected_state_(7); + end + + value = self.read_int_string_tuple_(); + self.state_ = 8; + end + + % Ordinal 8 + function more = has_stream_of_type_variants(self) + if self.state_ ~= 8 + self.raise_unexpected_state_(8); + end + + more = self.has_stream_of_type_variants_(); + if ~more + self.state_ = 9; + end + end + + function value = read_stream_of_type_variants(self) + if self.state_ ~= 8 + self.raise_unexpected_state_(8); + end + + value = self.read_stream_of_type_variants_(); + end + + function copy_to(self, writer) + writer.write_float_image(self.read_float_image()); + writer.write_int_image(self.read_int_image()); + writer.write_int_image_alternate_syntax(self.read_int_image_alternate_syntax()); + writer.write_string_image(self.read_string_image()); + writer.write_int_float_tuple(self.read_int_float_tuple()); + writer.write_float_float_tuple(self.read_float_float_tuple()); + writer.write_int_float_tuple_alternate_syntax(self.read_int_float_tuple_alternate_syntax()); + writer.write_int_string_tuple(self.read_int_string_tuple()); + while self.has_stream_of_type_variants() + item = self.read_stream_of_type_variants(); + writer.write_stream_of_type_variants({item}); + end + writer.end_stream_of_type_variants(); + end + end + + methods (Static) + function res = schema() + res = test_model.SimpleGenericsWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + read_float_image_(self) + read_int_image_(self) + read_int_image_alternate_syntax_(self) + read_string_image_(self) + read_int_float_tuple_(self) + read_float_float_tuple_(self) + read_int_float_tuple_alternate_syntax_(self) + read_int_string_tuple_(self) + has_stream_of_type_variants_(self) + read_stream_of_type_variants_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_float_image"; + elseif state == 1 + name = "read_int_image"; + elseif state == 2 + name = "read_int_image_alternate_syntax"; + elseif state == 3 + name = "read_string_image"; + elseif state == 4 + name = "read_int_float_tuple"; + elseif state == 5 + name = "read_float_float_tuple"; + elseif state == 6 + name = "read_int_float_tuple_alternate_syntax"; + elseif state == 7 + name = "read_int_string_tuple"; + elseif state == 8 + name = "read_stream_of_type_variants"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/SimpleGenericsWriterBase.m b/matlab/generated/+test_model/SimpleGenericsWriterBase.m new file mode 100644 index 00000000..4e5240ea --- /dev/null +++ b/matlab/generated/+test_model/SimpleGenericsWriterBase.m @@ -0,0 +1,173 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol SimpleGenerics +classdef (Abstract) SimpleGenericsWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = SimpleGenericsWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 9 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_float_image(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_float_image_(value); + self.state_ = 1; + end + + % Ordinal 1 + function write_int_image(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_int_image_(value); + self.state_ = 2; + end + + % Ordinal 2 + function write_int_image_alternate_syntax(self, value) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + self.write_int_image_alternate_syntax_(value); + self.state_ = 3; + end + + % Ordinal 3 + function write_string_image(self, value) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + self.write_string_image_(value); + self.state_ = 4; + end + + % Ordinal 4 + function write_int_float_tuple(self, value) + if self.state_ ~= 4 + self.raise_unexpected_state_(4); + end + + self.write_int_float_tuple_(value); + self.state_ = 5; + end + + % Ordinal 5 + function write_float_float_tuple(self, value) + if self.state_ ~= 5 + self.raise_unexpected_state_(5); + end + + self.write_float_float_tuple_(value); + self.state_ = 6; + end + + % Ordinal 6 + function write_int_float_tuple_alternate_syntax(self, value) + if self.state_ ~= 6 + self.raise_unexpected_state_(6); + end + + self.write_int_float_tuple_alternate_syntax_(value); + self.state_ = 7; + end + + % Ordinal 7 + function write_int_string_tuple(self, value) + if self.state_ ~= 7 + self.raise_unexpected_state_(7); + end + + self.write_int_string_tuple_(value); + self.state_ = 8; + end + + % Ordinal 8 + function write_stream_of_type_variants(self, value) + if self.state_ ~= 8 + self.raise_unexpected_state_(8); + end + + self.write_stream_of_type_variants_(value); + end + + function end_stream_of_type_variants(self) + if self.state_ ~= 8 + self.raise_unexpected_state_(8); + end + + self.end_stream_(); + self.state_ = 9; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"SimpleGenerics","sequence":[{"name":"floatImage","type":"Image.FloatImage"},{"name":"intImage","type":"Image.IntImage"},{"name":"intImageAlternateSyntax","type":{"name":"TestModel.Image","typeArguments":["int32"]}},{"name":"stringImage","type":{"name":"TestModel.Image","typeArguments":["string"]}},{"name":"intFloatTuple","type":{"name":"Tuples.Tuple","typeArguments":["int32","float32"]}},{"name":"floatFloatTuple","type":{"name":"Tuples.Tuple","typeArguments":["float32","float32"]}},{"name":"intFloatTupleAlternateSyntax","type":{"name":"Tuples.Tuple","typeArguments":["int32","float32"]}},{"name":"intStringTuple","type":{"name":"Tuples.Tuple","typeArguments":["int32","string"]}},{"name":"streamOfTypeVariants","type":{"stream":{"items":[{"tag":"imageFloat","explicitTag":true,"type":"Image.FloatImage"},{"tag":"imageDouble","explicitTag":true,"type":{"name":"TestModel.Image","typeArguments":["float64"]}}]}}}]},"types":[{"name":"FloatImage","type":{"name":"Image.Image","typeArguments":["float32"]}},{"name":"Image","typeParameters":["T"],"type":{"array":{"items":"T","dimensions":[{"name":"x"},{"name":"y"}]}}},{"name":"IntImage","type":{"name":"Image.Image","typeArguments":["int32"]}},{"name":"Image","typeParameters":["T"],"type":{"name":"Image.Image","typeArguments":["T"]}},{"name":"Tuple","typeParameters":["T1","T2"],"fields":[{"name":"v1","type":"T1"},{"name":"v2","type":"T2"}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_float_image_(self, value) + write_int_image_(self, value) + write_int_image_alternate_syntax_(self, value) + write_string_image_(self, value) + write_int_float_tuple_(self, value) + write_float_float_tuple_(self, value) + write_int_float_tuple_alternate_syntax_(self, value) + write_int_string_tuple_(self, value) + write_stream_of_type_variants_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_float_image"; + elseif state == 1 + name = "write_int_image"; + elseif state == 2 + name = "write_int_image_alternate_syntax"; + elseif state == 3 + name = "write_string_image"; + elseif state == 4 + name = "write_int_float_tuple"; + elseif state == 5 + name = "write_float_float_tuple"; + elseif state == 6 + name = "write_int_float_tuple_alternate_syntax"; + elseif state == 7 + name = "write_int_string_tuple"; + elseif state == 8 + name = "write_stream_of_type_variants or end_stream_of_type_variants"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/SimpleRecord.m b/matlab/generated/+test_model/SimpleRecord.m new file mode 100644 index 00000000..fc3930ad --- /dev/null +++ b/matlab/generated/+test_model/SimpleRecord.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef SimpleRecord < handle + properties + x + y + z + end + + methods + function self = SimpleRecord(kwargs) + arguments + kwargs.x = int32(0); + kwargs.y = int32(0); + kwargs.z = int32(0); + end + self.x = kwargs.x; + self.y = kwargs.y; + self.z = kwargs.z; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.SimpleRecord") && ... + isequal(self.x, other.x) && ... + isequal(self.y, other.y) && ... + isequal(self.z, other.z); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.SimpleRecord(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/SimpleRecordFixedArray.m b/matlab/generated/+test_model/SimpleRecordFixedArray.m new file mode 100644 index 00000000..c89409e7 --- /dev/null +++ b/matlab/generated/+test_model/SimpleRecordFixedArray.m @@ -0,0 +1,8 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function a = SimpleRecordFixedArray(array) + arguments + array test_model.SimpleRecord + end + a = array; +end diff --git a/matlab/generated/+test_model/SizeBasedEnum.m b/matlab/generated/+test_model/SizeBasedEnum.m new file mode 100644 index 00000000..2971730d --- /dev/null +++ b/matlab/generated/+test_model/SizeBasedEnum.m @@ -0,0 +1,28 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef SizeBasedEnum < uint64 + methods (Static) + function v = A + v = test_model.SizeBasedEnum(0); + end + function v = B + v = test_model.SizeBasedEnum(1); + end + function v = C + v = test_model.SizeBasedEnum(2); + end + + function z = zeros(varargin) + elem = test_model.SizeBasedEnum(0); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/SmallBenchmarkRecord.m b/matlab/generated/+test_model/SmallBenchmarkRecord.m new file mode 100644 index 00000000..b9e62a52 --- /dev/null +++ b/matlab/generated/+test_model/SmallBenchmarkRecord.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef SmallBenchmarkRecord < handle + properties + a + b + c + end + + methods + function self = SmallBenchmarkRecord(kwargs) + arguments + kwargs.a = double(0); + kwargs.b = single(0); + kwargs.c = single(0); + end + self.a = kwargs.a; + self.b = kwargs.b; + self.c = kwargs.c; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.SmallBenchmarkRecord") && ... + isequal(self.a, other.a) && ... + isequal(self.b, other.b) && ... + isequal(self.c, other.c); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.SmallBenchmarkRecord(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/StateTestReaderBase.m b/matlab/generated/+test_model/StateTestReaderBase.m new file mode 100644 index 00000000..78a134e5 --- /dev/null +++ b/matlab/generated/+test_model/StateTestReaderBase.m @@ -0,0 +1,106 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef StateTestReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = StateTestReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 3 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function value = read_an_int(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_an_int_(); + self.state_ = 1; + end + + % Ordinal 1 + function more = has_a_stream(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + more = self.has_a_stream_(); + if ~more + self.state_ = 2; + end + end + + function value = read_a_stream(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_a_stream_(); + end + + % Ordinal 2 + function value = read_another_int(self) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + value = self.read_another_int_(); + self.state_ = 3; + end + + function copy_to(self, writer) + writer.write_an_int(self.read_an_int()); + while self.has_a_stream() + item = self.read_a_stream(); + writer.write_a_stream({item}); + end + writer.end_a_stream(); + writer.write_another_int(self.read_another_int()); + end + end + + methods (Static) + function res = schema() + res = test_model.StateTestWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + read_an_int_(self) + has_a_stream_(self) + read_a_stream_(self) + read_another_int_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_an_int"; + elseif state == 1 + name = "read_a_stream"; + elseif state == 2 + name = "read_another_int"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/StateTestWriterBase.m b/matlab/generated/+test_model/StateTestWriterBase.m new file mode 100644 index 00000000..44130dd8 --- /dev/null +++ b/matlab/generated/+test_model/StateTestWriterBase.m @@ -0,0 +1,95 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol StateTest +classdef (Abstract) StateTestWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = StateTestWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 3 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_an_int(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_an_int_(value); + self.state_ = 1; + end + + % Ordinal 1 + function write_a_stream(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_a_stream_(value); + end + + function end_a_stream(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.end_stream_(); + self.state_ = 2; + end + + % Ordinal 2 + function write_another_int(self, value) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + self.write_another_int_(value); + self.state_ = 3; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"StateTest","sequence":[{"name":"anInt","type":"int32"},{"name":"aStream","type":{"stream":{"items":"int32"}}},{"name":"anotherInt","type":"int32"}]},"types":null}'); + end + end + + methods (Abstract, Access=protected) + write_an_int_(self, value) + write_a_stream_(self, value) + write_another_int_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_an_int"; + elseif state == 1 + name = "write_a_stream or end_a_stream"; + elseif state == 2 + name = "write_another_int"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/StreamsOfAliasedUnionsReaderBase.m b/matlab/generated/+test_model/StreamsOfAliasedUnionsReaderBase.m new file mode 100644 index 00000000..cb6b79c1 --- /dev/null +++ b/matlab/generated/+test_model/StreamsOfAliasedUnionsReaderBase.m @@ -0,0 +1,107 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef StreamsOfAliasedUnionsReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = StreamsOfAliasedUnionsReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 2 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function more = has_int_or_simple_record(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + more = self.has_int_or_simple_record_(); + if ~more + self.state_ = 1; + end + end + + function value = read_int_or_simple_record(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_int_or_simple_record_(); + end + + % Ordinal 1 + function more = has_nullable_int_or_simple_record(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + more = self.has_nullable_int_or_simple_record_(); + if ~more + self.state_ = 2; + end + end + + function value = read_nullable_int_or_simple_record(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_nullable_int_or_simple_record_(); + end + + function copy_to(self, writer) + while self.has_int_or_simple_record() + item = self.read_int_or_simple_record(); + writer.write_int_or_simple_record({item}); + end + writer.end_int_or_simple_record(); + while self.has_nullable_int_or_simple_record() + item = self.read_nullable_int_or_simple_record(); + writer.write_nullable_int_or_simple_record({item}); + end + writer.end_nullable_int_or_simple_record(); + end + end + + methods (Static) + function res = schema() + res = test_model.StreamsOfAliasedUnionsWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + has_int_or_simple_record_(self) + read_int_or_simple_record_(self) + has_nullable_int_or_simple_record_(self) + read_nullable_int_or_simple_record_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_int_or_simple_record"; + elseif state == 1 + name = "read_nullable_int_or_simple_record"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/StreamsOfAliasedUnionsWriterBase.m b/matlab/generated/+test_model/StreamsOfAliasedUnionsWriterBase.m new file mode 100644 index 00000000..300e16af --- /dev/null +++ b/matlab/generated/+test_model/StreamsOfAliasedUnionsWriterBase.m @@ -0,0 +1,90 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol StreamsOfAliasedUnions +classdef (Abstract) StreamsOfAliasedUnionsWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = StreamsOfAliasedUnionsWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 2 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_int_or_simple_record(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_int_or_simple_record_(value); + end + + function end_int_or_simple_record(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.end_stream_(); + self.state_ = 1; + end + + % Ordinal 1 + function write_nullable_int_or_simple_record(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_nullable_int_or_simple_record_(value); + end + + function end_nullable_int_or_simple_record(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.end_stream_(); + self.state_ = 2; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"StreamsOfAliasedUnions","sequence":[{"name":"intOrSimpleRecord","type":{"stream":{"items":"TestModel.AliasedIntOrSimpleRecord"}}},{"name":"nullableIntOrSimpleRecord","type":{"stream":{"items":"TestModel.AliasedNullableIntSimpleRecord"}}}]},"types":[{"name":"AliasedIntOrSimpleRecord","type":[{"tag":"int32","type":"int32"},{"tag":"SimpleRecord","type":"TestModel.SimpleRecord"}]},{"name":"AliasedNullableIntSimpleRecord","type":[null,{"tag":"int32","type":"int32"},{"tag":"SimpleRecord","type":"TestModel.SimpleRecord"}]},{"name":"SimpleRecord","fields":[{"name":"x","type":"int32"},{"name":"y","type":"int32"},{"name":"z","type":"int32"}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_int_or_simple_record_(self, value) + write_nullable_int_or_simple_record_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_int_or_simple_record or end_int_or_simple_record"; + elseif state == 1 + name = "write_nullable_int_or_simple_record or end_nullable_int_or_simple_record"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/StreamsOfUnionsReaderBase.m b/matlab/generated/+test_model/StreamsOfUnionsReaderBase.m new file mode 100644 index 00000000..04f6642f --- /dev/null +++ b/matlab/generated/+test_model/StreamsOfUnionsReaderBase.m @@ -0,0 +1,107 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef StreamsOfUnionsReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = StreamsOfUnionsReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 2 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function more = has_int_or_simple_record(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + more = self.has_int_or_simple_record_(); + if ~more + self.state_ = 1; + end + end + + function value = read_int_or_simple_record(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_int_or_simple_record_(); + end + + % Ordinal 1 + function more = has_nullable_int_or_simple_record(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + more = self.has_nullable_int_or_simple_record_(); + if ~more + self.state_ = 2; + end + end + + function value = read_nullable_int_or_simple_record(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_nullable_int_or_simple_record_(); + end + + function copy_to(self, writer) + while self.has_int_or_simple_record() + item = self.read_int_or_simple_record(); + writer.write_int_or_simple_record({item}); + end + writer.end_int_or_simple_record(); + while self.has_nullable_int_or_simple_record() + item = self.read_nullable_int_or_simple_record(); + writer.write_nullable_int_or_simple_record({item}); + end + writer.end_nullable_int_or_simple_record(); + end + end + + methods (Static) + function res = schema() + res = test_model.StreamsOfUnionsWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + has_int_or_simple_record_(self) + read_int_or_simple_record_(self) + has_nullable_int_or_simple_record_(self) + read_nullable_int_or_simple_record_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_int_or_simple_record"; + elseif state == 1 + name = "read_nullable_int_or_simple_record"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/StreamsOfUnionsWriterBase.m b/matlab/generated/+test_model/StreamsOfUnionsWriterBase.m new file mode 100644 index 00000000..565dbc1b --- /dev/null +++ b/matlab/generated/+test_model/StreamsOfUnionsWriterBase.m @@ -0,0 +1,90 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol StreamsOfUnions +classdef (Abstract) StreamsOfUnionsWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = StreamsOfUnionsWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 2 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_int_or_simple_record(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_int_or_simple_record_(value); + end + + function end_int_or_simple_record(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.end_stream_(); + self.state_ = 1; + end + + % Ordinal 1 + function write_nullable_int_or_simple_record(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_nullable_int_or_simple_record_(value); + end + + function end_nullable_int_or_simple_record(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.end_stream_(); + self.state_ = 2; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"StreamsOfUnions","sequence":[{"name":"intOrSimpleRecord","type":{"stream":{"items":[{"tag":"int32","type":"int32"},{"tag":"SimpleRecord","type":"TestModel.SimpleRecord"}]}}},{"name":"nullableIntOrSimpleRecord","type":{"stream":{"items":[null,{"tag":"int32","type":"int32"},{"tag":"SimpleRecord","type":"TestModel.SimpleRecord"}]}}}]},"types":[{"name":"SimpleRecord","fields":[{"name":"x","type":"int32"},{"name":"y","type":"int32"},{"name":"z","type":"int32"}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_int_or_simple_record_(self, value) + write_nullable_int_or_simple_record_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_int_or_simple_record or end_int_or_simple_record"; + elseif state == 1 + name = "write_nullable_int_or_simple_record or end_nullable_int_or_simple_record"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/StreamsReaderBase.m b/matlab/generated/+test_model/StreamsReaderBase.m new file mode 100644 index 00000000..803408ec --- /dev/null +++ b/matlab/generated/+test_model/StreamsReaderBase.m @@ -0,0 +1,165 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef StreamsReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = StreamsReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 4 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function more = has_int_data(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + more = self.has_int_data_(); + if ~more + self.state_ = 1; + end + end + + function value = read_int_data(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_int_data_(); + end + + % Ordinal 1 + function more = has_optional_int_data(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + more = self.has_optional_int_data_(); + if ~more + self.state_ = 2; + end + end + + function value = read_optional_int_data(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_optional_int_data_(); + end + + % Ordinal 2 + function more = has_record_with_optional_vector_data(self) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + more = self.has_record_with_optional_vector_data_(); + if ~more + self.state_ = 3; + end + end + + function value = read_record_with_optional_vector_data(self) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + value = self.read_record_with_optional_vector_data_(); + end + + % Ordinal 3 + function more = has_fixed_vector(self) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + more = self.has_fixed_vector_(); + if ~more + self.state_ = 4; + end + end + + function value = read_fixed_vector(self) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + value = self.read_fixed_vector_(); + end + + function copy_to(self, writer) + while self.has_int_data() + item = self.read_int_data(); + writer.write_int_data({item}); + end + writer.end_int_data(); + while self.has_optional_int_data() + item = self.read_optional_int_data(); + writer.write_optional_int_data({item}); + end + writer.end_optional_int_data(); + while self.has_record_with_optional_vector_data() + item = self.read_record_with_optional_vector_data(); + writer.write_record_with_optional_vector_data({item}); + end + writer.end_record_with_optional_vector_data(); + while self.has_fixed_vector() + item = self.read_fixed_vector(); + writer.write_fixed_vector({item}); + end + writer.end_fixed_vector(); + end + end + + methods (Static) + function res = schema() + res = test_model.StreamsWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + has_int_data_(self) + read_int_data_(self) + has_optional_int_data_(self) + read_optional_int_data_(self) + has_record_with_optional_vector_data_(self) + read_record_with_optional_vector_data_(self) + has_fixed_vector_(self) + read_fixed_vector_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_int_data"; + elseif state == 1 + name = "read_optional_int_data"; + elseif state == 2 + name = "read_record_with_optional_vector_data"; + elseif state == 3 + name = "read_fixed_vector"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/StreamsWriterBase.m b/matlab/generated/+test_model/StreamsWriterBase.m new file mode 100644 index 00000000..940a39f7 --- /dev/null +++ b/matlab/generated/+test_model/StreamsWriterBase.m @@ -0,0 +1,132 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol Streams +classdef (Abstract) StreamsWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = StreamsWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 4 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_int_data(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_int_data_(value); + end + + function end_int_data(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.end_stream_(); + self.state_ = 1; + end + + % Ordinal 1 + function write_optional_int_data(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_optional_int_data_(value); + end + + function end_optional_int_data(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.end_stream_(); + self.state_ = 2; + end + + % Ordinal 2 + function write_record_with_optional_vector_data(self, value) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + self.write_record_with_optional_vector_data_(value); + end + + function end_record_with_optional_vector_data(self) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + self.end_stream_(); + self.state_ = 3; + end + + % Ordinal 3 + function write_fixed_vector(self, value) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + self.write_fixed_vector_(value); + end + + function end_fixed_vector(self) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + self.end_stream_(); + self.state_ = 4; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"Streams","sequence":[{"name":"intData","type":{"stream":{"items":"int32"}}},{"name":"optionalIntData","type":{"stream":{"items":[null,"int32"]}}},{"name":"recordWithOptionalVectorData","type":{"stream":{"items":"TestModel.RecordWithOptionalVector"}}},{"name":"fixedVector","type":{"stream":{"items":{"vector":{"items":"int32","length":3}}}}}]},"types":[{"name":"RecordWithOptionalVector","fields":[{"name":"optionalVector","type":[null,{"vector":{"items":"int32"}}]}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_int_data_(self, value) + write_optional_int_data_(self, value) + write_record_with_optional_vector_data_(self, value) + write_fixed_vector_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_int_data or end_int_data"; + elseif state == 1 + name = "write_optional_int_data or end_optional_int_data"; + elseif state == 2 + name = "write_record_with_optional_vector_data or end_record_with_optional_vector_data"; + elseif state == 3 + name = "write_fixed_vector or end_fixed_vector"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/StringOrInt32.m b/matlab/generated/+test_model/StringOrInt32.m new file mode 100644 index 00000000..58bb97eb --- /dev/null +++ b/matlab/generated/+test_model/StringOrInt32.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef StringOrInt32 < yardl.Union + methods (Static) + function res = String(value) + res = test_model.StringOrInt32(1, value); + end + + function res = Int32(value) + res = test_model.StringOrInt32(2, value); + end + + function z = zeros(varargin) + elem = test_model.StringOrInt32(0, yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function res = isString(self) + res = self.index == 1; + end + + function res = isInt32(self) + res = self.index == 2; + end + + function eq = eq(self, other) + eq = isa(other, "test_model.StringOrInt32") && isequal(self.index, other.index) && isequal(self.value, other.value); + end + + function ne = ne(self, other) + ne = ~self.eq(other); + end + + function t = tag(self) + tags_ = ["String", "Int32"]; + t = tags_(self.index_); + end + end +end diff --git a/matlab/generated/+test_model/StringsReaderBase.m b/matlab/generated/+test_model/StringsReaderBase.m new file mode 100644 index 00000000..bc79a89f --- /dev/null +++ b/matlab/generated/+test_model/StringsReaderBase.m @@ -0,0 +1,77 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef StringsReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = StringsReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 2 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function value = read_single_string(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_single_string_(); + self.state_ = 1; + end + + % Ordinal 1 + function value = read_rec_with_string(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_rec_with_string_(); + self.state_ = 2; + end + + function copy_to(self, writer) + writer.write_single_string(self.read_single_string()); + writer.write_rec_with_string(self.read_rec_with_string()); + end + end + + methods (Static) + function res = schema() + res = test_model.StringsWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + read_single_string_(self) + read_rec_with_string_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_single_string"; + elseif state == 1 + name = "read_rec_with_string"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/StringsWriterBase.m b/matlab/generated/+test_model/StringsWriterBase.m new file mode 100644 index 00000000..7c2d5b92 --- /dev/null +++ b/matlab/generated/+test_model/StringsWriterBase.m @@ -0,0 +1,74 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol Strings +classdef (Abstract) StringsWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = StringsWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 2 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_single_string(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_single_string_(value); + self.state_ = 1; + end + + % Ordinal 1 + function write_rec_with_string(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_rec_with_string_(value); + self.state_ = 2; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"Strings","sequence":[{"name":"singleString","type":"string"},{"name":"recWithString","type":"TestModel.RecordWithStrings"}]},"types":[{"name":"RecordWithStrings","fields":[{"name":"a","type":"string"},{"name":"b","type":"string"}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_single_string_(self, value) + write_rec_with_string_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_single_string"; + elseif state == 1 + name = "write_rec_with_string"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/SubarraysInRecordsReaderBase.m b/matlab/generated/+test_model/SubarraysInRecordsReaderBase.m new file mode 100644 index 00000000..00332db1 --- /dev/null +++ b/matlab/generated/+test_model/SubarraysInRecordsReaderBase.m @@ -0,0 +1,77 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef SubarraysInRecordsReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = SubarraysInRecordsReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 2 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function value = read_with_fixed_subarrays(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_with_fixed_subarrays_(); + self.state_ = 1; + end + + % Ordinal 1 + function value = read_with_vlen_subarrays(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_with_vlen_subarrays_(); + self.state_ = 2; + end + + function copy_to(self, writer) + writer.write_with_fixed_subarrays(self.read_with_fixed_subarrays()); + writer.write_with_vlen_subarrays(self.read_with_vlen_subarrays()); + end + end + + methods (Static) + function res = schema() + res = test_model.SubarraysInRecordsWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + read_with_fixed_subarrays_(self) + read_with_vlen_subarrays_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_with_fixed_subarrays"; + elseif state == 1 + name = "read_with_vlen_subarrays"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/SubarraysInRecordsWriterBase.m b/matlab/generated/+test_model/SubarraysInRecordsWriterBase.m new file mode 100644 index 00000000..89d53486 --- /dev/null +++ b/matlab/generated/+test_model/SubarraysInRecordsWriterBase.m @@ -0,0 +1,74 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol SubarraysInRecords +classdef (Abstract) SubarraysInRecordsWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = SubarraysInRecordsWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 2 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_with_fixed_subarrays(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_with_fixed_subarrays_(value); + self.state_ = 1; + end + + % Ordinal 1 + function write_with_vlen_subarrays(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_with_vlen_subarrays_(value); + self.state_ = 2; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"SubarraysInRecords","sequence":[{"name":"withFixedSubarrays","type":{"array":{"items":"TestModel.RecordWithFixedCollections"}}},{"name":"withVlenSubarrays","type":{"array":{"items":"TestModel.RecordWithVlenCollections"}}}]},"types":[{"name":"RecordWithFixedCollections","fields":[{"name":"fixedVector","type":{"vector":{"items":"int32","length":3}}},{"name":"fixedArray","type":{"array":{"items":"int32","dimensions":[{"length":2},{"length":3}]}}}]},{"name":"RecordWithVlenCollections","fields":[{"name":"vector","type":{"vector":{"items":"int32"}}},{"name":"array","type":{"array":{"items":"int32","dimensions":2}}}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_with_fixed_subarrays_(self, value) + write_with_vlen_subarrays_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_with_fixed_subarrays"; + elseif state == 1 + name = "write_with_vlen_subarrays"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/SubarraysReaderBase.m b/matlab/generated/+test_model/SubarraysReaderBase.m new file mode 100644 index 00000000..5efef824 --- /dev/null +++ b/matlab/generated/+test_model/SubarraysReaderBase.m @@ -0,0 +1,175 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef SubarraysReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = SubarraysReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 9 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function value = read_dynamic_with_fixed_int_subarray(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_dynamic_with_fixed_int_subarray_(); + self.state_ = 1; + end + + % Ordinal 1 + function value = read_dynamic_with_fixed_float_subarray(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_dynamic_with_fixed_float_subarray_(); + self.state_ = 2; + end + + % Ordinal 2 + function value = read_known_dim_count_with_fixed_int_subarray(self) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + value = self.read_known_dim_count_with_fixed_int_subarray_(); + self.state_ = 3; + end + + % Ordinal 3 + function value = read_known_dim_count_with_fixed_float_subarray(self) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + value = self.read_known_dim_count_with_fixed_float_subarray_(); + self.state_ = 4; + end + + % Ordinal 4 + function value = read_fixed_with_fixed_int_subarray(self) + if self.state_ ~= 4 + self.raise_unexpected_state_(4); + end + + value = self.read_fixed_with_fixed_int_subarray_(); + self.state_ = 5; + end + + % Ordinal 5 + function value = read_fixed_with_fixed_float_subarray(self) + if self.state_ ~= 5 + self.raise_unexpected_state_(5); + end + + value = self.read_fixed_with_fixed_float_subarray_(); + self.state_ = 6; + end + + % Ordinal 6 + function value = read_nested_subarray(self) + if self.state_ ~= 6 + self.raise_unexpected_state_(6); + end + + value = self.read_nested_subarray_(); + self.state_ = 7; + end + + % Ordinal 7 + function value = read_dynamic_with_fixed_vector_subarray(self) + if self.state_ ~= 7 + self.raise_unexpected_state_(7); + end + + value = self.read_dynamic_with_fixed_vector_subarray_(); + self.state_ = 8; + end + + % Ordinal 8 + function value = read_generic_subarray(self) + if self.state_ ~= 8 + self.raise_unexpected_state_(8); + end + + value = self.read_generic_subarray_(); + self.state_ = 9; + end + + function copy_to(self, writer) + writer.write_dynamic_with_fixed_int_subarray(self.read_dynamic_with_fixed_int_subarray()); + writer.write_dynamic_with_fixed_float_subarray(self.read_dynamic_with_fixed_float_subarray()); + writer.write_known_dim_count_with_fixed_int_subarray(self.read_known_dim_count_with_fixed_int_subarray()); + writer.write_known_dim_count_with_fixed_float_subarray(self.read_known_dim_count_with_fixed_float_subarray()); + writer.write_fixed_with_fixed_int_subarray(self.read_fixed_with_fixed_int_subarray()); + writer.write_fixed_with_fixed_float_subarray(self.read_fixed_with_fixed_float_subarray()); + writer.write_nested_subarray(self.read_nested_subarray()); + writer.write_dynamic_with_fixed_vector_subarray(self.read_dynamic_with_fixed_vector_subarray()); + writer.write_generic_subarray(self.read_generic_subarray()); + end + end + + methods (Static) + function res = schema() + res = test_model.SubarraysWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + read_dynamic_with_fixed_int_subarray_(self) + read_dynamic_with_fixed_float_subarray_(self) + read_known_dim_count_with_fixed_int_subarray_(self) + read_known_dim_count_with_fixed_float_subarray_(self) + read_fixed_with_fixed_int_subarray_(self) + read_fixed_with_fixed_float_subarray_(self) + read_nested_subarray_(self) + read_dynamic_with_fixed_vector_subarray_(self) + read_generic_subarray_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_dynamic_with_fixed_int_subarray"; + elseif state == 1 + name = "read_dynamic_with_fixed_float_subarray"; + elseif state == 2 + name = "read_known_dim_count_with_fixed_int_subarray"; + elseif state == 3 + name = "read_known_dim_count_with_fixed_float_subarray"; + elseif state == 4 + name = "read_fixed_with_fixed_int_subarray"; + elseif state == 5 + name = "read_fixed_with_fixed_float_subarray"; + elseif state == 6 + name = "read_nested_subarray"; + elseif state == 7 + name = "read_dynamic_with_fixed_vector_subarray"; + elseif state == 8 + name = "read_generic_subarray"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/SubarraysWriterBase.m b/matlab/generated/+test_model/SubarraysWriterBase.m new file mode 100644 index 00000000..014763fa --- /dev/null +++ b/matlab/generated/+test_model/SubarraysWriterBase.m @@ -0,0 +1,165 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol Subarrays +classdef (Abstract) SubarraysWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = SubarraysWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 9 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_dynamic_with_fixed_int_subarray(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_dynamic_with_fixed_int_subarray_(value); + self.state_ = 1; + end + + % Ordinal 1 + function write_dynamic_with_fixed_float_subarray(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_dynamic_with_fixed_float_subarray_(value); + self.state_ = 2; + end + + % Ordinal 2 + function write_known_dim_count_with_fixed_int_subarray(self, value) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + self.write_known_dim_count_with_fixed_int_subarray_(value); + self.state_ = 3; + end + + % Ordinal 3 + function write_known_dim_count_with_fixed_float_subarray(self, value) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + self.write_known_dim_count_with_fixed_float_subarray_(value); + self.state_ = 4; + end + + % Ordinal 4 + function write_fixed_with_fixed_int_subarray(self, value) + if self.state_ ~= 4 + self.raise_unexpected_state_(4); + end + + self.write_fixed_with_fixed_int_subarray_(value); + self.state_ = 5; + end + + % Ordinal 5 + function write_fixed_with_fixed_float_subarray(self, value) + if self.state_ ~= 5 + self.raise_unexpected_state_(5); + end + + self.write_fixed_with_fixed_float_subarray_(value); + self.state_ = 6; + end + + % Ordinal 6 + function write_nested_subarray(self, value) + if self.state_ ~= 6 + self.raise_unexpected_state_(6); + end + + self.write_nested_subarray_(value); + self.state_ = 7; + end + + % Ordinal 7 + function write_dynamic_with_fixed_vector_subarray(self, value) + if self.state_ ~= 7 + self.raise_unexpected_state_(7); + end + + self.write_dynamic_with_fixed_vector_subarray_(value); + self.state_ = 8; + end + + % Ordinal 8 + function write_generic_subarray(self, value) + if self.state_ ~= 8 + self.raise_unexpected_state_(8); + end + + self.write_generic_subarray_(value); + self.state_ = 9; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"Subarrays","sequence":[{"name":"dynamicWithFixedIntSubarray","type":{"array":{"items":{"array":{"items":"int32","dimensions":[{"length":3}]}}}}},{"name":"dynamicWithFixedFloatSubarray","type":{"array":{"items":{"array":{"items":"float32","dimensions":[{"length":3}]}}}}},{"name":"knownDimCountWithFixedIntSubarray","type":{"array":{"items":{"array":{"items":"int32","dimensions":[{"length":3}]}},"dimensions":1}}},{"name":"knownDimCountWithFixedFloatSubarray","type":{"array":{"items":{"array":{"items":"float32","dimensions":[{"length":3}]}},"dimensions":1}}},{"name":"fixedWithFixedIntSubarray","type":{"array":{"items":{"array":{"items":"int32","dimensions":[{"length":3}]}},"dimensions":[{"length":2}]}}},{"name":"fixedWithFixedFloatSubarray","type":{"array":{"items":{"array":{"items":"float32","dimensions":[{"length":3}]}},"dimensions":[{"length":2}]}}},{"name":"nestedSubarray","type":{"array":{"items":{"array":{"items":{"array":{"items":"int32","dimensions":[{"length":3}]}},"dimensions":[{"length":2}]}}}}},{"name":"dynamicWithFixedVectorSubarray","type":{"array":{"items":{"vector":{"items":"int32","length":3}}}}},{"name":"genericSubarray","type":{"name":"TestModel.Image","typeArguments":[{"array":{"items":"int32","dimensions":[{"length":3}]}}]}}]},"types":[{"name":"Image","typeParameters":["T"],"type":{"array":{"items":"T","dimensions":[{"name":"x"},{"name":"y"}]}}},{"name":"Image","typeParameters":["T"],"type":{"name":"Image.Image","typeArguments":["T"]}}]}'); + end + end + + methods (Abstract, Access=protected) + write_dynamic_with_fixed_int_subarray_(self, value) + write_dynamic_with_fixed_float_subarray_(self, value) + write_known_dim_count_with_fixed_int_subarray_(self, value) + write_known_dim_count_with_fixed_float_subarray_(self, value) + write_fixed_with_fixed_int_subarray_(self, value) + write_fixed_with_fixed_float_subarray_(self, value) + write_nested_subarray_(self, value) + write_dynamic_with_fixed_vector_subarray_(self, value) + write_generic_subarray_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_dynamic_with_fixed_int_subarray"; + elseif state == 1 + name = "write_dynamic_with_fixed_float_subarray"; + elseif state == 2 + name = "write_known_dim_count_with_fixed_int_subarray"; + elseif state == 3 + name = "write_known_dim_count_with_fixed_float_subarray"; + elseif state == 4 + name = "write_fixed_with_fixed_int_subarray"; + elseif state == 5 + name = "write_fixed_with_fixed_float_subarray"; + elseif state == 6 + name = "write_nested_subarray"; + elseif state == 7 + name = "write_dynamic_with_fixed_vector_subarray"; + elseif state == 8 + name = "write_generic_subarray"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/TextFormat.m b/matlab/generated/+test_model/TextFormat.m new file mode 100644 index 00000000..60a46b9c --- /dev/null +++ b/matlab/generated/+test_model/TextFormat.m @@ -0,0 +1,4 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TextFormat < basic_types.TextFormat +end diff --git a/matlab/generated/+test_model/TupleWithRecords.m b/matlab/generated/+test_model/TupleWithRecords.m new file mode 100644 index 00000000..dbc507d8 --- /dev/null +++ b/matlab/generated/+test_model/TupleWithRecords.m @@ -0,0 +1,45 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TupleWithRecords < handle + properties + a + b + end + + methods + function self = TupleWithRecords(kwargs) + arguments + kwargs.a = test_model.SimpleRecord(); + kwargs.b = test_model.SimpleRecord(); + end + self.a = kwargs.a; + self.b = kwargs.b; + end + + function res = eq(self, other) + res = ... + isa(other, "test_model.TupleWithRecords") && ... + isequal(self.a, other.a) && ... + isequal(self.b, other.b); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + + methods (Static) + function z = zeros(varargin) + elem = test_model.TupleWithRecords(); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/UInt64Enum.m b/matlab/generated/+test_model/UInt64Enum.m new file mode 100644 index 00000000..41a5c10f --- /dev/null +++ b/matlab/generated/+test_model/UInt64Enum.m @@ -0,0 +1,22 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef UInt64Enum < uint64 + methods (Static) + function v = A + v = test_model.UInt64Enum(9223372036854775808); + end + + function z = zeros(varargin) + elem = test_model.UInt64Enum(0); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/matlab/generated/+test_model/UOrV.m b/matlab/generated/+test_model/UOrV.m new file mode 100644 index 00000000..9f6a006e --- /dev/null +++ b/matlab/generated/+test_model/UOrV.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef UOrV < yardl.Union + methods (Static) + function res = U(value) + res = test_model.UOrV(1, value); + end + + function res = V(value) + res = test_model.UOrV(2, value); + end + + function z = zeros(varargin) + elem = test_model.UOrV(0, yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function res = isU(self) + res = self.index == 1; + end + + function res = isV(self) + res = self.index == 2; + end + + function eq = eq(self, other) + eq = isa(other, "test_model.UOrV") && isequal(self.index, other.index) && isequal(self.value, other.value); + end + + function ne = ne(self, other) + ne = ~self.eq(other); + end + + function t = tag(self) + tags_ = ["U", "V"]; + t = tags_(self.index_); + end + end +end diff --git a/matlab/generated/+test_model/UnionsReaderBase.m b/matlab/generated/+test_model/UnionsReaderBase.m new file mode 100644 index 00000000..ed23e28b --- /dev/null +++ b/matlab/generated/+test_model/UnionsReaderBase.m @@ -0,0 +1,105 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef UnionsReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = UnionsReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 4 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function value = read_int_or_simple_record(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_int_or_simple_record_(); + self.state_ = 1; + end + + % Ordinal 1 + function value = read_int_or_record_with_vlens(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_int_or_record_with_vlens_(); + self.state_ = 2; + end + + % Ordinal 2 + function value = read_monosotate_or_int_or_simple_record(self) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + value = self.read_monosotate_or_int_or_simple_record_(); + self.state_ = 3; + end + + % Ordinal 3 + function value = read_record_with_unions(self) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + value = self.read_record_with_unions_(); + self.state_ = 4; + end + + function copy_to(self, writer) + writer.write_int_or_simple_record(self.read_int_or_simple_record()); + writer.write_int_or_record_with_vlens(self.read_int_or_record_with_vlens()); + writer.write_monosotate_or_int_or_simple_record(self.read_monosotate_or_int_or_simple_record()); + writer.write_record_with_unions(self.read_record_with_unions()); + end + end + + methods (Static) + function res = schema() + res = test_model.UnionsWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + read_int_or_simple_record_(self) + read_int_or_record_with_vlens_(self) + read_monosotate_or_int_or_simple_record_(self) + read_record_with_unions_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_int_or_simple_record"; + elseif state == 1 + name = "read_int_or_record_with_vlens"; + elseif state == 2 + name = "read_monosotate_or_int_or_simple_record"; + elseif state == 3 + name = "read_record_with_unions"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/UnionsWriterBase.m b/matlab/generated/+test_model/UnionsWriterBase.m new file mode 100644 index 00000000..d90aab88 --- /dev/null +++ b/matlab/generated/+test_model/UnionsWriterBase.m @@ -0,0 +1,100 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol Unions +classdef (Abstract) UnionsWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = UnionsWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 4 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_int_or_simple_record(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_int_or_simple_record_(value); + self.state_ = 1; + end + + % Ordinal 1 + function write_int_or_record_with_vlens(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_int_or_record_with_vlens_(value); + self.state_ = 2; + end + + % Ordinal 2 + function write_monosotate_or_int_or_simple_record(self, value) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + self.write_monosotate_or_int_or_simple_record_(value); + self.state_ = 3; + end + + % Ordinal 3 + function write_record_with_unions(self, value) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + self.write_record_with_unions_(value); + self.state_ = 4; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"Unions","sequence":[{"name":"intOrSimpleRecord","type":[{"tag":"int32","type":"int32"},{"tag":"SimpleRecord","type":"TestModel.SimpleRecord"}]},{"name":"intOrRecordWithVlens","type":[{"tag":"int32","type":"int32"},{"tag":"RecordWithVlens","type":"TestModel.RecordWithVlens"}]},{"name":"monosotateOrIntOrSimpleRecord","type":[null,{"tag":"int32","type":"int32"},{"tag":"SimpleRecord","type":"TestModel.SimpleRecord"}]},{"name":"recordWithUnions","type":"BasicTypes.RecordWithUnions"}]},"types":[{"name":"DaysOfWeek","values":[{"symbol":"monday","value":1},{"symbol":"tuesday","value":2},{"symbol":"wednesday","value":4},{"symbol":"thursday","value":8},{"symbol":"friday","value":16},{"symbol":"saturday","value":32},{"symbol":"sunday","value":64}]},{"name":"Fruits","values":[{"symbol":"apple","value":0},{"symbol":"banana","value":1},{"symbol":"pear","value":2}]},{"name":"GenericNullableUnion2","typeParameters":["T1","T2"],"type":[null,{"tag":"T1","type":"T1"},{"tag":"T2","type":"T2"}]},{"name":"RecordWithUnions","fields":[{"name":"nullOrIntOrString","type":[null,{"tag":"int32","type":"int32"},{"tag":"string","type":"string"}]},{"name":"dateOrDatetime","type":[{"tag":"time","type":"time"},{"tag":"datetime","type":"datetime"}]},{"name":"nullOrFruitsOrDaysOfWeek","type":{"name":"BasicTypes.GenericNullableUnion2","typeArguments":["BasicTypes.Fruits","BasicTypes.DaysOfWeek"]}}]},{"name":"RecordWithVlens","fields":[{"name":"a","type":{"vector":{"items":"TestModel.SimpleRecord"}}},{"name":"b","type":"int32"},{"name":"c","type":"int32"}]},{"name":"SimpleRecord","fields":[{"name":"x","type":"int32"},{"name":"y","type":"int32"},{"name":"z","type":"int32"}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_int_or_simple_record_(self, value) + write_int_or_record_with_vlens_(self, value) + write_monosotate_or_int_or_simple_record_(self, value) + write_record_with_unions_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_int_or_simple_record"; + elseif state == 1 + name = "write_int_or_record_with_vlens"; + elseif state == 2 + name = "write_monosotate_or_int_or_simple_record"; + elseif state == 3 + name = "write_record_with_unions"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+test_model/VectorOfGenericRecords.m b/matlab/generated/+test_model/VectorOfGenericRecords.m new file mode 100644 index 00000000..a8f035c4 --- /dev/null +++ b/matlab/generated/+test_model/VectorOfGenericRecords.m @@ -0,0 +1,5 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +function a = VectorOfGenericRecords(array) + a = array; +end diff --git a/matlab/generated/+test_model/VectorOrScalar.m b/matlab/generated/+test_model/VectorOrScalar.m new file mode 100644 index 00000000..a51eca2c --- /dev/null +++ b/matlab/generated/+test_model/VectorOrScalar.m @@ -0,0 +1,49 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef VectorOrScalar < yardl.Union + methods (Static) + function res = Vector(value) + res = test_model.VectorOrScalar(1, value); + end + + function res = Scalar(value) + res = test_model.VectorOrScalar(2, value); + end + + function z = zeros(varargin) + elem = test_model.VectorOrScalar(0, yardl.None); + if nargin == 0 + z = elem; + return; + end + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + + methods + function res = isVector(self) + res = self.index == 1; + end + + function res = isScalar(self) + res = self.index == 2; + end + + function eq = eq(self, other) + eq = isa(other, "test_model.VectorOrScalar") && isequal(self.index, other.index) && isequal(self.value, other.value); + end + + function ne = ne(self, other) + ne = ~self.eq(other); + end + + function t = tag(self) + tags_ = ["Vector", "Scalar"]; + t = tags_(self.index_); + end + end +end diff --git a/matlab/generated/+test_model/VlensReaderBase.m b/matlab/generated/+test_model/VlensReaderBase.m new file mode 100644 index 00000000..9d80cf61 --- /dev/null +++ b/matlab/generated/+test_model/VlensReaderBase.m @@ -0,0 +1,105 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef VlensReaderBase < handle + properties (Access=protected) + state_ + end + + methods + function self = VlensReaderBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 4 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function value = read_int_vector(self) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + value = self.read_int_vector_(); + self.state_ = 1; + end + + % Ordinal 1 + function value = read_complex_vector(self) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + value = self.read_complex_vector_(); + self.state_ = 2; + end + + % Ordinal 2 + function value = read_record_with_vlens(self) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + value = self.read_record_with_vlens_(); + self.state_ = 3; + end + + % Ordinal 3 + function value = read_vlen_of_record_with_vlens(self) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + value = self.read_vlen_of_record_with_vlens_(); + self.state_ = 4; + end + + function copy_to(self, writer) + writer.write_int_vector(self.read_int_vector()); + writer.write_complex_vector(self.read_complex_vector()); + writer.write_record_with_vlens(self.read_record_with_vlens()); + writer.write_vlen_of_record_with_vlens(self.read_vlen_of_record_with_vlens()); + end + end + + methods (Static) + function res = schema() + res = test_model.VlensWriterBase.schema; + end + end + + methods (Abstract, Access=protected) + read_int_vector_(self) + read_complex_vector_(self) + read_record_with_vlens_(self) + read_vlen_of_record_with_vlens_(self) + + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + actual_method = self.state_to_method_name_(actual); + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "read_int_vector"; + elseif state == 1 + name = "read_complex_vector"; + elseif state == 2 + name = "read_record_with_vlens"; + elseif state == 3 + name = "read_vlen_of_record_with_vlens"; + else + name = ""; + end + end + end +end diff --git a/matlab/generated/+test_model/VlensWriterBase.m b/matlab/generated/+test_model/VlensWriterBase.m new file mode 100644 index 00000000..e5be397c --- /dev/null +++ b/matlab/generated/+test_model/VlensWriterBase.m @@ -0,0 +1,100 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +% Abstract writer for protocol Vlens +classdef (Abstract) VlensWriterBase < handle + properties (Access=protected) + state_ + end + + methods + function self = VlensWriterBase() + self.state_ = 0; + end + + function close(self) + self.close_(); + if self.state_ ~= 4 + expected_method = self.state_to_method_name_(self.state_); + throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method)); + end + end + + % Ordinal 0 + function write_int_vector(self, value) + if self.state_ ~= 0 + self.raise_unexpected_state_(0); + end + + self.write_int_vector_(value); + self.state_ = 1; + end + + % Ordinal 1 + function write_complex_vector(self, value) + if self.state_ ~= 1 + self.raise_unexpected_state_(1); + end + + self.write_complex_vector_(value); + self.state_ = 2; + end + + % Ordinal 2 + function write_record_with_vlens(self, value) + if self.state_ ~= 2 + self.raise_unexpected_state_(2); + end + + self.write_record_with_vlens_(value); + self.state_ = 3; + end + + % Ordinal 3 + function write_vlen_of_record_with_vlens(self, value) + if self.state_ ~= 3 + self.raise_unexpected_state_(3); + end + + self.write_vlen_of_record_with_vlens_(value); + self.state_ = 4; + end + end + + methods (Static) + function res = schema() + res = string('{"protocol":{"name":"Vlens","sequence":[{"name":"intVector","type":{"vector":{"items":"int32"}}},{"name":"complexVector","type":{"vector":{"items":"complexfloat32"}}},{"name":"recordWithVlens","type":"TestModel.RecordWithVlens"},{"name":"vlenOfRecordWithVlens","type":{"vector":{"items":"TestModel.RecordWithVlens"}}}]},"types":[{"name":"RecordWithVlens","fields":[{"name":"a","type":{"vector":{"items":"TestModel.SimpleRecord"}}},{"name":"b","type":"int32"},{"name":"c","type":"int32"}]},{"name":"SimpleRecord","fields":[{"name":"x","type":"int32"},{"name":"y","type":"int32"},{"name":"z","type":"int32"}]}]}'); + end + end + + methods (Abstract, Access=protected) + write_int_vector_(self, value) + write_complex_vector_(self, value) + write_record_with_vlens_(self, value) + write_vlen_of_record_with_vlens_(self, value) + + end_stream_(self) + close_(self) + end + + methods (Access=private) + function raise_unexpected_state_(self, actual) + expected_method = self.state_to_method_name_(self.state_); + actual_method = self.state_to_method_name_(actual); + throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method)); + end + + function name = state_to_method_name_(self, state) + if state == 0 + name = "write_int_vector"; + elseif state == 1 + name = "write_complex_vector"; + elseif state == 2 + name = "write_record_with_vlens"; + elseif state == 3 + name = "write_vlen_of_record_with_vlens"; + else + name = ''; + end + end + end +end diff --git a/matlab/generated/+tuples/+binary/TupleSerializer.m b/matlab/generated/+tuples/+binary/TupleSerializer.m new file mode 100644 index 00000000..6229b7b0 --- /dev/null +++ b/matlab/generated/+tuples/+binary/TupleSerializer.m @@ -0,0 +1,25 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef TupleSerializer < yardl.binary.RecordSerializer + methods + function self = TupleSerializer(t1_serializer, t2_serializer) + field_serializers{1} = t1_serializer; + field_serializers{2} = t2_serializer; + self@yardl.binary.RecordSerializer('tuples.Tuple', field_serializers); + end + + function write(self, outstream, value) + arguments + self + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) tuples.Tuple + end + self.write_(outstream, value.v1, value.v2); + end + + function value = read(self, instream) + fields = self.read_(instream); + value = tuples.Tuple(v1=fields{1}, v2=fields{2}); + end + end +end diff --git a/matlab/generated/+tuples/Tuple.m b/matlab/generated/+tuples/Tuple.m new file mode 100644 index 00000000..6e0f491b --- /dev/null +++ b/matlab/generated/+tuples/Tuple.m @@ -0,0 +1,37 @@ +% This file was generated by the "yardl" tool. DO NOT EDIT. + +classdef Tuple < handle + properties + v1 + v2 + end + + methods + function self = Tuple(kwargs) + arguments + kwargs.v1; + kwargs.v2; + end + if ~isfield(kwargs, "v1") + throw(yardl.TypeError("Missing required keyword argument 'v1'")) + end + self.v1 = kwargs.v1; + if ~isfield(kwargs, "v2") + throw(yardl.TypeError("Missing required keyword argument 'v2'")) + end + self.v2 = kwargs.v2; + end + + function res = eq(self, other) + res = ... + isa(other, "tuples.Tuple") && ... + isequal(self.v1, other.v1) && ... + isequal(self.v2, other.v2); + end + + function res = ne(self, other) + res = ~self.eq(other); + end + end + +end diff --git a/matlab/run_sandbox.m b/matlab/run_sandbox.m new file mode 100644 index 00000000..f9df271a --- /dev/null +++ b/matlab/run_sandbox.m @@ -0,0 +1,25 @@ +addpath("./generated"); + +filename = "sandbox_mat.bin"; + +data = [ ... + [892.37889483 - 9932.485937837j; 73.383672763878 - 33.3394472537j], ... + [3883.22890980 + 373.4933837j; 56985.39384393 - 33833.3330128474373j], ... + [283.383672763878 - 33.3394472537j; 3883.22890980 + 373.4933837j], ... +]; + +w = sandbox.binary.HelloWorldWriter(filename); +w.write_data(data); +w.end_data(); +w.close(); + +r = sandbox.binary.HelloWorldReader(filename); +while r.has_data() + values = r.read_data(); + for n = 1:length(values) + disp(values(n)); + end +end +r.close(); + +system(sprintf("hexdump -C %s", filename)); diff --git a/matlab/test/CodedStreamTest.m b/matlab/test/CodedStreamTest.m new file mode 100644 index 00000000..f36c830e --- /dev/null +++ b/matlab/test/CodedStreamTest.m @@ -0,0 +1,229 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef CodedStreamTest < matlab.unittest.TestCase + + methods (Test) + + function testConstructors(testCase) + filename = "/mnt/does_not_exist/foo/bar"; + testCase.verifyError(@() yardl.binary.CodedInputStream(filename), 'yardl:RuntimeError'); + testCase.verifyError(@() yardl.binary.CodedOutputStream(filename), 'yardl:RuntimeError'); + + filename = tempname; + [fid, errmsg] = fopen(filename, 'w'); + w = yardl.binary.CodedOutputStream(fid); + w.close(); + + [fid, errmsg] = fopen(filename, 'r'); + r = yardl.binary.CodedInputStream(fid); + r.close(); + + delete(filename); + end + + function testVarShort(testCase) + entries = int16([0, 1, 5, 33, 0x7E, 0x7F, 0x80, 0x81, 255, 256, 257, 838, 0x3FFF, 0x4000, 0x4001, 0x7FFF]); + + filename = tempname; + w = yardl.binary.CodedOutputStream(filename); + for i = 1:length(entries) + yardl.binary.Int16Serializer.write(w, entries(i)); + yardl.binary.Int16Serializer.write(w, -entries(i)); + end + w.close(); + + r = yardl.binary.CodedInputStream(filename); + for i = 1:length(entries) + testCase.verifyEqual(yardl.binary.Int16Serializer.read(r), entries(i)); + testCase.verifyEqual(yardl.binary.Int16Serializer.read(r), -entries(i)); + end + r.close(); + + delete(filename); + end + + function testVarUShort(testCase) + entries = uint16([0, 1, 5, 33, 0x7E, 0x7F, 0x80, 0x81, 255, 256, 257, 838, 0x3FFF, 0x4000, 0x4001, 0x7FFF, 0x8000, 0x8001, 0xFFFF]); + + filename = tempname; + w = yardl.binary.CodedOutputStream(filename); + for i = 1:length(entries) + yardl.binary.Uint16Serializer.write(w, entries(i)); + end + w.close(); + + r = yardl.binary.CodedInputStream(filename); + for i = 1:length(entries) + testCase.verifyEqual(yardl.binary.Uint16Serializer.read(r), entries(i)); + end + r.close(); + + delete(filename); + end + + function testVarIntegers(testCase) + entries = uint32([ 0, 1, 5, 33, 0x7E, 0x7F, 0x80, 0x81, 255, 256, 257, 838, 283928, 2847772, 3443, 0x7FFFFFFF, 0xFFFFFFFF]); + + filename = tempname; + w = yardl.binary.CodedOutputStream(filename); + for i = 1:length(entries) + yardl.binary.Uint32Serializer.write(w, entries(i)); + + yardl.binary.Int32Serializer.write(w, int32(entries(i))); + yardl.binary.Int32Serializer.write(w, -int32(entries(i))); + + yardl.binary.Uint64Serializer.write(w, uint64(entries(i))); + yardl.binary.Uint64Serializer.write(w, bitor(uint64(entries(i)), uint64(0x800000000))); + + yardl.binary.Int64Serializer.write(w, int64(entries(i))); + yardl.binary.Int64Serializer.write(w, -int64(entries(i))); + yardl.binary.Int64Serializer.write(w, bitor(int64(entries(i)), int64(0x400000000))); + yardl.binary.Int64Serializer.write(w, -bitor(int64(entries(i)), int64(0x400000000))); + end + w.close(); + + r = yardl.binary.CodedInputStream(filename); + for i = 1:length(entries) + testCase.verifyEqual(yardl.binary.Uint32Serializer.read(r), entries(i)); + + testCase.verifyEqual(yardl.binary.Int32Serializer.read(r), int32(entries(i))); + testCase.verifyEqual(yardl.binary.Int32Serializer.read(r), -int32(entries(i))); + + testCase.verifyEqual(yardl.binary.Uint64Serializer.read(r), uint64(entries(i))); + testCase.verifyEqual(yardl.binary.Uint64Serializer.read(r), bitor(uint64(entries(i)), uint64(0x800000000))); + + testCase.verifyEqual(yardl.binary.Int64Serializer.read(r), int64(entries(i))); + testCase.verifyEqual(yardl.binary.Int64Serializer.read(r), -int64(entries(i))); + testCase.verifyEqual(yardl.binary.Int64Serializer.read(r), bitor(int64(entries(i)), int64(0x400000000))); + testCase.verifyEqual(yardl.binary.Int64Serializer.read(r), -bitor(int64(entries(i)), int64(0x400000000))); + end + r.close(); + + delete(filename); + end + + function testBytes(testCase) + filename = tempname; + + val = 42; + unsigned = uint8([0, 1, 5, 33, 0x7E, 0x7F, 0x80, 0x81, 255]); + signed = int8([0, 1, 5, 33, 0x7E, 0x7F, -0x80, -0x7F, -1]); + + unsignedSerializer = yardl.binary.Uint8Serializer; + signedSerializer = yardl.binary.Int8Serializer; + + w = yardl.binary.CodedOutputStream(filename); + w.write_byte(uint8(val)); + testCase.verifyError(@() w.write_byte(-1), 'MATLAB:validators:mustBeA'); + testCase.verifyError(@() w.write_byte(256), 'MATLAB:validators:mustBeA'); + + w.write_bytes(unsigned); + testCase.verifyError(@() w.write_bytes(signed), 'MATLAB:validators:mustBeA'); + + unsignedSerializer.write(w, val); + unsignedSerializer.write_trivially(w, unsigned); + + signedSerializer.write(w, -val); + signedSerializer.write_trivially(w, signed); + w.close(); + + r = yardl.binary.CodedInputStream(filename); + testCase.verifyEqual(r.read_byte(), uint8(val)); + testCase.verifyEqual(r.read_bytes(length(unsigned)), unsigned); + testCase.verifyEqual(unsignedSerializer.read(r), uint8(val)); + testCase.verifyEqual(unsignedSerializer.read_trivially(r, length(unsigned)), unsigned); + testCase.verifyEqual(signedSerializer.read(r), int8(-val)); + testCase.verifyEqual(signedSerializer.read_trivially(r, length(signed)), signed); + r.close(); + + delete(filename); + end + + function testFloats(testCase) + filename = tempname; + + f = single(42.75); + d = double(-42.75); + fs = rand(123, 89, 'single'); + ds = rand(123, 89); + + cf = single(complex(7, -8)); + df = complex(7, -8); + cfs = complex(rand(123, 89, 'single'), rand(123, 89, 'single')); + dfs = complex(rand(123, 89), rand(123, 89)); + + float32Serializer = yardl.binary.Float32Serializer; + float64Serializer = yardl.binary.Float64Serializer; + complexFloat32Serializer = yardl.binary.Complexfloat32Serializer; + complexFloat64Serializer = yardl.binary.Complexfloat64Serializer; + + w = yardl.binary.CodedOutputStream(filename); + float32Serializer.write(w, f); + float64Serializer.write(w, d); + float32Serializer.write_trivially(w, fs); + float64Serializer.write_trivially(w, ds); + complexFloat32Serializer.write(w, cf); + complexFloat64Serializer.write(w, df); + complexFloat32Serializer.write_trivially(w, cfs); + complexFloat64Serializer.write_trivially(w, dfs); + w.close(); + + r = yardl.binary.CodedInputStream(filename); + testCase.verifyEqual(float32Serializer.read(r), f); + testCase.verifyEqual(float64Serializer.read(r), d); + testCase.verifyEqual(float32Serializer.read_trivially(r, size(fs)), fs); + testCase.verifyEqual(float64Serializer.read_trivially(r, size(ds)), ds); + testCase.verifyEqual(complexFloat32Serializer.read(r), cf); + testCase.verifyEqual(complexFloat64Serializer.read(r), df); + testCase.verifyEqual(complexFloat32Serializer.read_trivially(r, size(cfs)), cfs); + testCase.verifyEqual(complexFloat64Serializer.read_trivially(r, size(dfs)), dfs); + r.close(); + + delete(filename); + end + + function testBools(testCase) + filename = tempname; + + bools = [true, false, true, false]; + boolSerializer = yardl.binary.BoolSerializer; + + w = yardl.binary.CodedOutputStream(filename); + boolSerializer.write(w, true); + boolSerializer.write_trivially(w, bools); + w.close(); + + r = yardl.binary.CodedInputStream(filename); + testCase.verifyEqual(boolSerializer.read(r), true); + testCase.verifyEqual(boolSerializer.read_trivially(r, size(bools)), bools); + r.close(); + + delete(filename); + end + + function testNonTrivialErrors(testCase) + filename = tempname; + + int16Serializer = yardl.binary.Int16Serializer; + int32Serializer = yardl.binary.Int32Serializer; + int64Serializer = yardl.binary.Int64Serializer; + uint16Serializer = yardl.binary.Uint16Serializer; + uint32Serializer = yardl.binary.Uint32Serializer; + uint64Serializer = yardl.binary.Uint64Serializer; + stringSerializer = yardl.binary.StringSerializer; + + w = yardl.binary.CodedOutputStream(filename); + testCase.verifyError(@() int16Serializer.write_trivially(w, []), 'yardl:TypeError'); + testCase.verifyError(@() int32Serializer.write_trivially(w, []), 'yardl:TypeError'); + testCase.verifyError(@() int64Serializer.write_trivially(w, []), 'yardl:TypeError'); + testCase.verifyError(@() uint16Serializer.write_trivially(w, []), 'yardl:TypeError'); + testCase.verifyError(@() uint32Serializer.write_trivially(w, []), 'yardl:TypeError'); + testCase.verifyError(@() uint64Serializer.write_trivially(w, []), 'yardl:TypeError'); + testCase.verifyError(@() stringSerializer.write_trivially(w, []), 'yardl:TypeError'); + w.close(); + + delete(filename); + end + end +end diff --git a/matlab/test/ComputedFieldsTest.m b/matlab/test/ComputedFieldsTest.m new file mode 100644 index 00000000..25a8b00c --- /dev/null +++ b/matlab/test/ComputedFieldsTest.m @@ -0,0 +1,214 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef ComputedFieldsTest < matlab.unittest.TestCase + methods (Test) + + function testFieldAccess(testCase) + r = test_model.RecordWithComputedFields(); + + r.int_field = int32(42); + testCase.verifyEqual(r.access_int_field(), int32(42)); + testCase.verifyEqual(r.access_other_computed_field(), r.access_int_field()); + + r.string_field = "hello"; + testCase.verifyEqual(r.access_string_field(), "hello"); + + r.tuple_field = test_model.MyTuple(v1=1, v2=2); + testCase.verifyEqual(r.access_tuple_field(), r.tuple_field); + testCase.verifyEqual(r.access_nested_tuple_field(), r.tuple_field.v2); + + r.array_field = int32([[1; 2; 3], [4; 5; 6]]); + testCase.verifyEqual(r.access_array_field(), r.array_field); + testCase.verifyEqual(r.access_array_field_element(), r.array_field(2, 1)); + testCase.verifyEqual(r.access_array_field_element_by_name(), r.array_field(2, 1)); + + r.vector_field = [1, 2, 3, 4]; + testCase.verifyEqual(r.access_vector_field, r.vector_field); + testCase.verifyEqual(r.access_vector_field_element(), r.vector_field(2)); + r.vector_of_vectors_field = int32([[1; 2; 3], [4; 5; 6]]); + testCase.verifyEqual(r.access_vector_of_vectors_field(), r.vector_of_vectors_field(3, 2)); + r.fixed_vector_of_vectors_field = int32([[1; 2; 3], [4; 5; 6]]); + testCase.verifyEqual(r.access_fixed_vector_of_vectors_field(), r.fixed_vector_of_vectors_field(3, 2)); + + r.map_field = dictionary(["hello", "world"], ["world", "bye"]); + testCase.verifyEqual(r.access_map(), r.map_field); + testCase.verifyEqual(r.access_map_entry(), "world"); + testCase.verifyEqual(r.access_map_entry_with_computed_field(), "world"); + testCase.verifyEqual(r.access_map_entry_with_computed_field_nested(), "bye"); + + testCase.verifyError(@() r.access_missing_map_entry(), "MATLAB:dictionary:ScalarKeyNotFound"); + end + + function testLiterals(testCase) + r = test_model.RecordWithComputedFields(); + testCase.verifyEqual(r.int_literal(), 42); + testCase.verifyEqual(int64(r.large_negative_int64_literal()), -int64(0x4000000000000000)); + testCase.verifyEqual(uint64(r.large_u_int64_literal()), 0x8000000000000000); + testCase.verifyEqual(r.string_literal(), "hello"); + end + + function testDimensionIndex(testCase) + r = test_model.RecordWithComputedFields(); + + testCase.verifyEqual(r.array_dimension_x_index(), 0); + testCase.verifyEqual(r.array_dimension_y_index(), 1); + + r.string_field = "y"; + testCase.verifyEqual(r.array_dimension_index_from_string_field(), 1); + + r.string_field = "missing"; + testCase.verifyError(@() r.array_dimension_index_from_string_field(), "yardl:ValueError"); + end + + function testDimensionCount(testCase) + r = test_model.RecordWithComputedFields(); + + testCase.verifyEqual(r.array_dimension_count(), 2); + + r.dynamic_array_field = int32([[1; 2; 3], [4; 5; 6]]); + testCase.verifyEqual(r.dynamic_array_dimension_count(), 2); + r.dynamic_array_field = int32([1, 2, 3]); + testCase.verifyEqual(r.dynamic_array_dimension_count(), 1); + end + + function testVectorSize(testCase) + r = test_model.RecordWithComputedFields(); + testCase.verifyEqual(r.vector_size(), 0); + r.vector_field = [1, 2, 3, 4]; + testCase.verifyEqual(r.vector_size(), 4); + + testCase.verifyEqual(r.fixed_vector_size(), 3); + testCase.verifyEqual(r.fixed_vector_of_vectors_size(), 2); + end + + function testMapSize(testCase) + r = test_model.RecordWithComputedFields(); + testCase.verifyEqual(r.map_size(), 0); + r.map_field = dictionary(["hello", "bonjour"], ["world", "monde"]); + testCase.verifyEqual(r.map_size(), 2); + end + + function testArraySize(testCase) + r = test_model.RecordWithComputedFields(); + r.array_field = int32([[1; 2; 3], [4; 5; 6]]); + + testCase.verifyEqual(r.array_size(), 6); + testCase.verifyEqual(r.array_x_size(), 2); + testCase.verifyEqual(r.array_y_size(), 3); + testCase.verifyEqual(r.array_0_size(), 2); + testCase.verifyEqual(r.array_1_size(), 3); + + testCase.verifyEqual(r.array_size_from_int_field(), 2); + r.int_field = 1; + testCase.verifyEqual(r.array_size_from_int_field(), 3); + + r.string_field = "x"; + testCase.verifyEqual(r.array_size_from_string_field(), 2); + r.string_field = "y"; + testCase.verifyEqual(r.array_size_from_string_field(), 3); + + r.string_field = "missing"; + testCase.verifyError(@() r.array_size_from_string_field(), "yardl:ValueError"); + + r.tuple_field.v1 = 1; + testCase.verifyEqual(r.array_size_from_nested_int_field(), 3); + testCase.verifyEqual(r.fixed_array_size(), 12); + testCase.verifyEqual(r.fixed_array_x_size(), 3); + testCase.verifyEqual(r.fixed_array_0_size(), 3); + + r.array_field_map_dimensions = int32([[1; 2; 3], [4; 5; 6]]); + testCase.verifyEqual(r.array_field_map_dimensions_x_size(), 2); + end + + function testSwitch(testCase) + r = test_model.RecordWithComputedFields(); + r.optional_named_array = int32([[1; 2; 3], [4; 5; 6]]); + testCase.verifyEqual(r.optional_named_array_length(), 6); + testCase.verifyEqual(r.optional_named_array_length_with_discard(), 6); + + r.optional_named_array = yardl.None; + testCase.verifyEqual(r.optional_named_array_length(), 0); + testCase.verifyEqual(r.optional_named_array_length_with_discard(), 0); + + r.int_float_union = test_model.Int32OrFloat32.Int32(int32(42)); + testCase.verifyEqual(r.int_float_union_as_float(), single(42)); + r.int_float_union = test_model.Int32OrFloat32.Float32(single(42.9)); + testCase.verifyEqual(r.int_float_union_as_float(), single(42.9)); + + r.nullable_int_float_union = yardl.None; + testCase.verifyEqual(r.nullable_int_float_union_string(), "null"); + r.nullable_int_float_union = test_model.Int32OrFloat32.Int32(42); + testCase.verifyEqual(r.nullable_int_float_union_string(), "int"); + r.nullable_int_float_union = test_model.Int32OrFloat32.Float32(42.9); + testCase.verifyEqual(r.nullable_int_float_union_string(), "float"); + + r.union_with_nested_generic_union = test_model.IntOrGenericRecordWithComputedFields.Int(42); + testCase.verifyEqual(r.nested_switch(), -1); + testCase.verifyEqual(r.use_nested_computed_field(), -1); + + g0 = basic_types.GenericRecordWithComputedFields(f1=basic_types.T0OrT1.T0("hi")); + r.union_with_nested_generic_union = ... + test_model.IntOrGenericRecordWithComputedFields.GenericRecordWithComputedFields(g0); + testCase.verifyEqual(r.nested_switch(), int32(10)); + testCase.verifyEqual(r.use_nested_computed_field(), int32(0)); + + g1 = basic_types.GenericRecordWithComputedFields(f1=basic_types.T0OrT1.T1(single(42.9))); + r.union_with_nested_generic_union = ... + test_model.IntOrGenericRecordWithComputedFields.GenericRecordWithComputedFields(g1); + testCase.verifyEqual(r.nested_switch(), int32(20)); + testCase.verifyEqual(r.use_nested_computed_field(), int32(1)); + + r.int_field = int32(10); + testCase.verifyEqual(r.switch_over_single_value(), int32(10)); + + + gr = basic_types.GenericRecordWithComputedFields(f1=basic_types.T0OrT1.T0(int32(42))); + testCase.verifyEqual(gr.type_index(), 0); + gr.f1 = basic_types.T0OrT1.T1(single(42.9)); + testCase.verifyEqual(gr.type_index(), 1); + end + + function testArithmetic(testCase) + r = test_model.RecordWithComputedFields(); + testCase.verifyEqual(r.arithmetic_1(), 3); + testCase.verifyEqual(r.arithmetic_2(), 11); + testCase.verifyEqual(r.arithmetic_3(), 13); + + r.array_field = int32([[1; 2; 3], [4; 5; 6]]); + r.int_field = 1; + testCase.verifyEqual(r.arithmetic_4(), 5); + testCase.verifyEqual(r.arithmetic_5(), 3); + + testCase.verifyEqual(r.arithmetic_6(), 3.5); + + testCase.verifyEqual(r.arithmetic_7(), 49.0); + + r.complexfloat32_field = complex(2, 3); + testCase.verifyEqual(r.arithmetic8(), single(complex(6, 9))); + + testCase.verifyEqual(r.arithmetic_9(), 2.2); + testCase.verifyEqual(r.arithmetic_10(), 1e10 + 9e9); + end + + function testCasting(testCase) + r = test_model.RecordWithComputedFields(); + r.int_field = int32(42); + testCase.verifyEqual(r.cast_int_to_float(), single(42)); + + r.float32_field = 42.9; + % NOTE: Matlab rounds floating point numbers when casting to integer + testCase.verifyEqual(r.cast_float_to_int(), int32(43)); + + testCase.verifyEqual(r.cast_power(), int32(49)); + + r.complexfloat32_field = single(complex(2, 3)); + r.complexfloat64_field = complex(2, 3); + testCase.verifyEqual(r.cast_complex32_to_complex64(), complex(2, 3)); + testCase.verifyEqual(r.cast_complex64_to_complex32(), single(complex(2, 3))); + + testCase.verifyEqual(r.cast_float_to_complex(), complex(single(66.6), 0)); + end + + end +end diff --git a/matlab/test/EqualityTest.m b/matlab/test/EqualityTest.m new file mode 100644 index 00000000..a976c59a --- /dev/null +++ b/matlab/test/EqualityTest.m @@ -0,0 +1,256 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef EqualityTest < matlab.unittest.TestCase + methods (Test) + + function testSimpleEquality(testCase) + a = test_model.SimpleRecord(x=1, y=2, z=3); + b = test_model.SimpleRecord(x=1, y=2, z=3); + testCase.verifyEqual(a, b); + + c = test_model.SimpleRecord(x=1, y=2, z=4); + testCase.verifyNotEqual(a, c); + + testCase.verifyEqual([a, b], [b, a]); + testCase.verifyNotEqual([a, b], [b, c]); + end + + function testFlagsEquality(testCase) + a = bitor(test_model.DaysOfWeek.MONDAY, test_model.DaysOfWeek.TUESDAY); + b = bitor(test_model.DaysOfWeek.TUESDAY, test_model.DaysOfWeek.MONDAY); + testCase.verifyEqual(a, b); + + c = test_model.DaysOfWeek(0); + d = test_model.DaysOfWeek(0); + testCase.verifyEqual(c, d); + testCase.verifyNotEqual(a, c); + + e = test_model.DaysOfWeek(0xFFFF); + f = test_model.DaysOfWeek(0xFFFF); + testCase.verifyEqual(e, f); + + testCase.verifyEqual([a, b, c, d, e, f], [b, a, d, c, f, e]); + end + + function testEnumEquality(testCase) + a = test_model.Fruits.APPLE; + b = test_model.Fruits.APPLE; + testCase.verifyEqual(a, b); + + c = test_model.Fruits(10000); + d = test_model.Fruits(10000); + testCase.verifyEqual(c, d); + + testCase.verifyEqual([a, b, c, d], [b, a, d, c]); + testCase.verifyNotEqual([a, b, c, d], [b, c, a, d]); + end + + function testRecordWithEnumEquality(testCase) + a = test_model.RecordWithEnums(enum=test_model.Fruits.APPLE, ... + flags=bitor(test_model.DaysOfWeek.SATURDAY, test_model.DaysOfWeek.SUNDAY), ... + flags_2=0); + b = test_model.RecordWithEnums(enum=test_model.Fruits.APPLE, ... + flags=bitor(test_model.DaysOfWeek.SATURDAY, test_model.DaysOfWeek.SUNDAY), ... + flags_2=0); + testCase.verifyEqual(a, b); + + c = test_model.RecordWithEnums(enum=test_model.Fruits.APPLE, ... + flags=test_model.DaysOfWeek.SATURDAY, ... + flags_2=0); + testCase.verifyNotEqual(a, c); + + testCase.verifyEqual([a, b, c], [b, a, c]); + end + + function testDateEquality(testCase) + a = test_model.RecordWithPrimitives(); + a.date_field = yardl.Date.from_components(2020, 1, 1); + b = test_model.RecordWithPrimitives(); + b.date_field = yardl.Date.from_components(2020, 1, 1); + + testCase.verifyEqual(a, b); + + c = test_model.RecordWithPrimitives(); + c.date_field = yardl.Date.from_components(2020, 1, 2); + testCase.verifyNotEqual(a, c); + + testCase.verifyEqual([a, b, c], [b, a, c]); + end + + function testTimeEquality(testCase) + a = test_model.RecordWithPrimitives(); + a.time_field = yardl.Time.from_components(12, 22, 44, 0); + b = test_model.RecordWithPrimitives(); + b.time_field = yardl.Time.from_components(12, 22, 44, 0); + + testCase.verifyEqual(a, b); + + c = test_model.RecordWithPrimitives(); + c.time_field = yardl.Time.from_components(12, 22, 45, 0); + testCase.verifyNotEqual(a, c); + + testCase.verifyEqual([a, b, c], [b, a, c]); + end + + function testDateTimeEquality(testCase) + a = test_model.RecordWithPrimitives(); + a.datetime_field = yardl.DateTime.from_components(2020, 1, 1, 12, 22, 44, 0); + b = test_model.RecordWithPrimitives(); + b.datetime_field = yardl.DateTime.from_components(2020, 1, 1, 12, 22, 44, 0); + + testCase.verifyEqual(a, b); + + c = test_model.RecordWithPrimitives(); + c.datetime_field = yardl.DateTime.from_components(2020, 1, 1, 12, 22, 45, 0); + testCase.verifyNotEqual(a, c); + + testCase.verifyEqual([a, b, c], [b, a, c]); + end + + function testStringEquality(testCase) + a = test_model.RecordWithStrings("a", "b"); + b = test_model.RecordWithStrings("a", "b"); + testCase.verifyEqual(a, b); + + c = test_model.RecordWithStrings("a", "c"); + testCase.verifyNotEqual(a, c); + + testCase.verifyEqual([a, b, c], [b, a, c]); + end + + + function testRecordWithPrimitiveVectorsEquality(testCase) + a = test_model.RecordWithVectors( ... + default_vector=[1, 2], ... + default_vector_fixed_length=[1, 2, 3], ... + vector_of_vectors=[[1, 2], [3, 4]] ... + ); + + b = test_model.RecordWithVectors( ... + default_vector=[1, 2], ... + default_vector_fixed_length=[1, 2, 3], ... + vector_of_vectors=[[1, 2], [3, 4]] ... + ); + + testCase.verifyEqual(a, b); + + testCase.verifyEqual([a, b], [b, a]); + end + + function testOptionalIntEquality(testCase) + a = test_model.RecordWithOptionalFields(); + a.optional_time = yardl.Time.from_components(1, 1, 1, 1); + b = test_model.RecordWithOptionalFields(); + b.optional_time = yardl.Time.from_components(1, 1, 1, 1); + testCase.verifyEqual(a, b); + + c = test_model.RecordWithOptionalFields(); + c.optional_time = yardl.Time.from_components(1, 1, 1, 2); + testCase.verifyNotEqual(a, c); + testCase.verifyNotEqual(b, c); + + d = test_model.RecordWithOptionalFields(); + e = test_model.RecordWithOptionalFields(); + testCase.verifyEqual(d, e); + testCase.verifyNotEqual(a, d); + + testCase.verifyEqual([a, b, c, d, e], [b, a, c, e, d]); + end + + function testTimeVectorEquality(testCase) + a = test_model.RecordWithVectorOfTimes(... + times=[yardl.Time.from_components(1, 1, 1, 1), yardl.Time.from_components(1, 1, 1, 1)] ... + ); + b = test_model.RecordWithVectorOfTimes(... + times=[yardl.Time.from_components(1, 1, 1, 1), yardl.Time.from_components(1, 1, 1, 1)] ... + ); + testCase.verifyEqual(a, b); + + c = test_model.RecordWithVectorOfTimes(... + times=[yardl.Time.from_components(1, 1, 1, 1), yardl.Time.from_components(1, 1, 1, 2)] ... + ); + testCase.verifyNotEqual(a, c); + + testCase.verifyEqual([a, b, c], [b, a, c]); + end + + function testSimpleArrayEquality(testCase) + a = test_model.RecordWithArrays(); + a.default_array = int32([1, 2, 3]); + b = test_model.RecordWithArrays(); + b.default_array = int32([1, 2, 3]); + testCase.verifyEqual(a, b); + + c = test_model.RecordWithArrays(); + c.default_array = int32([1, 2, 4]); + testCase.verifyNotEqual(a, c); + + testCase.verifyEqual([a, b, c], [b, a, c]); + end + + function testSimpleUnionEquality(testCase) + a = basic_types.RecordWithUnions(); + a.null_or_int_or_string = yardl.None; + b = basic_types.RecordWithUnions(); + b.null_or_int_or_string = yardl.None; + testCase.verifyEqual(a, b); + + c = basic_types.RecordWithUnions(); + c.null_or_int_or_string = basic_types.Int32OrString.Int32(1); + d = basic_types.RecordWithUnions(); + d.null_or_int_or_string = basic_types.Int32OrString.Int32(1); + testCase.verifyEqual(c, d); + testCase.verifyNotEqual(a, c); + + e = basic_types.RecordWithUnions(); + e.null_or_int_or_string = basic_types.Int32OrString.String("hello"); + f = basic_types.RecordWithUnions(); + f.null_or_int_or_string = basic_types.Int32OrString.String("hello"); + testCase.verifyEqual(e, f); + testCase.verifyNotEqual(a, e); + testCase.verifyNotEqual(c, e); + + testCase.verifyEqual([a, b, c, d, e, f], [b, a, d, c, f, e]); + end + + function testTimeUnionEquality(testCase) + a = basic_types.RecordWithUnions(); + a.date_or_datetime = basic_types.TimeOrDatetime.Time(yardl.Time.from_components(1, 1, 1, 1)); + b = basic_types.RecordWithUnions(); + b.date_or_datetime = basic_types.TimeOrDatetime.Time(yardl.Time.from_components(1, 1, 1, 1)); + testCase.verifyEqual(a, b); + + testCase.verifyEqual([a, b], [b, a]); + end + + function testGenericEquality(testCase) + a = test_model.GenericRecord(scalar_1=1, scalar_2=2.0, vector_1=[1, 2, 3], ... + image_2=single([[1.1, 2.2], [3.3, 4.4]])); + b = test_model.GenericRecord(scalar_1=1, scalar_2=2.0, vector_1=[1, 2, 3], ... + image_2=single([[1.1, 2.2], [3.3, 4.4]])); + testCase.verifyEqual(a, b); + + c = test_model.MyTuple(v1=42.0, v2="hello, world"); + d = tuples.Tuple(v1=42.0, v2="hello, world"); + testCase.verifyTrue(c == d) + + e = test_model.AliasedTuple(v1=42.0, v2="hello, world"); + testCase.verifyTrue(c == e); + + testCase.verifyEqual({a, b, c, d, e}, {b, a, d, c, e}); + end + + function testRecordWithComputedFieldsEquality(testCase) + a = test_model.RecordWithComputedFields(); + b = test_model.RecordWithComputedFields(); + testCase.verifyEqual(a, b); + testCase.verifyTrue(a == b); + testCase.verifyTrue(isequal(a, b)); + + b.vector_field = [1, 2, 3]; + testCase.verifyFalse(a == b); + testCase.verifyFalse(isequal(a, b)); + end + end +end diff --git a/matlab/test/GeneratedTypesTest.m b/matlab/test/GeneratedTypesTest.m new file mode 100644 index 00000000..47eeb227 --- /dev/null +++ b/matlab/test/GeneratedTypesTest.m @@ -0,0 +1,228 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef GeneratedTypesTest < matlab.unittest.TestCase + methods (Test) + + function testDefaultRecordWithPrimitives(testCase) + r = test_model.RecordWithPrimitives(); + + testCase.verifyEqual(r.bool_field, false); + testCase.verifyEqual(r.int32_field, int32(0)); + testCase.verifyEqual(r.date_field, yardl.Date()); + testCase.verifyEqual(r.time_field, yardl.Time()); + testCase.verifyEqual(r.datetime_field, yardl.DateTime()); + end + + function testDefaultRecordWithVectors(testCase) + r = test_model.RecordWithVectors(); + + testCase.verifyEqual(r.default_vector, int32([])); + testCase.verifyEqual(r.default_vector_fixed_length, int32([0, 0, 0])); + testCase.verifyEqual(r.default_vector, int32([])); + end + + function testDefaultRecordWithArrays(testCase) + import matlab.unittest.constraints.IsEmpty + import matlab.unittest.constraints.IsInstanceOf + + r = test_model.RecordWithArrays(); + + testCase.verifyEqual(r.default_array, int32([])); + testCase.verifyThat(r.default_array_with_empty_dimension, IsEmpty); + testCase.verifyThat(r.rank_1_array, IsEmpty); + testCase.verifyThat(r.rank_2_array, IsEmpty); + testCase.verifyEqual(size(r.rank_2_array), [0, 0]); + testCase.verifyThat(r.rank_2_array_with_named_dimensions, IsEmpty); + testCase.verifyEqual(size(r.rank_2_array_with_named_dimensions), [0, 0]); + + testCase.verifyEqual(r.rank_2_fixed_array, zeros(4, 3, 'int32')); + testCase.verifyEqual(r.rank_2_fixed_array_with_named_dimensions, zeros(4, 3, 'int32')); + + testCase.verifyThat(r.dynamic_array, IsEmpty); + testCase.verifyThat(r.dynamic_array, IsInstanceOf('int32')); + + testCase.verifyThat(r.array_of_vectors, IsInstanceOf('int32')); + testCase.verifyEqual(size(r.array_of_vectors), [5, 4]); + end + + function testDefaultRecordWithOptionalFields(testCase) + r = test_model.RecordWithOptionalFields(); + + testCase.verifyEqual(r.optional_int, yardl.None); + end + + function testDefaultRecordWithUnionsOfContainers(testCase) + r = test_model.RecordWithUnionsOfContainers(); + + testCase.verifyEqual(r.map_or_scalar, test_model.MapOrScalar.Map(dictionary)); + testCase.verifyEqual(r.vector_or_scalar, test_model.VectorOrScalar.Vector(int32([]))); + testCase.verifyEqual(r.array_or_scalar, test_model.ArrayOrScalar.Array(int32([]))); + end + + function testDefaultRecordWithAliasedGenerics(testCase) + r = test_model.RecordWithAliasedGenerics(); + + testCase.verifyEqual(r.my_strings.v1, ""); + testCase.verifyEqual(r.my_strings.v2, ""); + testCase.verifyEqual(r.aliased_strings.v1, ""); + testCase.verifyEqual(r.aliased_strings.v2, ""); + end + + function testDefaultRecordGenericEmpty(testCase) + g1 = test_model.RecordWithOptionalGenericField(); + testCase.verifyEqual(g1.v, yardl.None); + + g1a = test_model.RecordWithAliasedOptionalGenericField(); + testCase.verifyEqual(g1a.v, g1.v); + + g2 = test_model.RecordWithOptionalGenericUnionField(); + testCase.verifyEqual(g2.v, yardl.None); + + g2a = test_model.RecordWithAliasedOptionalGenericUnionField(); + testCase.verifyEqual(g2a.v, g2.v) + + % testCase.verifyError(@() test_model.MyTuple(), 'MATLAB:minrhs'); + testCase.verifyError(@() test_model.MyTuple(), 'yardl:TypeError'); + t = test_model.MyTuple(v1="a", v2=42); + + rm = test_model.RecordWithGenericMaps(); + testCase.verifyEqual(rm.m, dictionary); + testCase.verifyEqual(rm.am, rm.m); + end + + function testDefaultRecordWithGenericRequiredArguments(testCase) + testCase.verifyError(@() test_model.RecordWithGenericArrays(), 'yardl:TypeError'); + testCase.verifyError(@() test_model.RecordWithGenericVectors(), 'yardl:TypeError'); + testCase.verifyError(@() test_model.RecordWithGenericFixedVectors(), 'yardl:TypeError'); + end + + function testDefaultRecordContainingNestedGenericRecords(testCase) + r = test_model.RecordContainingNestedGenericRecords(); + + g1 = test_model.RecordWithOptionalGenericField(); + g1a = test_model.RecordWithAliasedOptionalGenericField(); + g2 = test_model.RecordWithOptionalGenericUnionField(); + g2a = test_model.RecordWithAliasedOptionalGenericUnionField(); + g7 = test_model.RecordWithGenericMaps(); + + testCase.verifyEqual(r.f1, g1); + testCase.verifyEqual(r.f1a, g1a); + testCase.verifyEqual(r.f2, g2); + testCase.verifyEqual(r.f2a, g2a); + + testCase.verifyEqual(r.nested.g1, g1); + testCase.verifyEqual(r.nested.g1a, g1a); + testCase.verifyEqual(r.nested.g2, g2); + testCase.verifyEqual(r.nested.g2a, g2a); + + testCase.verifyEqual(r.nested.g3.v1, ""); + testCase.verifyEqual(r.nested.g3.v2, int32(0)); + testCase.verifyEqual(r.nested.g3a.v1, r.nested.g3.v1); + testCase.verifyEqual(r.nested.g3a.v2, r.nested.g3.v2); + + testCase.verifyEqual(r.nested.g4.v, int32([])); + testCase.verifyEqual(r.nested.g4.av, r.nested.g4.v); + + testCase.verifyEqual(r.nested.g5.fv, int32([0, 0, 0])); + testCase.verifyEqual(r.nested.g5.afv, r.nested.g5.fv); + + testCase.verifyEqual(r.nested.g6.nd, int32([])); + testCase.verifyEqual(r.nested.g6.aliased_nd, r.nested.g6.nd); + + testCase.verifyEqual(r.nested.g6.fixed_nd, zeros(8, 16, 'int32')); + testCase.verifyEqual(r.nested.g6.aliased_fixed_nd, r.nested.g6.fixed_nd); + + testCase.verifyEqual(r.nested.g6.dynamic_nd, int32([])); + testCase.verifyEqual(r.nested.g6.aliased_dynamic_nd, r.nested.g6.dynamic_nd); + + testCase.verifyEqual(r.nested.g7, g7); + end + + function testYardlAllocate(testCase) + rs = yardl.allocate('test_model.RecordWithPrimitives', 5); + testCase.verifyEqual(size(rs), [5, 5]); + testCase.verifyTrue(all(rs == test_model.RecordWithPrimitives())); + + os = yardl.allocate('yardl.Optional', 1, 4); + testCase.verifyEqual(size(os), [1, 4]); + testCase.verifyTrue(all(os == yardl.None)); + + us = yardl.allocate('basic_types.Int32OrString', 5, 2); + testCase.verifyEqual(size(us), [5, 2]); + testCase.verifyTrue(all([us.index] == 0)); + testCase.verifyTrue(all(us == basic_types.Int32OrString(0, yardl.None))); + + ns = yardl.allocate('int16', 0); + testCase.verifyEqual(class(ns), 'int16'); + testCase.verifyEqual(size(ns), [0, 0]); + + bs = yardl.allocate('logical', [2, 3, 4]); + testCase.verifyEqual(class(bs), 'logical'); + testCase.verifyEqual(size(bs), [2, 3, 4]); + testCase.verifyTrue(all(bs(:) == false)); + + ss = yardl.allocate('string', 2); + testCase.verifyEqual(class(ss), 'string'); + testCase.verifyEqual(size(ss), [2, 2]); + testCase.verifyTrue(all(ss(:) == "")); + + ds = yardl.allocate('yardl.Date', 3, 1); + testCase.verifyEqual(size(ds), [3, 1]); + testCase.verifyTrue(all(ds == yardl.Date(0))); + + ts = yardl.allocate('yardl.Time', 3); + testCase.verifyEqual(size(ts), [3, 3]); + testCase.verifyTrue(all(ts == yardl.Time(0))); + + dts = yardl.allocate('yardl.DateTime', 3, 3); + testCase.verifyEqual(size(dts), [3, 3]); + testCase.verifyTrue(all(dts == yardl.DateTime(0))); + end + + function testFlags(testCase) + zero = test_model.TextFormat(0); + regular = test_model.TextFormat.REGULAR; + bold = test_model.TextFormat.BOLD; + underline = test_model.TextFormat.UNDERLINE; + bold_underline = bold.with_flags(underline); + bold_underline2 = test_model.TextFormat(bold, underline); + everything = regular.with_flags(test_model.TextFormat(bold, underline, 2, 8)); + + testCase.verifyEqual(zero, regular); + + testCase.verifyEqual(everything, test_model.TextFormat(0b1111)); + + testCase.verifyEqual(regular.with_flags(test_model.TextFormat.BOLD), test_model.TextFormat.BOLD); + testCase.verifyEqual(regular.with_flags(uint64(1)), test_model.TextFormat.BOLD); + testCase.verifyEqual(bold.with_flags(underline), bold_underline); + testCase.verifyEqual(bold.with_flags(underline), bold_underline2); + + testCase.verifyEqual(bold_underline.without_flags(bold), underline); + testCase.verifyEqual(bold_underline.without_flags(uint64(1)), underline); + testCase.verifyEqual(bold_underline2.without_flags(bold), underline); + testCase.verifyEqual(bold_underline2.without_flags(uint64(1)), underline); + + testCase.verifyTrue(bold.has_flags(uint64(1))); + testCase.verifyTrue(bold.has_flags(bold)); + testCase.verifyTrue(bold_underline.has_flags(bold)); + testCase.verifyTrue(bold_underline.has_flags(underline)); + testCase.verifyTrue(bold_underline.has_flags(bold_underline)); + testCase.verifyTrue(bold_underline2.has_flags(bold)); + testCase.verifyTrue(bold_underline2.has_flags(underline)); + testCase.verifyTrue(bold_underline2.has_flags(bold_underline)); + end + + function testUnionTags(testCase) + isi = basic_types.Int32OrString.Int32(42); + testCase.verifyTrue(isi.isInt32()); + testCase.verifyFalse(isi.isString()); + testCase.verifyEqual(isi.tag(), "Int32"); + + iss = basic_types.Int32OrString.String("hello"); + testCase.verifyTrue(iss.isString()); + testCase.verifyFalse(iss.isInt32()); + testCase.verifyEqual(iss.tag(), "String"); + end + end +end diff --git a/matlab/test/ProtocolStateTest.m b/matlab/test/ProtocolStateTest.m new file mode 100644 index 00000000..4b248001 --- /dev/null +++ b/matlab/test/ProtocolStateTest.m @@ -0,0 +1,81 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef ProtocolStateTest < matlab.unittest.TestCase + methods (Test) + + function testProperSequenceWrite(testCase) + w = ProtocolStateTestWriter(); + w.write_an_int(1); + w.write_a_stream([1, 2, 3]); + w.end_a_stream(); + w.write_another_int(3); + w.close(); + end + + function testProperSequenceWriteEmptyStream(testCase) + w = ProtocolStateTestWriter(); + w.write_an_int(1); + w.write_a_stream([]); + w.end_a_stream(); + w.write_another_int(3); + w.close(); + end + + function testProperSequenceWriteMultipleStreams(testCase) + w = ProtocolStateTestWriter(); + w.write_an_int(1); + w.write_a_stream([1, 2, 3]); + w.write_a_stream([4, 5, 6]); + w.end_a_stream(); + w.write_another_int(3); + w.close(); + end + + function testSequenceWriteMissingFirstStep(testCase) + w = ProtocolStateTestWriter(); + testCase.verifyError(@() w.write_a_stream([1, 2, 3]), 'yardl:ProtocolError'); + end + + function testSequenceWriteMissingEndStream(testCase) + w = ProtocolStateTestWriter(); + w.write_an_int(1); + w.write_a_stream([1, 2, 3]); + testCase.verifyError(@() w.write_another_int(4), 'yardl:ProtocolError'); + end + + function testSequenceWritePrematureClose(testCase) + w = ProtocolStateTestWriter(); + w.write_an_int(1); + w.write_a_stream([1, 2, 3]); + testCase.verifyError(@() w.close(), 'yardl:ProtocolError'); + end + + + function testProperSequenceRead(testCase) + r = ProtocolStateTestReader(); + r.read_an_int(); + while r.has_a_stream() + r.read_a_stream(); + end + r.read_another_int(); + r.close(); + end + + function testReadSkipFirstStep(testCase) + r = ProtocolStateTestReader(); + testCase.verifyError(@() r.has_a_stream(), 'yardl:ProtocolError'); + testCase.verifyError(@() r.read_a_stream(), 'yardl:ProtocolError'); + end + + function testReadCloseEarly(testCase) + r = ProtocolStateTestReader(); + r.read_an_int(); + while r.has_a_stream() + r.read_a_stream(); + end + testCase.verifyError(@() r.close(), 'yardl:ProtocolError'); + end + + end +end diff --git a/matlab/test/ProtocolStateTestReader.m b/matlab/test/ProtocolStateTestReader.m new file mode 100644 index 00000000..157abe6c --- /dev/null +++ b/matlab/test/ProtocolStateTestReader.m @@ -0,0 +1,35 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef ProtocolStateTestReader < test_model.StateTestReaderBase + + methods (Access=protected) + + function res = read_an_int_(self) + res = -2; + end + + function more = has_a_stream_(self) + persistent n + if isempty(n) + n = 0; + more = true; + else + more = false; + end + n = n + 1; + end + + function res = read_a_stream_(self) + res = [-1, -2, -3]; + end + + function res = read_another_int_(self) + res = -4; + end + + function close_(self) + end + + end +end diff --git a/matlab/test/ProtocolStateTestWriter.m b/matlab/test/ProtocolStateTestWriter.m new file mode 100644 index 00000000..4d49d179 --- /dev/null +++ b/matlab/test/ProtocolStateTestWriter.m @@ -0,0 +1,24 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef ProtocolStateTestWriter < test_model.StateTestWriterBase + + methods (Access=protected) + + function write_an_int_(self, value) + end + + function write_a_stream_(self, value) + end + + function write_another_int_(self, value) + end + + function end_stream_(self) + end + + function close_(self) + end + + end +end diff --git a/matlab/test/RoundTripTest.m b/matlab/test/RoundTripTest.m new file mode 100644 index 00000000..feb314e4 --- /dev/null +++ b/matlab/test/RoundTripTest.m @@ -0,0 +1,555 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef RoundTripTest < matlab.unittest.TestCase + properties (TestParameter) + % format = {"binary", "ndjson"}; + format = {"binary"}; + end + + methods (Test) + + function testScalarPrimitives(testCase, format) + rec = test_model.RecordWithPrimitives(); + rec.bool_field = true; + rec.int8_field = int8(-88); + rec.uint8_field = uint8(88); + rec.int16_field = int16(-1616); + rec.uint16_field = uint16(1616); + rec.int32_field = int32(-3232); + rec.uint32_field = uint32(3232); + rec.int64_field = int64(-64646464); + rec.uint64_field = uint64(64646464); + rec.size_field = uint64(64646464); + rec.float32_field = single(32.0); + rec.float64_field = double(64.64); + rec.complexfloat32_field = single(complex(32.0, 64.0)); + rec.complexfloat64_field = 64.64 + 32.32j; + rec.date_field = yardl.Date.from_components(2024, 4, 2); + rec.time_field = yardl.Time.from_components(12, 34, 56, 0); + rec.datetime_field = yardl.DateTime.from_components(2024, 4, 2, 12, 34, 56, 111222333); + + w = create_validating_writer(testCase, format, 'Scalars'); + w.write_int32(int32(42)) + w.write_record(rec) + w.close(); + end + + function testScalarOptionals(testCase, format) + w = create_validating_writer(testCase, format, 'ScalarOptionals'); + w.write_optional_int(yardl.None); + w.write_optional_record(yardl.None); + w.write_record_with_optional_fields(test_model.RecordWithOptionalFields()); + w.write_optional_record_with_optional_fields(yardl.None); + w.close(); + + w = create_validating_writer(testCase, format, 'ScalarOptionals'); + w.write_optional_int(int32(55)); + w.write_optional_record(test_model.SimpleRecord(x=8, y=9, z=10)); + w.write_record_with_optional_fields(... + test_model.RecordWithOptionalFields(optional_int=int32(44), ... + optional_int_alternate_syntax=int32(44), ... + optional_time=yardl.Time.from_components(12, 34, 56, 0))); + w.write_optional_record_with_optional_fields(... + test_model.RecordWithOptionalFields(optional_int=int32(12), ... + optional_int_alternate_syntax=int32(12), ... + optional_time=yardl.Time.from_components(11, 32, 26, 0))); + w.close(); + end + + function testNestedRecords(testCase, format) + w = create_validating_writer(testCase, format, 'NestedRecords'); + t = test_model.TupleWithRecords(... + a=test_model.SimpleRecord(x=1, y=2, z=3), ... + b=test_model.SimpleRecord(x=4, y=5, z=6)); + w.write_tuple_with_records(t); + w.close(); + end + + function testVariableLengthVectors(testCase, format) + w = create_validating_writer(testCase, format, 'Vlens'); + w.write_int_vector(int32([1, 2, 3])); + w.write_complex_vector(single([1+2j, 3+4j])); + rec = test_model.RecordWithVlens(... + a=[test_model.SimpleRecord(x=1, y=2, z=3), test_model.SimpleRecord(x=4, y=5, z=6)], ... + b=4, ... + c=2 ... + ); + w.write_record_with_vlens(rec); + w.write_vlen_of_record_with_vlens([rec, rec]); + w.close(); + end + + function testStrings(testCase, format) + w = create_validating_writer(testCase, format, 'Strings'); + w.write_single_string("hello"); + w.write_rec_with_string(test_model.RecordWithStrings(a="Montréal", b="臺北市")); + w.close(); + end + + function testOptionalVectors(testCase, format) + w = create_validating_writer(testCase, format, 'OptionalVectors'); + w.write_record_with_optional_vector(test_model.RecordWithOptionalVector()); + w.close(); + + w = create_validating_writer(testCase, format, 'OptionalVectors'); + w.write_record_with_optional_vector(test_model.RecordWithOptionalVector(optional_vector=int32([1, 2, 3]))); + w.close(); + end + + function testFixedVectors(testCase, format) + ints = int32([1, 2, 3, 4, 5]); + SR = @test_model.SimpleRecord; + simple_recs = [SR(x=1, y=2, z=3), SR(x=4, y=5, z=6), SR(x=7, y=8, z=9)]; + RV = @test_model.RecordWithVlens; + vlens_recs = [... + RV(a=[SR(x=1, y=2, z=3), SR(x=4, y=5, z=6)], b=4, c=2), ... + RV(a=[SR(x=7, y=8, z=9), SR(x=10, y=11, z=12)], b=5, c=3)]; + rec_with_fixed = test_model.RecordWithFixedVectors(... + fixed_int_vector=ints, ... + fixed_simple_record_vector=simple_recs, ... + fixed_record_with_vlens_vector=vlens_recs); + + w = create_validating_writer(testCase, format, 'FixedVectors'); + w.write_fixed_int_vector(ints); + w.write_fixed_simple_record_vector(simple_recs); + w.write_fixed_record_with_vlens_vector(vlens_recs); + w.write_record_with_fixed_vectors(rec_with_fixed); + w.close(); + end + + function testFixedArrays(testCase, format) + ints = int32([[1, 2, 3]; [4, 5, 6]]); + ints = transpose(ints); + + SR = @test_model.SimpleRecord; + simple_recs = [... + [SR(x=1, y=2, z=3), SR(x=4, y=5, z=6)]; ... + [SR(x=11, y=12, z=13), SR(x=14, y=15, z=16)]; ... + [SR(x=21, y=22, z=23), SR(x=24, y=25, z=26)] ... + ]; + simple_recs = transpose(simple_recs); + + RV = @test_model.RecordWithVlens; + vlens_recs = [... + [... + RV(a=[SR(x=1, y=2, z=3), SR(x=7, y=8, z=9)], b=13, c=14), ... + RV(a=[SR(x=7, y=8, z=9), SR(x=10, y=11, z=12)], b=5, c=3)]; ... + [... + RV(a=[SR(x=31, y=32, z=33), SR(x=34, y=35, z=36), SR(x=37, y=38, z=39)], b=213, c=214), ... + RV(a=[SR(x=41, y=42, z=43)], b=313, c=314)] ... + ]; + vlens_recs = transpose(vlens_recs); + + rec_with_fixed = test_model.RecordWithFixedArrays(... + ints=ints, ... + fixed_simple_record_array=simple_recs, ... + fixed_record_with_vlens_array=vlens_recs); + + w = create_validating_writer(testCase, format, 'FixedArrays'); + w.write_ints(ints); + w.write_fixed_simple_record_array(simple_recs); + w.write_fixed_record_with_vlens_array(vlens_recs); + w.write_record_with_fixed_arrays(rec_with_fixed); + + named_fixed_array = transpose(int32([[1, 2, 3, 4]; [5, 6, 7, 8]])); + w.write_named_array(named_fixed_array) + w.close(); + end + + function testSubarrays(testCase, format) + w = create_validating_writer(testCase, format, 'Subarrays'); + + ints = transpose(int32([[1, 2, 3]; [4, 5, 6]])); + w.write_dynamic_with_fixed_int_subarray(ints); + + floats = transpose(single([[1, 2, 3]; [4, 5, 6]])); + w.write_dynamic_with_fixed_float_subarray(floats); + + ints = transpose(int32([[1, 2, 3]; [4, 5, 6]])); + w.write_known_dim_count_with_fixed_int_subarray(ints); + + floats = transpose(single([[1, 2, 3]; [4, 5, 6]])); + w.write_known_dim_count_with_fixed_float_subarray(floats); + + ints = transpose(int32([[1, 2, 3]; [4, 5, 6]])); + w.write_fixed_with_fixed_int_subarray(ints); + + floats = transpose(single([[1, 2, 3]; [4, 5, 6]])); + w.write_fixed_with_fixed_float_subarray(floats); + + nested(:, :, 1) = int32([[1; 2; 3], [4; 5; 6]]); + nested(:, :, 2) = [[10; 20; 30], [40; 50; 60]]; + nested(:, :, 3) = [[100; 200; 300], [400; 500; 600]]; + w.write_nested_subarray(nested); + + ints = transpose(int32([[1, 2, 3]; [4, 5, 6]])); + w.write_dynamic_with_fixed_vector_subarray(ints); + + image(:, 1, 1) = int32([1; 2; 3]); + image(:, 1, 2) = [4; 5; 6]; + image(:, 2, 1) = [10; 11; 12]; + image(:, 2, 2) = [13; 14; 15]; + w.write_generic_subarray(image); + + w.close(); + end + + function testSubarraysInRecords(testCase, format) + RF = @test_model.RecordWithFixedCollections; + records_with_fixed = [... + RF(fixed_vector=int32([1, 2, 3]), fixed_array=int32([[11; 12; 13], [14; 15; 16]])), ... + RF(fixed_vector=int32([101, 102, 103]), fixed_array=int32([[1011; 1012; 1013], [1014; 1015; 1016]])), ... + ]; + + RV = @test_model.RecordWithVlenCollections; + records_with_vlens = [... + RV(vector=int32([1, 2, 3]), array=int32([[11, 12, 13]; [14, 15, 16]])), ...]) + RV(vector=int32([101, 102, 103]), array=int32([[1011, 1012, 1013]; [1014, 1015, 1016]])), ... + ]; + + w = create_validating_writer(testCase, format, 'SubarraysInRecords'); + w.write_with_fixed_subarrays(records_with_fixed); + w.write_with_vlen_subarrays(records_with_vlens); + w.close(); + end + + function testNDArrays(testCase, format) + ints = transpose(int32([[1, 2, 3]; [4, 5, 6]])); + + SR = @test_model.SimpleRecord; + simple_recs = [... + [SR(x=1, y=2, z=3), SR(x=4, y=5, z=6)]; ... + [SR(x=11, y=12, z=13), SR(x=14, y=15, z=16)]; ... + [SR(x=21, y=22, z=23), SR(x=24, y=25, z=26)] ... + ]; + simple_recs = transpose(simple_recs); + + RV = @test_model.RecordWithVlens; + vlens_recs = [... + [... + RV(a=[SR(x=1, y=2, z=3), SR(x=7, y=8, z=9)], b=13, c=14), ... + RV(a=[SR(x=7, y=8, z=9), SR(x=10, y=11, z=12)], b=5, c=3)]; ... + [... + RV(a=[SR(x=31, y=32, z=33), SR(x=34, y=35, z=36), SR(x=37, y=38, z=39)], b=213, c=214), ... + RV(a=[SR(x=41, y=42, z=43)], b=313, c=314)] ... + ]; + vlens_recs = transpose(vlens_recs); + + rec_with_nds = test_model.RecordWithNDArrays(... + ints=ints, ... + fixed_simple_record_array=simple_recs, ... + fixed_record_with_vlens_array=vlens_recs); + + w = create_validating_writer(testCase, format, 'NDArrays'); + w.write_ints(ints); + w.write_simple_record_array(simple_recs); + w.write_record_with_vlens_array(vlens_recs); + w.write_record_with_nd_arrays(rec_with_nds); + w.write_named_array(ints); + w.close(); + end + + function testDynamicNDArrays(testCase, format) + ints = transpose(int32([[1, 2, 3]; [4, 5, 6]; [7, 8, 9]; [10, 11, 12]])); + SR = @test_model.SimpleRecord; + simple_recs = transpose([... + [SR(x=1, y=2, z=3), SR(x=4, y=5, z=6), SR(x=7, y=8, z=9)]; ... + [SR(x=11, y=12, z=13), SR(x=14, y=15, z=16), SR(x=17, y=18, z=19)]; ... + ]); + RV = @test_model.RecordWithVlens; + vlens_recs = transpose([... + [RV(a=[SR(x=1, y=2, z=3)], b=-33, c=44)]; ... + [RV(a=[SR(x=8, y=2, z=9), SR(x=28, y=3, z=34)], b=233, c=347)] ... + ]); + rec_with_dynamic_nds = test_model.RecordWithDynamicNDArrays(... + ints=ints, ... + simple_record_array=simple_recs, ... + record_with_vlens_array=vlens_recs); + + w = create_validating_writer(testCase, format, 'DynamicNDArrays'); + w.write_ints(ints); + w.write_simple_record_array(simple_recs); + w.write_record_with_vlens_array(vlens_recs); + w.write_record_with_dynamic_nd_arrays(rec_with_dynamic_nds); + w.close(); + end + + function testMultiDArrays(testCase, format) + % ch=8, z=2, y=64, x=32 + img = zeros(32, 64, 2, 8, 'single'); + w = create_validating_writer(testCase, format, 'MultiDArrays'); + + w.write_images({... + img(:,:,:,1), ... + img(:,:,1,1), ... + img(:,1,1,:), ... + img(1,1,1,1) ... + }); + w.end_images(); + + w.write_frames({... + img(:,:,1,1), ... + img(:,:,2,1) ... + }); + w.end_frames(); + + w.close(); + end + + function testMaps(testCase, format) + d = dictionary(); + d("a") = int32(1); + d("b") = 2; + d("c") = 3; + + w = create_validating_writer(testCase, format, 'Maps'); + w.write_string_to_int(d); + w.write_int_to_string(dictionary(int32([1, 2, 3]), ["a", "b", "c"])); + w.write_string_to_union(... + dictionary(... + ["a", "b"], ... + [test_model.StringOrInt32.Int32(1), test_model.StringOrInt32.String("2")] ... + ) ... + ); + w.write_aliased_generic(d); + w.close(); + + % Now again for "empty" maps + w = create_validating_writer(testCase, format, 'Maps'); + w.write_string_to_int(dictionary()); + w.write_int_to_string(dictionary()); + w.write_string_to_union(dictionary()); + w.write_aliased_generic(dictionary()); + w.close(); + end + + function testUnions(testCase, format) + w = create_validating_writer(testCase, format, 'Unions'); + w.write_int_or_simple_record(test_model.Int32OrSimpleRecord.Int32(1)); + w.write_int_or_record_with_vlens(test_model.Int32OrRecordWithVlens.Int32(2)); + w.write_monosotate_or_int_or_simple_record(yardl.None); + w.write_record_with_unions(basic_types.RecordWithUnions()); + w.close(); + + w = create_validating_writer(testCase, format, 'Unions'); + w.write_int_or_simple_record(test_model.Int32OrSimpleRecord.SimpleRecord(test_model.SimpleRecord(x=1, y=2, z=3))); + w.write_int_or_record_with_vlens(test_model.Int32OrRecordWithVlens.RecordWithVlens(test_model.RecordWithVlens(a=[test_model.SimpleRecord(x=1, y=2, z=3)], b=12, c=13))); + w.write_monosotate_or_int_or_simple_record(test_model.Int32OrSimpleRecord.Int32(6)); + w.write_record_with_unions(basic_types.RecordWithUnions(... + null_or_int_or_string= basic_types.Int32OrString.Int32(7), ... + date_or_datetime= basic_types.TimeOrDatetime.Datetime(yardl.DateTime.from_components(2025, 3, 4, 12, 34, 56, 0)), ... + null_or_fruits_or_days_of_week= basic_types.GenericNullableUnion2.T1(basic_types.Fruits.APPLE) ... + )); + w.close(); + end + + function testEnums(testCase, format) + w = create_validating_writer(testCase, format, 'Enums'); + w.write_single(test_model.Fruits.APPLE); + w.write_vec([test_model.Fruits.APPLE, test_model.Fruits.BANANA, test_model.Fruits(233983)]); + w.write_size(test_model.SizeBasedEnum.C); + w.close(); + end + + function testFlags(testCase, format) + w = create_validating_writer(testCase, format, 'Flags'); + + import test_model.DaysOfWeek; + mon_or_wed_or_fri = DaysOfWeek(DaysOfWeek.MONDAY, DaysOfWeek.WEDNESDAY, DaysOfWeek.FRIDAY); + w.write_days([... + test_model.DaysOfWeek.SUNDAY, ... + test_model.DaysOfWeek(mon_or_wed_or_fri), ... + test_model.DaysOfWeek(0), ... + test_model.DaysOfWeek(282839), ... + test_model.DaysOfWeek(234532) ... + ]); + w.end_days(); + + w.write_formats([... + test_model.TextFormat.BOLD, ... + test_model.TextFormat.BOLD.with_flags(test_model.TextFormat.ITALIC), ... + test_model.TextFormat.REGULAR, ... + test_model.TextFormat(232932) ... + ]); + w.end_formats(); + + w.close(); + end + + function testSimpleStreams(testCase, format) + % Non-empty streams + w = create_validating_writer(testCase, format, 'Streams'); + w.write_int_data(int32(1:10)); + w.write_int_data(int32(42)); + w.write_int_data(int32(1:20)); + w.end_int_data(); + w.write_optional_int_data([1, 2, yardl.None, 4, 5, yardl.None, 7, 8, 9, 10]); + w.end_optional_int_data(); + w.write_record_with_optional_vector_data([... + test_model.RecordWithOptionalVector(), ... + test_model.RecordWithOptionalVector(optional_vector=int32([1, 2, 3])), ... + test_model.RecordWithOptionalVector(optional_vector=int32(1:10)) ... + ]); + w.end_record_with_optional_vector_data(); + w.write_fixed_vector(... + repelem({int32([1, 2, 3])}, 4)... + ); + w.end_fixed_vector(); + w.close(); + + % Mixed empty/non-empty streams + w = create_validating_writer(testCase, format, 'Streams'); + w.write_int_data(int32(1:10)) + w.write_int_data([]); + w.end_int_data(); + w.write_optional_int_data([]); + w.write_optional_int_data([1, 2, yardl.None, 4, 5, yardl.None, 7, 8, 9, 10]); + w.end_optional_int_data(); + w.write_record_with_optional_vector_data([]); + w.end_record_with_optional_vector_data(); + % w.write_fixed_vector(int32(repmat([1;2;3], 1,4))); + w.write_fixed_vector(repelem({int32([1, 2, 3])}, 4)); + w.end_fixed_vector(); + w.close(); + + % % All empty streams + w = create_validating_writer(testCase, format, 'Streams'); + w.write_int_data([]); + w.end_int_data(); + w.write_optional_int_data([]); + w.end_optional_int_data(); + w.write_record_with_optional_vector_data([]); + w.end_record_with_optional_vector_data(); + w.write_fixed_vector([]); + w.end_fixed_vector(); + w.close(); + + w = create_validating_writer(testCase, format, 'Streams'); + w.end_int_data(); + w.end_optional_int_data(); + w.end_record_with_optional_vector_data(); + w.end_fixed_vector(); + w.close(); + end + + function testStreamsOfUnions(testCase, format) + w = create_validating_writer(testCase, format, 'StreamsOfUnions'); + w.write_int_or_simple_record([... + test_model.Int32OrSimpleRecord.Int32(1), ... + test_model.Int32OrSimpleRecord.SimpleRecord(test_model.SimpleRecord(x=1, y=2, z=3)), ... + test_model.Int32OrSimpleRecord.Int32(2) ... + ]); + w.end_int_or_simple_record(); + w.write_nullable_int_or_simple_record([... + yardl.None, ... + test_model.Int32OrSimpleRecord.Int32(1), ... + test_model.Int32OrSimpleRecord.SimpleRecord(test_model.SimpleRecord(x=1, y=2, z=3)), ... + yardl.None, ... + test_model.Int32OrSimpleRecord.Int32(2), ... + yardl.None ... + ]); + w.end_nullable_int_or_simple_record(); + w.close(); + end + + function testStreamsOfAliasedUnions(testCase, format) + w = create_validating_writer(testCase, format, 'StreamsOfAliasedUnions'); + w.write_int_or_simple_record([... + test_model.AliasedIntOrSimpleRecord.Int32(1), ... + test_model.AliasedIntOrSimpleRecord.SimpleRecord(test_model.SimpleRecord(x=1, y=2, z=3)), ... + test_model.AliasedIntOrSimpleRecord.Int32(2) ... + ]); + w.end_int_or_simple_record(); + w.write_nullable_int_or_simple_record([... + yardl.None, ... + test_model.AliasedNullableIntSimpleRecord.Int32(1), ... + test_model.AliasedNullableIntSimpleRecord.SimpleRecord(test_model.SimpleRecord(x=1, y=2, z=3)), ... + yardl.None, ... + test_model.AliasedNullableIntSimpleRecord.Int32(2), ... + yardl.None ... + ]); + w.end_nullable_int_or_simple_record(); + w.close(); + end + + function testSimpleGenerics(testCase, format) + w = create_validating_writer(testCase, format, 'SimpleGenerics'); + w.write_float_image(transpose(single([[1, 2]; [3, 4]]))); + w.write_int_image(transpose(int32([[1, 2]; [3, 4]]))); + w.write_int_image_alternate_syntax(transpose(int32([[1, 2]; [3, 4]]))); + w.write_string_image(transpose([["a", "b"]; ["c", "d"]])); + w.write_int_float_tuple(test_model.MyTuple(v1=int32(1), v2=single(2))); + w.write_float_float_tuple(test_model.MyTuple(v1=single(1), v2=single(2))); + t = test_model.MyTuple(v1=int32(1), v2=single(2)); + w.write_int_float_tuple_alternate_syntax(t); + w.write_int_string_tuple(test_model.MyTuple(v1=int32(1), v2="2")); + w.write_stream_of_type_variants([... + test_model.ImageFloatOrImageDouble.ImageFloat(transpose(single([[1, 2]; [3, 4]]))), ... + test_model.ImageFloatOrImageDouble.ImageDouble(transpose([[1, 2]; [3, 4]])) ... + ]); + w.end_stream_of_type_variants(); + w.close(); + end + + function testAdvancedGenerics(testCase, format) + w = create_validating_writer(testCase, format, 'AdvancedGenerics'); + + i1 = single([[3, 4, 5]; [6, 7, 8]]); + i2 = single([[30, 40, 50]; [60, 70, 80]]); + i3 = single([[300, 400, 500]; [600, 700, 800]]); + i4 = single([[3000, 4000, 5000]; [6000, 7000, 8000]]); + + img_img_array{1, 1} = i1; + img_img_array{1, 2} = i2; + img_img_array{2, 1} = i3; + img_img_array{2, 2} = i4; + + w.write_float_image_image(img_img_array); + + w.write_generic_record_1(test_model.GenericRecord(... + scalar_1=int32(1), ... + scalar_2="hello", ... + vector_1=int32([1, 2, 3]), ... + image_2=[["abc", "def"]; ["a", "b"]] ... + )); + + w.write_tuple_of_optionals(test_model.MyTuple(v1=yardl.None, v2="hello")); + w.write_tuple_of_optionals_alternate_syntax(test_model.MyTuple(v1=int32(34), v2=yardl.None)); + w.write_tuple_of_vectors(test_model.MyTuple(v1=int32([1, 2, 3]), v2=single([4, 5, 6]))); + w.close(); + end + + function testAliases(testCase, format) + w = create_validating_writer(testCase, format, 'Aliases'); + w.write_aliased_string("hello"); + w.write_aliased_enum(test_model.Fruits.APPLE); + w.write_aliased_open_generic(test_model.AliasedOpenGeneric(v1="hello", v2=test_model.Fruits.BANANA)); + w.write_aliased_closed_generic(test_model.AliasedClosedGeneric(v1="hello", v2=test_model.Fruits.PEAR)); + w.write_aliased_optional(int32(23)); + w.write_aliased_generic_optional(single(44)); + w.write_aliased_generic_union_2(test_model.AliasedGenericUnion2.T1("hello")); + w.write_aliased_generic_vector(single([1.0, 33.0, 44.0])); + w.write_aliased_generic_fixed_vector(single([1.0, 33.0, 44.0])); + w.write_stream_of_aliased_generic_union_2([ ... + test_model.AliasedGenericUnion2.T1("hello"), ... + test_model.AliasedGenericUnion2.T2(test_model.Fruits.APPLE) ... + ]); + w.end_stream_of_aliased_generic_union_2(); + w.close(); + end + end +end + + +function w = create_validating_writer(testCase, format, protocol) + writer_name = "test_model." + format + "." + protocol + "Writer"; + reader_name = "test_model." + format + "." + protocol + "Reader"; + test_writer_name = "test_model.testing.Test" + protocol + "Writer"; + + create_writer = str2func(writer_name); + create_reader = str2func(reader_name); + create_test_writer = str2func(test_writer_name); + + w = create_test_writer(testCase, format, @(f) create_writer(f), @(f) create_reader(f)); +end diff --git a/matlab/test/SerializerShapeTest.m b/matlab/test/SerializerShapeTest.m new file mode 100644 index 00000000..c54ca35b --- /dev/null +++ b/matlab/test/SerializerShapeTest.m @@ -0,0 +1,107 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef SerializerShapeTest < matlab.unittest.TestCase + methods (Test) + + function testFixedVectorShape(testCase) + fvs = yardl.binary.FixedVectorSerializer(yardl.binary.Int32Serializer, 42); + testCase.verifyEqual(fvs.get_shape(), [1, 42]); + + fvs = yardl.binary.FixedVectorSerializer(fvs, 11); + testCase.verifyEqual(fvs.get_shape(), [42, 11]); + + fvs = yardl.binary.FixedVectorSerializer(yardl.binary.VectorSerializer(yardl.binary.Int32Serializer), 13); + testCase.verifyEqual(fvs.get_shape(), [1, 13]); + + fvs = yardl.binary.FixedVectorSerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [3, 4]), 5); + testCase.verifyEqual(fvs.get_shape(), [3, 4, 5]); + + fvs = yardl.binary.FixedVectorSerializer(yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2), 6); + testCase.verifyEqual(fvs.get_shape(), [1, 6]); + + fvs = yardl.binary.FixedVectorSerializer(yardl.binary.DynamicNDArraySerializer(yardl.binary.Int32Serializer), 7); + testCase.verifyEqual(fvs.get_shape(), [1, 7]); + end + + function testVectorShape(testCase) + vs = yardl.binary.VectorSerializer(yardl.binary.Int32Serializer); + testCase.verifyEqual(vs.get_shape(), []); + + vs = yardl.binary.VectorSerializer(vs); + testCase.verifyEqual(vs.get_shape(), []); + + vs = yardl.binary.VectorSerializer(yardl.binary.FixedVectorSerializer(yardl.binary.Int32Serializer, 42)); + testCase.verifyEqual(vs.get_shape(), []); + + fvs = yardl.binary.VectorSerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [3, 4])); + testCase.verifyEqual(fvs.get_shape(), []); + + fvs = yardl.binary.VectorSerializer(yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2)); + testCase.verifyEqual(fvs.get_shape(), []); + + fvs = yardl.binary.VectorSerializer(yardl.binary.DynamicNDArraySerializer(yardl.binary.Int32Serializer)); + testCase.verifyEqual(fvs.get_shape(), []); + end + + function testFixedNDArrayShape(testCase) + fas = yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [3, 4]); + testCase.verifyEqual(fas.get_shape(), [3, 4]); + + fas = yardl.binary.FixedNDArraySerializer(fas, [5, 6]); + testCase.verifyEqual(fas.get_shape(), [3, 4, 5, 6]); + + fas = yardl.binary.FixedNDArraySerializer(yardl.binary.VectorSerializer(yardl.binary.Int32Serializer), [7, 8]); + testCase.verifyEqual(fas.get_shape(), [7, 8]); + + fas = yardl.binary.FixedNDArraySerializer(yardl.binary.FixedVectorSerializer(yardl.binary.Int32Serializer, 42), [7, 8]); + testCase.verifyEqual(fas.get_shape(), [42, 7, 8]); + + fas = yardl.binary.FixedNDArraySerializer(yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2), [7, 8]); + testCase.verifyEqual(fas.get_shape(), [7, 8]); + + fas = yardl.binary.FixedNDArraySerializer(yardl.binary.DynamicNDArraySerializer(yardl.binary.Int32Serializer), [7, 8]); + testCase.verifyEqual(fas.get_shape(), [7, 8]); + end + + function testNDArrayShape(testCase) + nas = yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2); + testCase.verifyEqual(nas.get_shape(), []); + + nas = yardl.binary.NDArraySerializer(nas, 3); + testCase.verifyEqual(nas.get_shape(), []); + + nas = yardl.binary.NDArraySerializer(yardl.binary.VectorSerializer(yardl.binary.Int32Serializer), 2); + testCase.verifyEqual(nas.get_shape(), []); + + nas = yardl.binary.NDArraySerializer(yardl.binary.FixedVectorSerializer(yardl.binary.Int32Serializer, 42), 2); + testCase.verifyEqual(nas.get_shape(), []); + + nas = yardl.binary.NDArraySerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [5, 6]), 2); + testCase.verifyEqual(nas.get_shape(), []); + + nas = yardl.binary.NDArraySerializer(yardl.binary.DynamicNDArraySerializer(yardl.binary.Int32Serializer), 2); + testCase.verifyEqual(nas.get_shape(), []); + end + + function testDynamicNDArrayShape(testCase) + das = yardl.binary.DynamicNDArraySerializer(yardl.binary.Int32Serializer); + testCase.verifyEqual(das.get_shape(), []); + + das = yardl.binary.DynamicNDArraySerializer(das); + testCase.verifyEqual(das.get_shape(), []); + + das = yardl.binary.DynamicNDArraySerializer(yardl.binary.VectorSerializer(yardl.binary.Int32Serializer)); + testCase.verifyEqual(das.get_shape(), []); + + das = yardl.binary.DynamicNDArraySerializer(yardl.binary.FixedVectorSerializer(yardl.binary.Int32Serializer, 42)); + testCase.verifyEqual(das.get_shape(), []); + + das = yardl.binary.DynamicNDArraySerializer(yardl.binary.FixedNDArraySerializer(yardl.binary.Int32Serializer, [5, 6])); + testCase.verifyEqual(das.get_shape(), []); + + das = yardl.binary.DynamicNDArraySerializer(yardl.binary.NDArraySerializer(yardl.binary.Int32Serializer, 2)); + testCase.verifyEqual(das.get_shape(), []); + end + end +end diff --git a/matlab/test/YardlTypesTest.m b/matlab/test/YardlTypesTest.m new file mode 100644 index 00000000..6e034b66 --- /dev/null +++ b/matlab/test/YardlTypesTest.m @@ -0,0 +1,153 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef YardlTypesTest < matlab.unittest.TestCase + + methods (Test) + + function testDateTimeFromValidDatetime(testCase) + dt = yardl.DateTime.from_datetime(datetime(2020, 2, 29, 12, 22, 44, .111222)); + testCase.verifyEqual(dt.value(), int64(1582978964000111222)); + end + + function testDateTimeFromValidComponents(testCase) + dt = yardl.DateTime.from_components(2020, 2, 29, 12, 22, 44, 111222); + testCase.verifyEqual(dt.value(), int64(1582978964000111222)); + end + + function testDateTimeFromInvalidComponents(testCase) + % nanosecond out of range + testCase.verifyError(@() yardl.DateTime.from_components(2021, 2, 15, 12, 22, 44, 9999999999999999), 'yardl:ValueError'); + end + + function testDateTimeFromInt(testCase) + dt = yardl.DateTime(1577967764111222333); + mdt = dt.to_datetime(); + testCase.verifyEqual(mdt.Year, 2020); + testCase.verifyEqual(mdt.Month, 1); + testCase.verifyEqual(mdt.Day, 2); + testCase.verifyEqual(mdt.Hour, 12); + testCase.verifyEqual(mdt.Minute, 22); + testCase.verifyEqual(mdt.Second * 1e9, 44111222333, 'RelTol', 1e-8); + end + + function testDateFromValidDatetime(testCase) + d = yardl.Date.from_datetime(datetime(2020, 2, 29)); + testCase.verifyEqual(d.value(), 18321); + end + + function testDateFromValidComponents(testCase) + d = yardl.Date.from_components(2020, 2, 29); + md = d.to_datetime(); + testCase.verifyEqual(md.Year, 2020); + testCase.verifyEqual(md.Month, 2); + testCase.verifyEqual(md.Day, 29); + end + + function testTimeFromValidDatetime(testCase) + t = yardl.Time.from_datetime(datetime(2024, 3, 11, 12, 22, 44, 111.222)); + mdt = t.to_datetime(); + testCase.verifyEqual(mdt.Hour, 12); + testCase.verifyEqual(mdt.Minute, 22); + testCase.verifyEqual(mdt.Second * 1e9, 44111222000, 'RelTol', 1e-8); + end + + function testTimeFromValidComponents(testCase) + t = yardl.Time.from_components(12, 22, 44, 111222333); + mdt = t.to_datetime(); + testCase.verifyEqual(mdt.Hour, 12); + testCase.verifyEqual(mdt.Minute, 22); + testCase.verifyEqual(mdt.Second * 1e9, 44111222333, 'RelTol', 1e-8); + end + + function testTimeFromInvalidComponents(testCase) + % hour out of range + testCase.verifyError(@() yardl.Time.from_components(24, 0, 0, 0), 'yardl:ValueError'); + + % minute out of range + testCase.verifyError(@() yardl.Time.from_components(12, -3, 0, 0), 'yardl:ValueError'); + + % second out of range + testCase.verifyError(@() yardl.Time.from_components(12, 22, 74, 0), 'yardl:ValueError'); + + % nanosecond out of range + testCase.verifyError(@() yardl.Time.from_components(12, 22, 44, 9999999999999999), 'yardl:ValueError'); + end + + function testOptionals(testCase) + % None.has_value == false + testCase.verifyEqual(yardl.None().has_value, false); + % Optional(X).has_value == true + testCase.verifyEqual(yardl.Optional(42).has_value, true); + + % ERROR: None.value + testCase.verifyError(@() yardl.None().value, 'yardl:ValueError'); + + % ERROR: None.has_value = true + function setHasValueTrue() + o = yardl.None; + o.has_value = true; + end + testCase.verifyError(@setHasValueTrue, 'MATLAB:class:SetProhibited'); + + % ERROR: Optional(x).has_value = false + function setHasValueFalse() + o = yardl.Optional(42); + o.has_value = false; + end + testCase.verifyError(@setHasValueFalse, 'MATLAB:class:SetProhibited'); + + % None == None + testCase.verifyEqual(yardl.None, yardl.None); + + % Optional(X) == Optional(X) + testCase.verifyEqual(yardl.Optional(int16(42)), yardl.Optional(int16(42))); + testCase.verifyEqual(yardl.Optional("hello"), yardl.Optional("hello")); + testCase.verifyEqual(yardl.Optional([]), yardl.Optional([])); + testCase.verifyEqual(yardl.Optional([[1, 2]; [3, 4]]), yardl.Optional([[1, 2]; [3, 4]])); + + % Optional(X) == X + testCase.verifyTrue(yardl.Optional(int16(42)) == int16(42)); + testCase.verifyTrue(yardl.Optional("hello") == "hello"); + testCase.verifyTrue(isequal(yardl.Optional([]), [])); + testCase.verifyTrue(isequal(yardl.Optional([[1, 2]; [3, 4]]), [[1, 2]; [3, 4]])); + + % X == Optional(X) + testCase.verifyEqual(int16(42), yardl.Optional(int16(42))); + testCase.verifyEqual("hello", yardl.Optional("hello")); + testCase.verifyEqual([], yardl.Optional([])); + testCase.verifyEqual([[1, 2]; [3, 4]], yardl.Optional([[1, 2]; [3, 4]])); + + % None ~= Optional(X) + testCase.verifyNotEqual(yardl.None, yardl.Optional(42)); + + % Optional(X) ~= None + testCase.verifyNotEqual(yardl.Optional(42), yardl.None); + + % None ~= X + testCase.verifyNotEqual(yardl.None, 42); + % X ~= None + testCase.verifyNotEqual(42, yardl.None); + + % [Optionals] == [Optionals] + os = arrayfun(@yardl.Optional, 1:5); + testCase.verifyEqual(os, os); + + % [Nones] == [Nones] + nones = repelem(yardl.None, 5); + testCase.verifyEqual(nones, nones); + + % [Optional, None, ...] == [Optional, None, ...] + mixed1 = [1, 2, yardl.None, 4, 5, yardl.None]; + testCase.verifyEqual(mixed1, mixed1); + mixed2 = [yardl.Optional(1), yardl.Optional(2), yardl.None, yardl.Optional(4), yardl.Optional(5), yardl.None]; + testCase.verifyEqual(mixed1, mixed2); + testCase.verifyEqual(mixed2, mixed1); + + % [Optional, None, ...] ~= [None, Optional, ...] + mixed3 = [1, 2, yardl.None, 4, 5, 6]; + testCase.verifyNotEqual(mixed1, mixed3); + testCase.verifyNotEqual(mixed3, mixed1); + end + end +end diff --git a/matlab/test/benchmark.m b/matlab/test/benchmark.m new file mode 100644 index 00000000..9d802273 --- /dev/null +++ b/matlab/test/benchmark.m @@ -0,0 +1,293 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +function benchmark(varargin) + if nargin ~= 2 + error("Usage: benchmark "); + end + + scenario = parse_scenario(varargin{1}); + format = parse_format(varargin{2}); + + % Matlab support currently implemented for binary format only + if format ~= "binary" + return + end + + addpath("../generated/"); + fprintf("%s\n", scenario(format)); +end + +function output_filename = get_output_filename() + output_filename = "/tmp/benchmark_data.dat"; +end + +function format = parse_format(format) + switch format + case "binary" + format = "binary"; + case "ndjson" + format = "ndjson"; + case "hdf5" + format = "hdf5"; + otherwise + error("Invalid format"); + end +end + +function scenario = parse_scenario(scenario) + switch scenario + case "float256x256" + scenario = @benchmark_float256x256; + case "floatvlen" + scenario = @benchmark_float_vlen; + case "smallint256x256" + scenario = @benchmark_small_int_256x256; + case "smallrecord" + scenario = @benchmark_small_record; + case "smallrecordbatched" + scenario = @benchmark_small_record_batched; + case "smalloptionalsbatched" + scenario = @benchmark_small_optionals_batched; + case "simplemrd" + scenario = @benchmark_simple_mrd; + otherwise + error("Invalid scenario"); + end +end + +function [writer, reader] = create_writer_reader(format, protocol) + format_name = "test_model." + format + "." + protocol; + writer_name = format_name + "Writer"; + reader_name = format_name + "Reader"; + writer = str2func(writer_name); + reader = str2func(reader_name); +end + +function w = create_validating_writer(testCase, format, protocol) + writer_name = "test_model." + format + "." + protocol + "Writer"; + reader_name = "test_model." + format + "." + protocol + "Reader"; + test_writer_name = "test_model.testing.Test" + protocol + "Writer"; + + create_writer = str2func(writer_name); + create_reader = str2func(reader_name); + create_test_writer = str2func(test_writer_name); + + w = create_test_writer(testCase, format, @(f) create_writer(f), @(f) create_reader(f)); +end + +function reps = scale_repetitions(repetitions, scale) + reps = repetitions * scale; +end + +function res = time_scenario(total_bytes_size, write_func, read_func) + delete(get_output_filename()); + + total_size_mi_byte = total_bytes_size / 1024 / 1024; + + write_start = tic; + write_func(); + write_elapsed = toc(write_start); + write_mibps = total_size_mi_byte / write_elapsed; + + read_start = tic; + read_func(); + read_elapsed = toc(read_start); + read_mibps = total_size_mi_byte / read_elapsed; + + s.write_mi_bytes_per_second = write_mibps; + s.read_mi_bytes_per_second = read_mibps; + s.roundtrip_duration_seconds = write_elapsed + read_elapsed; + res = jsonencode(s); +end + +function res = benchmark_float256x256(format) + scale = 1; + + a = zeros(256, 256, 'single'); + for i = 1:numel(a) + a(i) = i - eps; + end + + repetitions = scale_repetitions(10000, scale); + total_bytes = 4 * numel(a) * repetitions; + + [create_writer, create_reader] = create_writer_reader(format, 'BenchmarkFloat256x256'); + + function write() + w = create_writer(get_output_filename()); + for r = 1:repetitions + w.write_float256x256({a}); + end + w.end_float256x256(); + w.close(); + end + + function read() + r = create_reader(get_output_filename()); + count = 0; + while r.has_float256x256() + b = r.read_float256x256(); + count = count + 1; + end + assert(count == repetitions); + r.close(); + end + + res = time_scenario(total_bytes, @write, @read); +end + +function res = benchmark_float_vlen(format) + scale = 1; + + a = zeros(256, 256, 'single'); + for i = 1:numel(a) + a(i) = i - eps; + end + + repetitions = scale_repetitions(10000, scale); + total_bytes = 4 * numel(a) * repetitions; + + [create_writer, create_reader] = create_writer_reader(format, 'BenchmarkFloatVlen'); + + function write() + w = create_writer(get_output_filename()); + for r = 1:repetitions + w.write_float_array({a}); + end + w.end_float_array(); + w.close(); + end + + function read() + r = create_reader(get_output_filename()); + count = 0; + while r.has_float_array() + b = r.read_float_array(); + count = count + 1; + end + assert(count == repetitions); + r.close(); + end + + res = time_scenario(total_bytes, @write, @read); +end + +function res = benchmark_small_int_256x256(format) + scale = 1; + + a = zeros(256, 256, 'int32'); + for i = 1:numel(a) + a(i) = int32(37); + end + + repetitions = scale_repetitions(10, scale); + total_bytes = 4 * numel(a) * repetitions; + + [create_writer, create_reader] = create_writer_reader(format, 'BenchmarkInt256x256'); + + function write() + w = create_writer(get_output_filename()); + for r = 1:repetitions + w.write_int256x256({a}); + end + w.end_int256x256(); + w.close(); + end + + function read() + r = create_reader(get_output_filename()); + count = 0; + while r.has_int256x256() + b = r.read_int256x256(); + count = count + 1; + end + assert(count == repetitions); + r.close(); + end + + res = time_scenario(total_bytes, @write, @read); +end + +function res = benchmark_small_record(format) + scale = 1; + + record = test_model.SmallBenchmarkRecord(); + record.a = double(73278383.23123213); + record.b = single(78323.2820379); + record.c = single(-2938923.29882); + + repetitions = scale_repetitions(50000, scale); + total_bytes = 16 * repetitions; + + [create_writer, create_reader] = create_writer_reader(format, 'BenchmarkSmallRecord'); + + function write() + w = create_writer(get_output_filename()); + for r = 1:repetitions + w.write_small_record({record}); + end + w.end_small_record(); + w.close(); + end + + function read() + r = create_reader(get_output_filename()); + count = 0; + while r.has_small_record() + b = r.read_small_record(); + count = count + 1; + end + assert(count == repetitions); + r.close(); + end + + res = time_scenario(total_bytes, @write, @read); +end + +function res = benchmark_small_record_batched(format) + % Batching has not yet been implemented for Matlab + res = ""; +end + +function res = benchmark_small_optionals_batched(format) + % Batching has not yet been implemented for Matlab + res = ""; +end + +function res = benchmark_simple_mrd(format) + scale = 1; + + acq = test_model.SimpleAcquisition(); + acq.data = complex(zeros(256, 32, 'single')); + acq.trajectory = zeros(2, 32, 'single'); + + value = test_model.AcquisitionOrImage.Acquisition(acq); + + repetitions = scale_repetitions(2500, scale); + total_bytes = 66032 * repetitions; + + [create_writer, create_reader] = create_writer_reader(format, 'BenchmarkSimpleMrd'); + + function write() + w = create_writer(get_output_filename()); + for r = 1:repetitions + w.write_data({value}); + end + w.end_data(); + w.close(); + end + + function read() + r = create_reader(get_output_filename()); + count = 0; + while r.has_data() + b = r.read_data(); + count = count + 1; + end + assert(count == repetitions); + r.close(); + end + + res = time_scenario(total_bytes, @write, @read); +end diff --git a/matlab/test/invoke_translator.m b/matlab/test/invoke_translator.m new file mode 100644 index 00000000..fee8da68 --- /dev/null +++ b/matlab/test/invoke_translator.m @@ -0,0 +1,17 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +function output_filename = invoke_translator(input_filename, input_format, output_format) + translator_path = "../../cpp/build/translator"; + output_filename = sprintf("%s.translated", input_filename); + dump = "cat"; + if ispc + dump = "type"; + end + cmd = sprintf("%s %s | %s %s %s > %s", dump, input_filename, translator_path, input_format, output_format, output_filename); + + [status, cmdout] = system(cmd); + if status ~= 0 + error("Failed to invoke translator: %s", cmdout); + end +end diff --git a/matlab/test/run_tests.m b/matlab/test/run_tests.m new file mode 100644 index 00000000..d764d132 --- /dev/null +++ b/matlab/test/run_tests.m @@ -0,0 +1,5 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +addpath("../generated/"); +assertSuccess(runtests(pwd)); diff --git a/models/sandbox/_package.yml b/models/sandbox/_package.yml index e4048ffd..29e8cb5c 100644 --- a/models/sandbox/_package.yml +++ b/models/sandbox/_package.yml @@ -5,3 +5,6 @@ cpp: python: outputDir: ../../python/ + +matlab: + outputDir: ../../matlab/generated diff --git a/models/test/_package.yml b/models/test/_package.yml index e051f7b0..a079acbd 100644 --- a/models/test/_package.yml +++ b/models/test/_package.yml @@ -17,5 +17,10 @@ python: outputDir: ../../python/ internalSymlinkStaticFiles: true +matlab: + outputDir: ../../matlab/generated + internalGenerateMocks: true + internalSymlinkStaticFiles: true + json: outputDir: ../../cpp/test/generated diff --git a/models/test/unittests.yml b/models/test/unittests.yml index b37caf96..0ecf5826 100644 --- a/models/test/unittests.yml +++ b/models/test/unittests.yml @@ -297,6 +297,13 @@ DynamicNDArrays: !protocol recordWithVlensArray: RecordWithVlens[] recordWithDynamicNDArrays: RecordWithDynamicNDArrays +MultiDArrays: !protocol + sequence: + images: !stream + items: float[ch, z, y, x] + frames: !stream + items: float[ch:1, z:1, y:64, x:32] + Maps: !protocol sequence: stringToInt: string->int @@ -554,6 +561,7 @@ RecordWithComputedFields: !record vectorField: int* vectorOfVectorsField: int** fixedVectorField: int*3 + fixedVectorOfVectorsField: int*3*2 optionalNamedArray: NamedNDArray? intFloatUnion: [int, float] nullableIntFloatUnion: [null, int, float] @@ -582,6 +590,7 @@ RecordWithComputedFields: !record accessVectorField: vectorField accessVectorFieldElement: vectorField[1] accessVectorOfVectorsField: vectorOfVectorsField[1][2] + accessFixedVectorOfVectorsField: fixedVectorOfVectorsField[1][2] arraySize: size(arrayField) arrayXSize: size(arrayField, "x") arrayYSize: size(arrayField, "y") @@ -596,6 +605,7 @@ RecordWithComputedFields: !record fixedArray0Size: size(fixedArrayField, 0) vectorSize: size(vectorField) fixedVectorSize: size(fixedVectorField) + fixedVectorOfVectorsSize: size(fixedVectorOfVectorsField) arrayDimensionXIndex: dimensionIndex(arrayField, "x") arrayDimensionYIndex: dimensionIndex(arrayField, "y") arrayDimensionIndexFromStringField: dimensionIndex(arrayField, stringField) diff --git a/python/benchmark.py b/python/benchmark.py index c15f23d5..555eee58 100755 --- a/python/benchmark.py +++ b/python/benchmark.py @@ -1,6 +1,7 @@ #! /usr/bin/env python3 from dataclasses import dataclass +import argparse import inspect import json import os @@ -24,10 +25,6 @@ OUTPUT_FILE = "/tmp/benchmark_data.dat" -# Setting this to True will display the roundtrip duration instead of the throughput -# and should only be done to calibrate the scales of each scenario and format. -DISPLAY_DURATIONS = False - @dataclass class Result: @@ -39,12 +36,17 @@ class Result: class MutlitingualResults(NamedTuple): cpp: Optional[Result] python: Optional[Result] + matlab: Optional[Result] _cpp_benchmark_path = ( pathlib.Path(__file__).parent / "../cpp/build/benchmark" ).resolve() +_matlab_benchmark_path = ( + (pathlib.Path(__file__).parent / "../matlab/test/benchmark.m").resolve().parent +) + def scale_repetitions(repetitions: int, scale: float): return int(repetitions * scale) @@ -256,16 +258,36 @@ def invoke_cpp_benchmark(scenario: str, format: Format) -> Optional[Result]: return Result(**json.loads(res.stdout), roundtrip_duration_seconds=elapsed_seconds) +def invoke_matlab_benchmark(scenario: str, format: Format) -> Optional[Result]: + res = subprocess.run( + # Workaround for CI: run-matlab-command is a wrapper around `matlab -batch` + # See https://github.com/matlab-actions/run-command/issues/53 + ["run-matlab-command", f"benchmark('{scenario}', '{format}')"], + cwd=_matlab_benchmark_path, + stdout=subprocess.PIPE, + check=True, + encoding="utf-8", + ) + if res.stdout.strip() == "": + return None + return Result(**json.loads(res.stdout)) + + def scenario_name(scenario_func: Callable[[Format], Optional[Result]]) -> str: return scenario_func.__name__.removeprefix("benchmark").replace("_", "") def invoke_benchmark( - scenario_func: Callable[[Format], Optional[Result]], format: Format + scenario_func: Callable[[Format], Optional[Result]], + format: Format, + include_matlab: bool, ) -> MutlitingualResults: cpp_res = invoke_cpp_benchmark(scenario_name(scenario_func), format) python_res = scenario_func(format) - return MutlitingualResults(cpp=cpp_res, python=python_res) + matlab_res = None + if include_matlab: + matlab_res = invoke_matlab_benchmark(scenario_name(scenario_func), format) + return MutlitingualResults(cpp=cpp_res, python=python_res, matlab=matlab_res) def update_table( @@ -274,6 +296,7 @@ def update_table( scenario_func: Callable[[Format], Optional[Result]], format: Format, results: MutlitingualResults, + display_durations: bool, ): def format_float(thoughput: float) -> str: return f"{thoughput:,.2f}" @@ -287,45 +310,89 @@ def color(): return "green" return None - if DISPLAY_DURATIONS: + if display_durations: table.add_row( scenario_name(scenario_func), str(format), - format_float(results.cpp.roundtrip_duration_seconds) - if results.cpp - else None, - format_float(results.python.roundtrip_duration_seconds) - if results.python - else None, + ( + format_float(results.cpp.roundtrip_duration_seconds) + if results.cpp + else None + ), + ( + format_float(results.python.roundtrip_duration_seconds) + if results.python + else None + ), + ( + format_float(results.matlab.roundtrip_duration_seconds) + if results.matlab + else None + ), style=color(), ) else: table.add_row( scenario_name(scenario_func), str(format), - format_float(results.cpp.write_mi_bytes_per_second) - if results.cpp - else None, - format_float(results.cpp.read_mi_bytes_per_second) if results.cpp else None, - format_float(results.python.write_mi_bytes_per_second) - if results.python - else None, - format_float(results.python.read_mi_bytes_per_second) - if results.python - else None, + ( + format_float(results.cpp.write_mi_bytes_per_second) + if results.cpp + else None + ), + ( + format_float(results.cpp.read_mi_bytes_per_second) + if results.cpp + else None + ), + ( + format_float(results.python.write_mi_bytes_per_second) + if results.python + else None + ), + ( + format_float(results.python.read_mi_bytes_per_second) + if results.python + else None + ), + ( + format_float(results.matlab.write_mi_bytes_per_second) + if results.matlab + else None + ), + ( + format_float(results.matlab.read_mi_bytes_per_second) + if results.matlab + else None + ), style=color(), ) live.refresh() if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument( + "--display-durations", + action="store_true", + help="Display the roundtrip duration instead of the throughput. " + "Use only to calibrate the scales of each scenario and format", + ) + parser.add_argument( + "--include-matlab", + action="store_true", + help="Include Matlab benchmarking results", + ) + args = parser.parse_args() + table = Table() - if DISPLAY_DURATIONS: + if args.display_durations: table.title = "Roundtrip duration" table.add_column("Scenario") table.add_column("Format") table.add_column("C++ Duration", justify="right") table.add_column("Python Duration", justify="right") + table.add_column("Matlab Duration", justify="right") else: table.title = "Throughput in MiB/s" table.add_column("Scenario") @@ -334,6 +401,8 @@ def color(): table.add_column("C++ Read", justify="right") table.add_column("Python Write", justify="right") table.add_column("Python Read", justify="right") + table.add_column("Matlab Write", justify="right") + table.add_column("Matlab Read", justify="right") with Live(table, auto_refresh=False) as live: for _, benchmark_func in inspect.getmembers( @@ -342,5 +411,7 @@ def color(): ): table.add_section() for format in [Format.HDF5, Format.BINARY, Format.NDJSON]: - res = invoke_benchmark(benchmark_func, format) - update_table(table, live, benchmark_func, format, res) + res = invoke_benchmark(benchmark_func, format, args.include_matlab) + update_table( + table, live, benchmark_func, format, res, args.display_durations + ) diff --git a/python/test_model/__init__.py b/python/test_model/__init__.py index 6546c76e..9b49f57e 100644 --- a/python/test_model/__init__.py +++ b/python/test_model/__init__.py @@ -145,6 +145,8 @@ def _parse_version(version: str) -> _Tuple[int, ...]: FlagsWriterBase, MapsReaderBase, MapsWriterBase, + MultiDArraysReaderBase, + MultiDArraysWriterBase, NDArraysReaderBase, NDArraysSingleDimensionReaderBase, NDArraysSingleDimensionWriterBase, @@ -211,6 +213,8 @@ def _parse_version(version: str) -> _Tuple[int, ...]: BinaryFlagsWriter, BinaryMapsReader, BinaryMapsWriter, + BinaryMultiDArraysReader, + BinaryMultiDArraysWriter, BinaryNDArraysReader, BinaryNDArraysSingleDimensionReader, BinaryNDArraysSingleDimensionWriter, @@ -277,6 +281,8 @@ def _parse_version(version: str) -> _Tuple[int, ...]: NDJsonFlagsWriter, NDJsonMapsReader, NDJsonMapsWriter, + NDJsonMultiDArraysReader, + NDJsonMultiDArraysWriter, NDJsonNDArraysReader, NDJsonNDArraysSingleDimensionReader, NDJsonNDArraysSingleDimensionWriter, diff --git a/python/test_model/binary.py b/python/test_model/binary.py index 06e80973..3cf168c6 100644 --- a/python/test_model/binary.py +++ b/python/test_model/binary.py @@ -701,6 +701,35 @@ def _read_record_with_vlens_array(self) -> npt.NDArray[np.void]: def _read_record_with_dynamic_nd_arrays(self) -> RecordWithDynamicNDArrays: return RecordWithDynamicNDArraysSerializer().read(self._stream) +class BinaryMultiDArraysWriter(_binary.BinaryProtocolWriter, MultiDArraysWriterBase): + """Binary writer for the MultiDArrays protocol.""" + + + def __init__(self, stream: typing.Union[typing.BinaryIO, str]) -> None: + MultiDArraysWriterBase.__init__(self) + _binary.BinaryProtocolWriter.__init__(self, stream, MultiDArraysWriterBase.schema) + + def _write_images(self, value: collections.abc.Iterable[npt.NDArray[np.float32]]) -> None: + _binary.StreamSerializer(_binary.NDArraySerializer(_binary.float32_serializer, 4)).write(self._stream, value) + + def _write_frames(self, value: collections.abc.Iterable[npt.NDArray[np.float32]]) -> None: + _binary.StreamSerializer(_binary.FixedNDArraySerializer(_binary.float32_serializer, (1, 1, 64, 32,))).write(self._stream, value) + + +class BinaryMultiDArraysReader(_binary.BinaryProtocolReader, MultiDArraysReaderBase): + """Binary writer for the MultiDArrays protocol.""" + + + def __init__(self, stream: typing.Union[io.BufferedReader, io.BytesIO, typing.BinaryIO, str]) -> None: + MultiDArraysReaderBase.__init__(self) + _binary.BinaryProtocolReader.__init__(self, stream, MultiDArraysReaderBase.schema) + + def _read_images(self) -> collections.abc.Iterable[npt.NDArray[np.float32]]: + return _binary.StreamSerializer(_binary.NDArraySerializer(_binary.float32_serializer, 4)).read(self._stream) + + def _read_frames(self) -> collections.abc.Iterable[npt.NDArray[np.float32]]: + return _binary.StreamSerializer(_binary.FixedNDArraySerializer(_binary.float32_serializer, (1, 1, 64, 32,))).read(self._stream) + class BinaryMapsWriter(_binary.BinaryProtocolWriter, MapsWriterBase): """Binary writer for the Maps protocol.""" @@ -1873,20 +1902,20 @@ def read(self, stream: _binary.CodedInputStream) -> RecordContainingNestedGeneri class RecordWithComputedFieldsSerializer(_binary.RecordSerializer[RecordWithComputedFields]): def __init__(self) -> None: - super().__init__([("array_field", _binary.NDArraySerializer(_binary.int32_serializer, 2)), ("array_field_map_dimensions", _binary.NDArraySerializer(_binary.int32_serializer, 2)), ("dynamic_array_field", _binary.DynamicNDArraySerializer(_binary.int32_serializer)), ("fixed_array_field", _binary.FixedNDArraySerializer(_binary.int32_serializer, (3, 4,))), ("int_field", _binary.int32_serializer), ("int8_field", _binary.int8_serializer), ("uint8_field", _binary.uint8_serializer), ("int16_field", _binary.int16_serializer), ("uint16_field", _binary.uint16_serializer), ("uint32_field", _binary.uint32_serializer), ("int64_field", _binary.int64_serializer), ("uint64_field", _binary.uint64_serializer), ("size_field", _binary.size_serializer), ("float32_field", _binary.float32_serializer), ("float64_field", _binary.float64_serializer), ("complexfloat32_field", _binary.complexfloat32_serializer), ("complexfloat64_field", _binary.complexfloat64_serializer), ("string_field", _binary.string_serializer), ("tuple_field", tuples.binary.TupleSerializer(_binary.int32_serializer, _binary.int32_serializer)), ("vector_field", _binary.VectorSerializer(_binary.int32_serializer)), ("vector_of_vectors_field", _binary.VectorSerializer(_binary.VectorSerializer(_binary.int32_serializer))), ("fixed_vector_field", _binary.FixedVectorSerializer(_binary.int32_serializer, 3)), ("optional_named_array", _binary.OptionalSerializer(_binary.NDArraySerializer(_binary.int32_serializer, 2))), ("int_float_union", _binary.UnionSerializer(Int32OrFloat32, [(Int32OrFloat32.Int32, _binary.int32_serializer), (Int32OrFloat32.Float32, _binary.float32_serializer)])), ("nullable_int_float_union", _binary.UnionSerializer(Int32OrFloat32, [None, (Int32OrFloat32.Int32, _binary.int32_serializer), (Int32OrFloat32.Float32, _binary.float32_serializer)])), ("union_with_nested_generic_union", _binary.UnionSerializer(IntOrGenericRecordWithComputedFields, [(IntOrGenericRecordWithComputedFields.Int, _binary.int32_serializer), (IntOrGenericRecordWithComputedFields.GenericRecordWithComputedFields, basic_types.binary.GenericRecordWithComputedFieldsSerializer(_binary.string_serializer, _binary.float32_serializer))])), ("map_field", _binary.MapSerializer(_binary.string_serializer, _binary.string_serializer))]) + super().__init__([("array_field", _binary.NDArraySerializer(_binary.int32_serializer, 2)), ("array_field_map_dimensions", _binary.NDArraySerializer(_binary.int32_serializer, 2)), ("dynamic_array_field", _binary.DynamicNDArraySerializer(_binary.int32_serializer)), ("fixed_array_field", _binary.FixedNDArraySerializer(_binary.int32_serializer, (3, 4,))), ("int_field", _binary.int32_serializer), ("int8_field", _binary.int8_serializer), ("uint8_field", _binary.uint8_serializer), ("int16_field", _binary.int16_serializer), ("uint16_field", _binary.uint16_serializer), ("uint32_field", _binary.uint32_serializer), ("int64_field", _binary.int64_serializer), ("uint64_field", _binary.uint64_serializer), ("size_field", _binary.size_serializer), ("float32_field", _binary.float32_serializer), ("float64_field", _binary.float64_serializer), ("complexfloat32_field", _binary.complexfloat32_serializer), ("complexfloat64_field", _binary.complexfloat64_serializer), ("string_field", _binary.string_serializer), ("tuple_field", tuples.binary.TupleSerializer(_binary.int32_serializer, _binary.int32_serializer)), ("vector_field", _binary.VectorSerializer(_binary.int32_serializer)), ("vector_of_vectors_field", _binary.VectorSerializer(_binary.VectorSerializer(_binary.int32_serializer))), ("fixed_vector_field", _binary.FixedVectorSerializer(_binary.int32_serializer, 3)), ("fixed_vector_of_vectors_field", _binary.FixedVectorSerializer(_binary.FixedVectorSerializer(_binary.int32_serializer, 3), 2)), ("optional_named_array", _binary.OptionalSerializer(_binary.NDArraySerializer(_binary.int32_serializer, 2))), ("int_float_union", _binary.UnionSerializer(Int32OrFloat32, [(Int32OrFloat32.Int32, _binary.int32_serializer), (Int32OrFloat32.Float32, _binary.float32_serializer)])), ("nullable_int_float_union", _binary.UnionSerializer(Int32OrFloat32, [None, (Int32OrFloat32.Int32, _binary.int32_serializer), (Int32OrFloat32.Float32, _binary.float32_serializer)])), ("union_with_nested_generic_union", _binary.UnionSerializer(IntOrGenericRecordWithComputedFields, [(IntOrGenericRecordWithComputedFields.Int, _binary.int32_serializer), (IntOrGenericRecordWithComputedFields.GenericRecordWithComputedFields, basic_types.binary.GenericRecordWithComputedFieldsSerializer(_binary.string_serializer, _binary.float32_serializer))])), ("map_field", _binary.MapSerializer(_binary.string_serializer, _binary.string_serializer))]) def write(self, stream: _binary.CodedOutputStream, value: RecordWithComputedFields) -> None: if isinstance(value, np.void): self.write_numpy(stream, value) return - self._write(stream, value.array_field, value.array_field_map_dimensions, value.dynamic_array_field, value.fixed_array_field, value.int_field, value.int8_field, value.uint8_field, value.int16_field, value.uint16_field, value.uint32_field, value.int64_field, value.uint64_field, value.size_field, value.float32_field, value.float64_field, value.complexfloat32_field, value.complexfloat64_field, value.string_field, value.tuple_field, value.vector_field, value.vector_of_vectors_field, value.fixed_vector_field, value.optional_named_array, value.int_float_union, value.nullable_int_float_union, value.union_with_nested_generic_union, value.map_field) + self._write(stream, value.array_field, value.array_field_map_dimensions, value.dynamic_array_field, value.fixed_array_field, value.int_field, value.int8_field, value.uint8_field, value.int16_field, value.uint16_field, value.uint32_field, value.int64_field, value.uint64_field, value.size_field, value.float32_field, value.float64_field, value.complexfloat32_field, value.complexfloat64_field, value.string_field, value.tuple_field, value.vector_field, value.vector_of_vectors_field, value.fixed_vector_field, value.fixed_vector_of_vectors_field, value.optional_named_array, value.int_float_union, value.nullable_int_float_union, value.union_with_nested_generic_union, value.map_field) def write_numpy(self, stream: _binary.CodedOutputStream, value: np.void) -> None: - self._write(stream, value['array_field'], value['array_field_map_dimensions'], value['dynamic_array_field'], value['fixed_array_field'], value['int_field'], value['int8_field'], value['uint8_field'], value['int16_field'], value['uint16_field'], value['uint32_field'], value['int64_field'], value['uint64_field'], value['size_field'], value['float32_field'], value['float64_field'], value['complexfloat32_field'], value['complexfloat64_field'], value['string_field'], value['tuple_field'], value['vector_field'], value['vector_of_vectors_field'], value['fixed_vector_field'], value['optional_named_array'], value['int_float_union'], value['nullable_int_float_union'], value['union_with_nested_generic_union'], value['map_field']) + self._write(stream, value['array_field'], value['array_field_map_dimensions'], value['dynamic_array_field'], value['fixed_array_field'], value['int_field'], value['int8_field'], value['uint8_field'], value['int16_field'], value['uint16_field'], value['uint32_field'], value['int64_field'], value['uint64_field'], value['size_field'], value['float32_field'], value['float64_field'], value['complexfloat32_field'], value['complexfloat64_field'], value['string_field'], value['tuple_field'], value['vector_field'], value['vector_of_vectors_field'], value['fixed_vector_field'], value['fixed_vector_of_vectors_field'], value['optional_named_array'], value['int_float_union'], value['nullable_int_float_union'], value['union_with_nested_generic_union'], value['map_field']) def read(self, stream: _binary.CodedInputStream) -> RecordWithComputedFields: field_values = self._read(stream) - return RecordWithComputedFields(array_field=field_values[0], array_field_map_dimensions=field_values[1], dynamic_array_field=field_values[2], fixed_array_field=field_values[3], int_field=field_values[4], int8_field=field_values[5], uint8_field=field_values[6], int16_field=field_values[7], uint16_field=field_values[8], uint32_field=field_values[9], int64_field=field_values[10], uint64_field=field_values[11], size_field=field_values[12], float32_field=field_values[13], float64_field=field_values[14], complexfloat32_field=field_values[15], complexfloat64_field=field_values[16], string_field=field_values[17], tuple_field=field_values[18], vector_field=field_values[19], vector_of_vectors_field=field_values[20], fixed_vector_field=field_values[21], optional_named_array=field_values[22], int_float_union=field_values[23], nullable_int_float_union=field_values[24], union_with_nested_generic_union=field_values[25], map_field=field_values[26]) + return RecordWithComputedFields(array_field=field_values[0], array_field_map_dimensions=field_values[1], dynamic_array_field=field_values[2], fixed_array_field=field_values[3], int_field=field_values[4], int8_field=field_values[5], uint8_field=field_values[6], int16_field=field_values[7], uint16_field=field_values[8], uint32_field=field_values[9], int64_field=field_values[10], uint64_field=field_values[11], size_field=field_values[12], float32_field=field_values[13], float64_field=field_values[14], complexfloat32_field=field_values[15], complexfloat64_field=field_values[16], string_field=field_values[17], tuple_field=field_values[18], vector_field=field_values[19], vector_of_vectors_field=field_values[20], fixed_vector_field=field_values[21], fixed_vector_of_vectors_field=field_values[22], optional_named_array=field_values[23], int_float_union=field_values[24], nullable_int_float_union=field_values[25], union_with_nested_generic_union=field_values[26], map_field=field_values[27]) class RecordNotUsedInProtocolSerializer(_binary.RecordSerializer[RecordNotUsedInProtocol]): diff --git a/python/test_model/ndjson.py b/python/test_model/ndjson.py index d597c183..1025db3a 100644 --- a/python/test_model/ndjson.py +++ b/python/test_model/ndjson.py @@ -2140,6 +2140,7 @@ def __init__(self) -> None: self._vector_field_converter = _ndjson.VectorConverter(_ndjson.int32_converter) self._vector_of_vectors_field_converter = _ndjson.VectorConverter(_ndjson.VectorConverter(_ndjson.int32_converter)) self._fixed_vector_field_converter = _ndjson.FixedVectorConverter(_ndjson.int32_converter, 3) + self._fixed_vector_of_vectors_field_converter = _ndjson.FixedVectorConverter(_ndjson.FixedVectorConverter(_ndjson.int32_converter, 3), 2) self._optional_named_array_converter = _ndjson.OptionalConverter(_ndjson.NDArrayConverter(_ndjson.int32_converter, 2)) self._int_float_union_converter = _ndjson.UnionConverter(Int32OrFloat32, [(Int32OrFloat32.Int32, _ndjson.int32_converter, [int, float]), (Int32OrFloat32.Float32, _ndjson.float32_converter, [int, float])], False) self._nullable_int_float_union_converter = _ndjson.UnionConverter(Int32OrFloat32, [None, (Int32OrFloat32.Int32, _ndjson.int32_converter, [int, float]), (Int32OrFloat32.Float32, _ndjson.float32_converter, [int, float])], False) @@ -2168,6 +2169,7 @@ def __init__(self) -> None: ("vector_field", self._vector_field_converter.overall_dtype()), ("vector_of_vectors_field", self._vector_of_vectors_field_converter.overall_dtype()), ("fixed_vector_field", self._fixed_vector_field_converter.overall_dtype()), + ("fixed_vector_of_vectors_field", self._fixed_vector_of_vectors_field_converter.overall_dtype()), ("optional_named_array", self._optional_named_array_converter.overall_dtype()), ("int_float_union", self._int_float_union_converter.overall_dtype()), ("nullable_int_float_union", self._nullable_int_float_union_converter.overall_dtype()), @@ -2202,6 +2204,7 @@ def to_json(self, value: RecordWithComputedFields) -> object: json_object["vectorField"] = self._vector_field_converter.to_json(value.vector_field) json_object["vectorOfVectorsField"] = self._vector_of_vectors_field_converter.to_json(value.vector_of_vectors_field) json_object["fixedVectorField"] = self._fixed_vector_field_converter.to_json(value.fixed_vector_field) + json_object["fixedVectorOfVectorsField"] = self._fixed_vector_of_vectors_field_converter.to_json(value.fixed_vector_of_vectors_field) if value.optional_named_array is not None: json_object["optionalNamedArray"] = self._optional_named_array_converter.to_json(value.optional_named_array) json_object["intFloatUnion"] = self._int_float_union_converter.to_json(value.int_float_union) @@ -2238,6 +2241,7 @@ def numpy_to_json(self, value: np.void) -> object: json_object["vectorField"] = self._vector_field_converter.numpy_to_json(value["vector_field"]) json_object["vectorOfVectorsField"] = self._vector_of_vectors_field_converter.numpy_to_json(value["vector_of_vectors_field"]) json_object["fixedVectorField"] = self._fixed_vector_field_converter.numpy_to_json(value["fixed_vector_field"]) + json_object["fixedVectorOfVectorsField"] = self._fixed_vector_of_vectors_field_converter.numpy_to_json(value["fixed_vector_of_vectors_field"]) if (field_val := value["optional_named_array"]) is not None: json_object["optionalNamedArray"] = self._optional_named_array_converter.numpy_to_json(field_val) json_object["intFloatUnion"] = self._int_float_union_converter.numpy_to_json(value["int_float_union"]) @@ -2273,6 +2277,7 @@ def from_json(self, json_object: object) -> RecordWithComputedFields: vector_field=self._vector_field_converter.from_json(json_object["vectorField"],), vector_of_vectors_field=self._vector_of_vectors_field_converter.from_json(json_object["vectorOfVectorsField"],), fixed_vector_field=self._fixed_vector_field_converter.from_json(json_object["fixedVectorField"],), + fixed_vector_of_vectors_field=self._fixed_vector_of_vectors_field_converter.from_json(json_object["fixedVectorOfVectorsField"],), optional_named_array=self._optional_named_array_converter.from_json(json_object.get("optionalNamedArray")), int_float_union=self._int_float_union_converter.from_json(json_object["intFloatUnion"],), nullable_int_float_union=self._nullable_int_float_union_converter.from_json(json_object.get("nullableIntFloatUnion")), @@ -2306,6 +2311,7 @@ def from_json_to_numpy(self, json_object: object) -> np.void: self._vector_field_converter.from_json_to_numpy(json_object["vectorField"]), self._vector_of_vectors_field_converter.from_json_to_numpy(json_object["vectorOfVectorsField"]), self._fixed_vector_field_converter.from_json_to_numpy(json_object["fixedVectorField"]), + self._fixed_vector_of_vectors_field_converter.from_json_to_numpy(json_object["fixedVectorOfVectorsField"]), self._optional_named_array_converter.from_json_to_numpy(json_object.get("optionalNamedArray")), self._int_float_union_converter.from_json_to_numpy(json_object["intFloatUnion"]), self._nullable_int_float_union_converter.from_json_to_numpy(json_object.get("nullableIntFloatUnion")), @@ -3334,6 +3340,45 @@ def _read_record_with_dynamic_nd_arrays(self) -> RecordWithDynamicNDArrays: converter = RecordWithDynamicNDArraysConverter() return converter.from_json(json_object) +class NDJsonMultiDArraysWriter(_ndjson.NDJsonProtocolWriter, MultiDArraysWriterBase): + """NDJson writer for the MultiDArrays protocol.""" + + + def __init__(self, stream: typing.Union[typing.TextIO, str]) -> None: + MultiDArraysWriterBase.__init__(self) + _ndjson.NDJsonProtocolWriter.__init__(self, stream, MultiDArraysWriterBase.schema) + + def _write_images(self, value: collections.abc.Iterable[npt.NDArray[np.float32]]) -> None: + converter = _ndjson.NDArrayConverter(_ndjson.float32_converter, 4) + for item in value: + json_item = converter.to_json(item) + self._write_json_line({"images": json_item}) + + def _write_frames(self, value: collections.abc.Iterable[npt.NDArray[np.float32]]) -> None: + converter = _ndjson.FixedNDArrayConverter(_ndjson.float32_converter, (1, 1, 64, 32,)) + for item in value: + json_item = converter.to_json(item) + self._write_json_line({"frames": json_item}) + + +class NDJsonMultiDArraysReader(_ndjson.NDJsonProtocolReader, MultiDArraysReaderBase): + """NDJson writer for the MultiDArrays protocol.""" + + + def __init__(self, stream: typing.Union[io.BufferedReader, typing.TextIO, str]) -> None: + MultiDArraysReaderBase.__init__(self) + _ndjson.NDJsonProtocolReader.__init__(self, stream, MultiDArraysReaderBase.schema) + + def _read_images(self) -> collections.abc.Iterable[npt.NDArray[np.float32]]: + converter = _ndjson.NDArrayConverter(_ndjson.float32_converter, 4) + while (json_object := self._read_json_line("images", False)) is not _ndjson.MISSING_SENTINEL: + yield converter.from_json(json_object) + + def _read_frames(self) -> collections.abc.Iterable[npt.NDArray[np.float32]]: + converter = _ndjson.FixedNDArrayConverter(_ndjson.float32_converter, (1, 1, 64, 32,)) + while (json_object := self._read_json_line("frames", False)) is not _ndjson.MISSING_SENTINEL: + yield converter.from_json(json_object) + class NDJsonMapsWriter(_ndjson.NDJsonProtocolWriter, MapsWriterBase): """NDJson writer for the Maps protocol.""" diff --git a/python/test_model/protocols.py b/python/test_model/protocols.py index 30f019bd..9276f020 100644 --- a/python/test_model/protocols.py +++ b/python/test_model/protocols.py @@ -3769,6 +3769,173 @@ def _state_to_method_name(self, state: int) -> str: return 'read_record_with_dynamic_nd_arrays' return "" +class MultiDArraysWriterBase(abc.ABC): + """Abstract writer for the MultiDArrays protocol.""" + + + def __init__(self) -> None: + self._state = 0 + + schema = r"""{"protocol":{"name":"MultiDArrays","sequence":[{"name":"images","type":{"stream":{"items":{"array":{"items":"float32","dimensions":[{"name":"ch"},{"name":"z"},{"name":"y"},{"name":"x"}]}}}}},{"name":"frames","type":{"stream":{"items":{"array":{"items":"float32","dimensions":[{"name":"ch","length":1},{"name":"z","length":1},{"name":"y","length":64},{"name":"x","length":32}]}}}}}]},"types":null}""" + + def close(self) -> None: + if self._state == 3: + try: + self._end_stream() + return + finally: + self._close() + self._close() + if self._state != 4: + expected_method = self._state_to_method_name((self._state + 1) & ~1) + raise ProtocolError(f"Protocol writer closed before all steps were called. Expected to call to '{expected_method}'.") + + def __enter__(self): + return self + + def __exit__(self, exc_type: typing.Optional[type[BaseException]], exc: typing.Optional[BaseException], traceback: object) -> None: + try: + self.close() + except Exception as e: + if exc is None: + raise e + + def write_images(self, value: collections.abc.Iterable[npt.NDArray[np.float32]]) -> None: + """Ordinal 0""" + + if self._state & ~1 != 0: + self._raise_unexpected_state(0) + + self._write_images(value) + self._state = 1 + + def write_frames(self, value: collections.abc.Iterable[npt.NDArray[np.float32]]) -> None: + """Ordinal 1""" + + if self._state == 1: + self._end_stream() + self._state = 2 + elif self._state & ~1 != 2: + self._raise_unexpected_state(2) + + self._write_frames(value) + self._state = 3 + + @abc.abstractmethod + def _write_images(self, value: collections.abc.Iterable[npt.NDArray[np.float32]]) -> None: + raise NotImplementedError() + + @abc.abstractmethod + def _write_frames(self, value: collections.abc.Iterable[npt.NDArray[np.float32]]) -> None: + raise NotImplementedError() + + @abc.abstractmethod + def _close(self) -> None: + pass + + @abc.abstractmethod + def _end_stream(self) -> None: + pass + + def _raise_unexpected_state(self, actual: int) -> None: + expected_method = self._state_to_method_name(self._state) + actual_method = self._state_to_method_name(actual) + raise ProtocolError(f"Expected to call to '{expected_method}' but received call to '{actual_method}'.") + + def _state_to_method_name(self, state: int) -> str: + if state == 0: + return 'write_images' + if state == 2: + return 'write_frames' + return "" + +class MultiDArraysReaderBase(abc.ABC): + """Abstract reader for the MultiDArrays protocol.""" + + + def __init__(self) -> None: + self._state = 0 + + def close(self) -> None: + self._close() + if self._state != 4: + if self._state % 2 == 1: + previous_method = self._state_to_method_name(self._state - 1) + raise ProtocolError(f"Protocol reader closed before all data was consumed. The iterable returned by '{previous_method}' was not fully consumed.") + else: + expected_method = self._state_to_method_name(self._state) + raise ProtocolError(f"Protocol reader closed before all data was consumed. Expected call to '{expected_method}'.") + + + schema = MultiDArraysWriterBase.schema + + def __enter__(self): + return self + + def __exit__(self, exc_type: typing.Optional[type[BaseException]], exc: typing.Optional[BaseException], traceback: object) -> None: + try: + self.close() + except Exception as e: + if exc is None: + raise e + + @abc.abstractmethod + def _close(self) -> None: + raise NotImplementedError() + + def read_images(self) -> collections.abc.Iterable[npt.NDArray[np.float32]]: + """Ordinal 0""" + + if self._state != 0: + self._raise_unexpected_state(0) + + value = self._read_images() + self._state = 1 + return self._wrap_iterable(value, 2) + + def read_frames(self) -> collections.abc.Iterable[npt.NDArray[np.float32]]: + """Ordinal 1""" + + if self._state != 2: + self._raise_unexpected_state(2) + + value = self._read_frames() + self._state = 3 + return self._wrap_iterable(value, 4) + + def copy_to(self, writer: MultiDArraysWriterBase) -> None: + writer.write_images(self.read_images()) + writer.write_frames(self.read_frames()) + + @abc.abstractmethod + def _read_images(self) -> collections.abc.Iterable[npt.NDArray[np.float32]]: + raise NotImplementedError() + + @abc.abstractmethod + def _read_frames(self) -> collections.abc.Iterable[npt.NDArray[np.float32]]: + raise NotImplementedError() + + T = typing.TypeVar('T') + def _wrap_iterable(self, iterable: collections.abc.Iterable[T], final_state: int) -> collections.abc.Iterable[T]: + yield from iterable + self._state = final_state + + def _raise_unexpected_state(self, actual: int) -> None: + actual_method = self._state_to_method_name(actual) + if self._state % 2 == 1: + previous_method = self._state_to_method_name(self._state - 1) + raise ProtocolError(f"Received call to '{actual_method}' but the iterable returned by '{previous_method}' was not fully consumed.") + else: + expected_method = self._state_to_method_name(self._state) + raise ProtocolError(f"Expected to call to '{expected_method}' but received call to '{actual_method}'.") + + def _state_to_method_name(self, state: int) -> str: + if state == 0: + return 'read_images' + if state == 2: + return 'read_frames' + return "" + class MapsWriterBase(abc.ABC): """Abstract writer for the Maps protocol.""" @@ -6166,7 +6333,7 @@ class ProtocolWithComputedFieldsWriterBase(abc.ABC): def __init__(self) -> None: self._state = 0 - schema = r"""{"protocol":{"name":"ProtocolWithComputedFields","sequence":[{"name":"recordWithComputedFields","type":"TestModel.RecordWithComputedFields"}]},"types":[{"name":"GenericRecordWithComputedFields","typeParameters":["T0","T1"],"fields":[{"name":"f1","type":[{"tag":"T0","type":"T0"},{"tag":"T1","type":"T1"}]}]},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"Tuples.Tuple","typeArguments":["T1","T2"]}},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"BasicTypes.MyTuple","typeArguments":["T1","T2"]}},{"name":"NamedNDArray","type":{"array":{"items":"int32","dimensions":[{"name":"dimA"},{"name":"dimB"}]}}},{"name":"RecordWithComputedFields","fields":[{"name":"arrayField","type":{"array":{"items":"int32","dimensions":[{"name":"x"},{"name":"y"}]}}},{"name":"arrayFieldMapDimensions","type":{"array":{"items":"int32","dimensions":[{"name":"x"},{"name":"y"}]}}},{"name":"dynamicArrayField","type":{"array":{"items":"int32"}}},{"name":"fixedArrayField","type":{"array":{"items":"int32","dimensions":[{"name":"x","length":3},{"name":"y","length":4}]}}},{"name":"intField","type":"int32"},{"name":"int8Field","type":"int8"},{"name":"uint8Field","type":"uint8"},{"name":"int16Field","type":"int16"},{"name":"uint16Field","type":"uint16"},{"name":"uint32Field","type":"uint32"},{"name":"int64Field","type":"int64"},{"name":"uint64Field","type":"uint64"},{"name":"sizeField","type":"size"},{"name":"float32Field","type":"float32"},{"name":"float64Field","type":"float64"},{"name":"complexfloat32Field","type":"complexfloat32"},{"name":"complexfloat64Field","type":"complexfloat64"},{"name":"stringField","type":"string"},{"name":"tupleField","type":{"name":"TestModel.MyTuple","typeArguments":["int32","int32"]}},{"name":"vectorField","type":{"vector":{"items":"int32"}}},{"name":"vectorOfVectorsField","type":{"vector":{"items":{"vector":{"items":"int32"}}}}},{"name":"fixedVectorField","type":{"vector":{"items":"int32","length":3}}},{"name":"optionalNamedArray","type":[null,"TestModel.NamedNDArray"]},{"name":"intFloatUnion","type":[{"tag":"int32","type":"int32"},{"tag":"float32","type":"float32"}]},{"name":"nullableIntFloatUnion","type":[null,{"tag":"int32","type":"int32"},{"tag":"float32","type":"float32"}]},{"name":"unionWithNestedGenericUnion","type":[{"tag":"int","explicitTag":true,"type":"int32"},{"tag":"genericRecordWithComputedFields","explicitTag":true,"type":{"name":"BasicTypes.GenericRecordWithComputedFields","typeArguments":["string","float32"]}}]},{"name":"mapField","type":{"map":{"keys":"string","values":"string"}}}]},{"name":"Tuple","typeParameters":["T1","T2"],"fields":[{"name":"v1","type":"T1"},{"name":"v2","type":"T2"}]}]}""" + schema = r"""{"protocol":{"name":"ProtocolWithComputedFields","sequence":[{"name":"recordWithComputedFields","type":"TestModel.RecordWithComputedFields"}]},"types":[{"name":"GenericRecordWithComputedFields","typeParameters":["T0","T1"],"fields":[{"name":"f1","type":[{"tag":"T0","type":"T0"},{"tag":"T1","type":"T1"}]}]},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"Tuples.Tuple","typeArguments":["T1","T2"]}},{"name":"MyTuple","typeParameters":["T1","T2"],"type":{"name":"BasicTypes.MyTuple","typeArguments":["T1","T2"]}},{"name":"NamedNDArray","type":{"array":{"items":"int32","dimensions":[{"name":"dimA"},{"name":"dimB"}]}}},{"name":"RecordWithComputedFields","fields":[{"name":"arrayField","type":{"array":{"items":"int32","dimensions":[{"name":"x"},{"name":"y"}]}}},{"name":"arrayFieldMapDimensions","type":{"array":{"items":"int32","dimensions":[{"name":"x"},{"name":"y"}]}}},{"name":"dynamicArrayField","type":{"array":{"items":"int32"}}},{"name":"fixedArrayField","type":{"array":{"items":"int32","dimensions":[{"name":"x","length":3},{"name":"y","length":4}]}}},{"name":"intField","type":"int32"},{"name":"int8Field","type":"int8"},{"name":"uint8Field","type":"uint8"},{"name":"int16Field","type":"int16"},{"name":"uint16Field","type":"uint16"},{"name":"uint32Field","type":"uint32"},{"name":"int64Field","type":"int64"},{"name":"uint64Field","type":"uint64"},{"name":"sizeField","type":"size"},{"name":"float32Field","type":"float32"},{"name":"float64Field","type":"float64"},{"name":"complexfloat32Field","type":"complexfloat32"},{"name":"complexfloat64Field","type":"complexfloat64"},{"name":"stringField","type":"string"},{"name":"tupleField","type":{"name":"TestModel.MyTuple","typeArguments":["int32","int32"]}},{"name":"vectorField","type":{"vector":{"items":"int32"}}},{"name":"vectorOfVectorsField","type":{"vector":{"items":{"vector":{"items":"int32"}}}}},{"name":"fixedVectorField","type":{"vector":{"items":"int32","length":3}}},{"name":"fixedVectorOfVectorsField","type":{"vector":{"items":{"vector":{"items":"int32","length":3}},"length":2}}},{"name":"optionalNamedArray","type":[null,"TestModel.NamedNDArray"]},{"name":"intFloatUnion","type":[{"tag":"int32","type":"int32"},{"tag":"float32","type":"float32"}]},{"name":"nullableIntFloatUnion","type":[null,{"tag":"int32","type":"int32"},{"tag":"float32","type":"float32"}]},{"name":"unionWithNestedGenericUnion","type":[{"tag":"int","explicitTag":true,"type":"int32"},{"tag":"genericRecordWithComputedFields","explicitTag":true,"type":{"name":"BasicTypes.GenericRecordWithComputedFields","typeArguments":["string","float32"]}}]},{"name":"mapField","type":{"map":{"keys":"string","values":"string"}}}]},{"name":"Tuple","typeParameters":["T1","T2"],"fields":[{"name":"v1","type":"T1"},{"name":"v2","type":"T2"}]}]}""" def close(self) -> None: self._close() diff --git a/python/test_model/types.py b/python/test_model/types.py index e66d0aa8..9cd9911d 100644 --- a/python/test_model/types.py +++ b/python/test_model/types.py @@ -1433,6 +1433,7 @@ class RecordWithComputedFields: vector_field: list[yardl.Int32] vector_of_vectors_field: list[list[yardl.Int32]] fixed_vector_field: list[yardl.Int32] + fixed_vector_of_vectors_field: list[list[yardl.Int32]] optional_named_array: typing.Optional[NamedNDArray] int_float_union: Int32OrFloat32 nullable_int_float_union: typing.Optional[Int32OrFloat32] @@ -1462,6 +1463,7 @@ def __init__(self, *, vector_field: typing.Optional[list[yardl.Int32]] = None, vector_of_vectors_field: typing.Optional[list[list[yardl.Int32]]] = None, fixed_vector_field: typing.Optional[list[yardl.Int32]] = None, + fixed_vector_of_vectors_field: typing.Optional[list[list[yardl.Int32]]] = None, optional_named_array: typing.Optional[NamedNDArray] = None, int_float_union: Int32OrFloat32 = Int32OrFloat32.Int32(0), nullable_int_float_union: typing.Optional[Int32OrFloat32] = None, @@ -1490,6 +1492,7 @@ def __init__(self, *, self.vector_field = vector_field if vector_field is not None else [] self.vector_of_vectors_field = vector_of_vectors_field if vector_of_vectors_field is not None else [] self.fixed_vector_field = fixed_vector_field if fixed_vector_field is not None else [0] * 3 + self.fixed_vector_of_vectors_field = fixed_vector_of_vectors_field if fixed_vector_of_vectors_field is not None else [[0] * 3 for _ in range(2)] self.optional_named_array = optional_named_array self.int_float_union = int_float_union self.nullable_int_float_union = nullable_int_float_union @@ -1550,6 +1553,9 @@ def access_vector_field_element(self) -> yardl.Int32: def access_vector_of_vectors_field(self) -> yardl.Int32: return self.vector_of_vectors_field[1][2] + def access_fixed_vector_of_vectors_field(self) -> yardl.Int32: + return self.fixed_vector_of_vectors_field[1][2] + def array_size(self) -> yardl.Size: return self.array_field.size @@ -1599,6 +1605,9 @@ def vector_size(self) -> yardl.Size: def fixed_vector_size(self) -> yardl.Size: return 3 + def fixed_vector_of_vectors_size(self) -> yardl.Size: + return 2 + def array_dimension_x_index(self) -> yardl.Size: return 0 @@ -1779,6 +1788,7 @@ def __eq__(self, other: object) -> bool: and self.vector_field == other.vector_field and self.vector_of_vectors_field == other.vector_of_vectors_field and self.fixed_vector_field == other.fixed_vector_field + and self.fixed_vector_of_vectors_field == other.fixed_vector_of_vectors_field and (other.optional_named_array is None if self.optional_named_array is None else (other.optional_named_array is not None and yardl.structural_equal(self.optional_named_array, other.optional_named_array))) and self.int_float_union == other.int_float_union and self.nullable_int_float_union == other.nullable_int_float_union @@ -1787,10 +1797,10 @@ def __eq__(self, other: object) -> bool: ) def __str__(self) -> str: - return f"RecordWithComputedFields(arrayField={self.array_field}, arrayFieldMapDimensions={self.array_field_map_dimensions}, dynamicArrayField={self.dynamic_array_field}, fixedArrayField={self.fixed_array_field}, intField={self.int_field}, int8Field={self.int8_field}, uint8Field={self.uint8_field}, int16Field={self.int16_field}, uint16Field={self.uint16_field}, uint32Field={self.uint32_field}, int64Field={self.int64_field}, uint64Field={self.uint64_field}, sizeField={self.size_field}, float32Field={self.float32_field}, float64Field={self.float64_field}, complexfloat32Field={self.complexfloat32_field}, complexfloat64Field={self.complexfloat64_field}, stringField={self.string_field}, tupleField={self.tuple_field}, vectorField={self.vector_field}, vectorOfVectorsField={self.vector_of_vectors_field}, fixedVectorField={self.fixed_vector_field}, optionalNamedArray={self.optional_named_array}, intFloatUnion={self.int_float_union}, nullableIntFloatUnion={self.nullable_int_float_union}, unionWithNestedGenericUnion={self.union_with_nested_generic_union}, mapField={self.map_field})" + return f"RecordWithComputedFields(arrayField={self.array_field}, arrayFieldMapDimensions={self.array_field_map_dimensions}, dynamicArrayField={self.dynamic_array_field}, fixedArrayField={self.fixed_array_field}, intField={self.int_field}, int8Field={self.int8_field}, uint8Field={self.uint8_field}, int16Field={self.int16_field}, uint16Field={self.uint16_field}, uint32Field={self.uint32_field}, int64Field={self.int64_field}, uint64Field={self.uint64_field}, sizeField={self.size_field}, float32Field={self.float32_field}, float64Field={self.float64_field}, complexfloat32Field={self.complexfloat32_field}, complexfloat64Field={self.complexfloat64_field}, stringField={self.string_field}, tupleField={self.tuple_field}, vectorField={self.vector_field}, vectorOfVectorsField={self.vector_of_vectors_field}, fixedVectorField={self.fixed_vector_field}, fixedVectorOfVectorsField={self.fixed_vector_of_vectors_field}, optionalNamedArray={self.optional_named_array}, intFloatUnion={self.int_float_union}, nullableIntFloatUnion={self.nullable_int_float_union}, unionWithNestedGenericUnion={self.union_with_nested_generic_union}, mapField={self.map_field})" def __repr__(self) -> str: - return f"RecordWithComputedFields(arrayField={repr(self.array_field)}, arrayFieldMapDimensions={repr(self.array_field_map_dimensions)}, dynamicArrayField={repr(self.dynamic_array_field)}, fixedArrayField={repr(self.fixed_array_field)}, intField={repr(self.int_field)}, int8Field={repr(self.int8_field)}, uint8Field={repr(self.uint8_field)}, int16Field={repr(self.int16_field)}, uint16Field={repr(self.uint16_field)}, uint32Field={repr(self.uint32_field)}, int64Field={repr(self.int64_field)}, uint64Field={repr(self.uint64_field)}, sizeField={repr(self.size_field)}, float32Field={repr(self.float32_field)}, float64Field={repr(self.float64_field)}, complexfloat32Field={repr(self.complexfloat32_field)}, complexfloat64Field={repr(self.complexfloat64_field)}, stringField={repr(self.string_field)}, tupleField={repr(self.tuple_field)}, vectorField={repr(self.vector_field)}, vectorOfVectorsField={repr(self.vector_of_vectors_field)}, fixedVectorField={repr(self.fixed_vector_field)}, optionalNamedArray={repr(self.optional_named_array)}, intFloatUnion={repr(self.int_float_union)}, nullableIntFloatUnion={repr(self.nullable_int_float_union)}, unionWithNestedGenericUnion={repr(self.union_with_nested_generic_union)}, mapField={repr(self.map_field)})" + return f"RecordWithComputedFields(arrayField={repr(self.array_field)}, arrayFieldMapDimensions={repr(self.array_field_map_dimensions)}, dynamicArrayField={repr(self.dynamic_array_field)}, fixedArrayField={repr(self.fixed_array_field)}, intField={repr(self.int_field)}, int8Field={repr(self.int8_field)}, uint8Field={repr(self.uint8_field)}, int16Field={repr(self.int16_field)}, uint16Field={repr(self.uint16_field)}, uint32Field={repr(self.uint32_field)}, int64Field={repr(self.int64_field)}, uint64Field={repr(self.uint64_field)}, sizeField={repr(self.size_field)}, float32Field={repr(self.float32_field)}, float64Field={repr(self.float64_field)}, complexfloat32Field={repr(self.complexfloat32_field)}, complexfloat64Field={repr(self.complexfloat64_field)}, stringField={repr(self.string_field)}, tupleField={repr(self.tuple_field)}, vectorField={repr(self.vector_field)}, vectorOfVectorsField={repr(self.vector_of_vectors_field)}, fixedVectorField={repr(self.fixed_vector_field)}, fixedVectorOfVectorsField={repr(self.fixed_vector_of_vectors_field)}, optionalNamedArray={repr(self.optional_named_array)}, intFloatUnion={repr(self.int_float_union)}, nullableIntFloatUnion={repr(self.nullable_int_float_union)}, unionWithNestedGenericUnion={repr(self.union_with_nested_generic_union)}, mapField={repr(self.map_field)})" class GenericUnionWithRepeatedTypeParameters(typing.Generic[T, T_NP]): @@ -2037,7 +2047,7 @@ def _mk_get_dtype(): dtype_map.setdefault(typing.Optional[AliasedNullableIntSimpleRecord], np.dtype(np.object_)) dtype_map.setdefault(Int32OrFloat32, np.dtype(np.object_)) dtype_map.setdefault(IntOrGenericRecordWithComputedFields, np.dtype(np.object_)) - dtype_map.setdefault(RecordWithComputedFields, np.dtype([('array_field', np.dtype(np.object_)), ('array_field_map_dimensions', np.dtype(np.object_)), ('dynamic_array_field', np.dtype(np.object_)), ('fixed_array_field', np.dtype(np.int32), (3, 4,)), ('int_field', np.dtype(np.int32)), ('int8_field', np.dtype(np.int8)), ('uint8_field', np.dtype(np.uint8)), ('int16_field', np.dtype(np.int16)), ('uint16_field', np.dtype(np.uint16)), ('uint32_field', np.dtype(np.uint32)), ('int64_field', np.dtype(np.int64)), ('uint64_field', np.dtype(np.uint64)), ('size_field', np.dtype(np.uint64)), ('float32_field', np.dtype(np.float32)), ('float64_field', np.dtype(np.float64)), ('complexfloat32_field', np.dtype(np.complex64)), ('complexfloat64_field', np.dtype(np.complex128)), ('string_field', np.dtype(np.object_)), ('tuple_field', get_dtype(types.GenericAlias(tuples.Tuple, (yardl.Int32, yardl.Int32,)))), ('vector_field', np.dtype(np.object_)), ('vector_of_vectors_field', np.dtype(np.object_)), ('fixed_vector_field', np.dtype(np.int32), (3,)), ('optional_named_array', np.dtype([('has_value', np.dtype(np.bool_)), ('value', np.dtype(np.object_))], align=True)), ('int_float_union', np.dtype(np.object_)), ('nullable_int_float_union', np.dtype(np.object_)), ('union_with_nested_generic_union', np.dtype(np.object_)), ('map_field', np.dtype(np.object_))], align=True)) + dtype_map.setdefault(RecordWithComputedFields, np.dtype([('array_field', np.dtype(np.object_)), ('array_field_map_dimensions', np.dtype(np.object_)), ('dynamic_array_field', np.dtype(np.object_)), ('fixed_array_field', np.dtype(np.int32), (3, 4,)), ('int_field', np.dtype(np.int32)), ('int8_field', np.dtype(np.int8)), ('uint8_field', np.dtype(np.uint8)), ('int16_field', np.dtype(np.int16)), ('uint16_field', np.dtype(np.uint16)), ('uint32_field', np.dtype(np.uint32)), ('int64_field', np.dtype(np.int64)), ('uint64_field', np.dtype(np.uint64)), ('size_field', np.dtype(np.uint64)), ('float32_field', np.dtype(np.float32)), ('float64_field', np.dtype(np.float64)), ('complexfloat32_field', np.dtype(np.complex64)), ('complexfloat64_field', np.dtype(np.complex128)), ('string_field', np.dtype(np.object_)), ('tuple_field', get_dtype(types.GenericAlias(tuples.Tuple, (yardl.Int32, yardl.Int32,)))), ('vector_field', np.dtype(np.object_)), ('vector_of_vectors_field', np.dtype(np.object_)), ('fixed_vector_field', np.dtype(np.int32), (3,)), ('fixed_vector_of_vectors_field', np.dtype(np.int32), (2,)), ('optional_named_array', np.dtype([('has_value', np.dtype(np.bool_)), ('value', np.dtype(np.object_))], align=True)), ('int_float_union', np.dtype(np.object_)), ('nullable_int_float_union', np.dtype(np.object_)), ('union_with_nested_generic_union', np.dtype(np.object_)), ('map_field', np.dtype(np.object_))], align=True)) dtype_map.setdefault(GenericUnionWithRepeatedTypeParameters, lambda type_args: np.dtype(np.object_)) dtype_map.setdefault(GenericUnion3, lambda type_args: np.dtype(np.object_)) dtype_map.setdefault(GenericUnion3Alternate, lambda type_args: np.dtype(np.object_)) diff --git a/tooling/internal/cmd/generatecommand.go b/tooling/internal/cmd/generatecommand.go index 3551c476..d4b88089 100644 --- a/tooling/internal/cmd/generatecommand.go +++ b/tooling/internal/cmd/generatecommand.go @@ -18,6 +18,7 @@ import ( "github.com/inancgumus/screen" "github.com/microsoft/yardl/tooling/internal/cpp" "github.com/microsoft/yardl/tooling/internal/iocommon" + "github.com/microsoft/yardl/tooling/internal/matlab" "github.com/microsoft/yardl/tooling/internal/python" "github.com/microsoft/yardl/tooling/pkg/dsl" "github.com/microsoft/yardl/tooling/pkg/packaging" @@ -167,6 +168,9 @@ func WriteSuccessfulSummary(packageInfo *packaging.PackageInfo) { if packageInfo.Json != nil { fmt.Printf("✅ Wrote JSON to %s.\n", packageInfo.Json.OutputDir) } + if packageInfo.Matlab != nil { + fmt.Printf("✅ Wrote Matlab to %s.\n", packageInfo.Matlab.OutputDir) + } } func generateImpl() (*packaging.PackageInfo, []string, error) { @@ -206,6 +210,13 @@ func generateImpl() (*packaging.PackageInfo, []string, error) { } } + if packageInfo.Matlab != nil { + err = matlab.Generate(env, *packageInfo.Matlab) + if err != nil { + return packageInfo, warnings, err + } + } + return packageInfo, warnings, err } diff --git a/tooling/internal/cmd/initcontent/package.tpl b/tooling/internal/cmd/initcontent/package.tpl index 34e87ebf..af477322 100644 --- a/tooling/internal/cmd/initcontent/package.tpl +++ b/tooling/internal/cmd/initcontent/package.tpl @@ -5,3 +5,6 @@ cpp: python: outputDir: ../python + +matlab: + outputDir: ../matlab diff --git a/tooling/internal/matlab/binary/binary.go b/tooling/internal/matlab/binary/binary.go new file mode 100644 index 00000000..035431f3 --- /dev/null +++ b/tooling/internal/matlab/binary/binary.go @@ -0,0 +1,344 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +package binary + +import ( + "fmt" + "strconv" + "strings" + + "github.com/microsoft/yardl/tooling/internal/formatting" + "github.com/microsoft/yardl/tooling/internal/matlab/common" + "github.com/microsoft/yardl/tooling/pkg/dsl" +) + +func WriteBinary(fw *common.MatlabFileWriter, ns *dsl.Namespace) error { + if ns.IsTopLevel { + if err := writeProtocols(fw, ns); err != nil { + return err + } + } + + return writeRecordSerializers(fw, ns) +} + +func writeProtocols(fw *common.MatlabFileWriter, ns *dsl.Namespace) error { + for _, p := range ns.Protocols { + if err := writeProtocolWriter(fw, p, ns); err != nil { + return err + } + + if err := writeProtocolReader(fw, p, ns); err != nil { + return err + } + } + return nil +} + +func writeProtocolWriter(fw *common.MatlabFileWriter, p *dsl.ProtocolDefinition, ns *dsl.Namespace) error { + return fw.WriteFile(BinaryWriterName(p), func(w *formatting.IndentedWriter) { + abstractWriterName := fmt.Sprintf("%s.%s", common.NamespaceIdentifierName(p.Namespace), common.AbstractWriterName(p)) + fmt.Fprintf(w, "classdef %s < yardl.binary.BinaryProtocolWriter & %s\n", BinaryWriterName(p), abstractWriterName) + common.WriteBlockBody(w, func() { + common.WriteComment(w, fmt.Sprintf("Binary writer for the %s protocol", p.Name)) + common.WriteComment(w, p.Comment) + + w.WriteStringln("properties (Access=protected)") + common.WriteBlockBody(w, func() { + for _, step := range p.Sequence { + w.WriteStringln(serializerName(step)) + } + }) + + w.WriteStringln("") + w.WriteStringln("methods") + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "function self = %s(filename)\n", BinaryWriterName(p)) + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "self@%s();\n", abstractWriterName) + fmt.Fprintf(w, "self@yardl.binary.BinaryProtocolWriter(filename, %s.schema);\n", abstractWriterName) + for _, step := range p.Sequence { + fmt.Fprintf(w, "self.%s = %s;\n", serializerName(step), typeSerializer(step.Type, ns.Name, nil)) + } + }) + }) + w.WriteStringln("") + + w.WriteStringln("methods (Access=protected)") + common.WriteBlockBody(w, func() { + for i, step := range p.Sequence { + fmt.Fprintf(w, "function %s(self, value)\n", common.ProtocolWriteImplMethodName(step)) + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "self.%s.write(self.stream_, value);\n", serializerName(step)) + }) + if i < len(p.Sequence)-1 { + w.WriteStringln("") + } + } + }) + }) + }) +} + +func writeProtocolReader(fw *common.MatlabFileWriter, p *dsl.ProtocolDefinition, ns *dsl.Namespace) error { + return fw.WriteFile(BinaryReaderName(p), func(w *formatting.IndentedWriter) { + abstractReaderName := fmt.Sprintf("%s.%s", common.NamespaceIdentifierName(p.Namespace), common.AbstractReaderName(p)) + fmt.Fprintf(w, "classdef %s < yardl.binary.BinaryProtocolReader & %s\n", BinaryReaderName(p), abstractReaderName) + common.WriteBlockBody(w, func() { + common.WriteComment(w, fmt.Sprintf("Binary reader for the %s protocol", p.Name)) + common.WriteComment(w, p.Comment) + + w.WriteStringln("properties (Access=protected)") + common.WriteBlockBody(w, func() { + for _, step := range p.Sequence { + w.WriteStringln(serializerName(step)) + } + }) + w.WriteStringln("") + + w.WriteStringln("methods") + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "function self = %s(filename)\n", BinaryReaderName(p)) + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "self@%s();\n", abstractReaderName) + fmt.Fprintf(w, "self@yardl.binary.BinaryProtocolReader(filename, %s.schema);\n", abstractReaderName) + for _, step := range p.Sequence { + fmt.Fprintf(w, "self.%s = %s;\n", serializerName(step), typeSerializer(step.Type, ns.Name, nil)) + } + }) + }) + w.WriteStringln("") + + w.WriteStringln("methods (Access=protected)") + common.WriteBlockBody(w, func() { + for i, step := range p.Sequence { + if step.IsStream() { + fmt.Fprintf(w, "function more = %s(self)\n", common.ProtocolHasMoreImplMethodName(step)) + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "more = self.%s.hasnext(self.stream_);\n", serializerName(step)) + }) + w.WriteStringln("") + } + + fmt.Fprintf(w, "function value = %s(self)\n", common.ProtocolReadImplMethodName(step)) + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "value = self.%s.read(self.stream_);\n", serializerName(step)) + }) + if i < len(p.Sequence)-1 { + w.WriteStringln("") + } + } + }) + }) + }) +} + +func serializerName(step *dsl.ProtocolStep) string { + return fmt.Sprintf("%s_serializer", formatting.ToSnakeCase(step.Name)) +} + +func writeRecordSerializers(fw *common.MatlabFileWriter, ns *dsl.Namespace) error { + for _, td := range ns.TypeDefinitions { + switch td := td.(type) { + case *dsl.RecordDefinition: + if err := writeRecordSerializer(fw, td, ns); err != nil { + return err + } + } + } + return nil +} + +func writeRecordSerializer(fw *common.MatlabFileWriter, rec *dsl.RecordDefinition, ns *dsl.Namespace) error { + return fw.WriteFile(recordSerializerClassName(rec, ns.Name), func(w *formatting.IndentedWriter) { + + typeSyntax := common.TypeSyntax(rec, ns.Name) + fmt.Fprintf(w, "classdef %s < yardl.binary.RecordSerializer\n", recordSerializerClassName(rec, ns.Name)) + common.WriteBlockBody(w, func() { + + w.WriteStringln("methods") + common.WriteBlockBody(w, func() { + if len(rec.TypeParameters) > 0 { + typeParamSerializers := make([]string, 0, len(rec.TypeParameters)) + for _, tp := range rec.TypeParameters { + typeParamSerializers = append( + typeParamSerializers, + typeDefinitionSerializer(tp, ns.Name)) + } + + fmt.Fprintf(w, "function self = %s(%s)\n", recordSerializerClassName(rec, ns.Name), strings.Join(typeParamSerializers, ", ")) + } else { + fmt.Fprintf(w, "function self = %s()\n", recordSerializerClassName(rec, ns.Name)) + } + + common.WriteBlockBody(w, func() { + for i, field := range rec.Fields { + fmt.Fprintf(w, "field_serializers{%d} = %s;\n", i+1, typeSerializer(field.Type, ns.Name, nil)) + } + fmt.Fprintf(w, "self@yardl.binary.RecordSerializer('%s', field_serializers);\n", typeSyntax) + }) + w.WriteStringln("") + + fmt.Fprintf(w, "function write(self, outstream, value)\n") + common.WriteBlockBody(w, func() { + w.WriteStringln("arguments") + common.WriteBlockBody(w, func() { + w.WriteStringln("self") + w.WriteStringln("outstream (1,1) yardl.binary.CodedOutputStream") + fmt.Fprintf(w, "value (1,1) %s\n", typeSyntax) + }) + + fieldAccesses := make([]string, len(rec.Fields)) + for i, field := range rec.Fields { + fieldAccesses[i] = fmt.Sprintf("value.%s", common.FieldIdentifierName(field.Name)) + } + fmt.Fprintf(w, "self.write_(outstream, %s);\n", strings.Join(fieldAccesses, ", ")) + }) + w.WriteStringln("") + + fmt.Fprintf(w, "function value = read(self, instream)\n") + common.WriteBlockBody(w, func() { + w.WriteStringln("fields = self.read_(instream);") + fieldWrites := make([]string, len(rec.Fields)) + for i, field := range rec.Fields { + fieldWrites[i] = fmt.Sprintf("%s=fields{%d}", common.FieldIdentifierName(field.Name), i+1) + } + fmt.Fprintf(w, "value = %s(%s);\n", typeSyntax, strings.Join(fieldWrites, ", ")) + }) + }) + }) + }) +} + +func recordSerializerClassName(record *dsl.RecordDefinition, contextNamespace string) string { + return fmt.Sprintf("%sSerializer", formatting.ToPascalCase(record.Name)) +} + +func typeDefinitionSerializer(td dsl.TypeDefinition, contextNamespace string) string { + switch td := td.(type) { + case dsl.PrimitiveDefinition: + return fmt.Sprintf("yardl.binary.%sSerializer", formatting.ToPascalCase(string(td))) + + case *dsl.EnumDefinition: + var baseType dsl.Type + if td.BaseType != nil { + baseType = td.BaseType + } else { + baseType = dsl.Int32Type + } + + elementSerializer := typeSerializer(baseType, contextNamespace, nil) + enumSyntax := common.TypeSyntax(td, contextNamespace) + return fmt.Sprintf("yardl.binary.EnumSerializer('%s', @%s, %s)", enumSyntax, enumSyntax, elementSerializer) + + case *dsl.RecordDefinition: + qualifiedSerializerName := fmt.Sprintf("%s.binary.%s", common.NamespaceIdentifierName(td.Namespace), recordSerializerClassName(td, contextNamespace)) + if len(td.TypeParameters) == 0 { + return fmt.Sprintf("%s()", qualifiedSerializerName) + } + if len(td.TypeArguments) == 0 { + panic("Expected type arguments") + } + + typeArguments := make([]string, 0, len(td.TypeArguments)) + for _, arg := range td.TypeArguments { + typeArguments = append(typeArguments, typeSerializer(arg, contextNamespace, nil)) + } + + return fmt.Sprintf("%s(%s)", qualifiedSerializerName, strings.Join(typeArguments, ", ")) + + case *dsl.GenericTypeParameter: + return fmt.Sprintf("%s_serializer", formatting.ToSnakeCase(td.Name)) + + case *dsl.NamedType: + return typeSerializer(td.Type, contextNamespace, td) + + default: + panic(fmt.Sprintf("Not implemented %T", td)) + } +} + +func typeSerializer(t dsl.Type, contextNamespace string, namedType *dsl.NamedType) string { + switch t := t.(type) { + case nil: + return "yardl.binary.NoneSerializer" + case *dsl.SimpleType: + return typeDefinitionSerializer(t.ResolvedDefinition, contextNamespace) + case *dsl.GeneralizedType: + getScalarSerializer := func() string { + if t.Cases.IsSingle() { + return typeSerializer(t.Cases[0].Type, contextNamespace, namedType) + } + if t.Cases.IsOptional() { + return fmt.Sprintf("yardl.binary.OptionalSerializer(%s)", typeSerializer(t.Cases[1].Type, contextNamespace, namedType)) + } + + unionClassName := common.UnionClassName(t) + if namedType != nil { + unionClassName = fmt.Sprintf("%s.%s", common.NamespaceIdentifierName(namedType.Namespace), namedType.Name) + } else { + unionClassName = fmt.Sprintf("%s.%s", common.NamespaceIdentifierName(contextNamespace), unionClassName) + } + + serializers := make([]string, len(t.Cases)) + factories := make([]string, len(t.Cases)) + for i, c := range t.Cases { + if c.Type == nil { + serializers[i] = "yardl.binary.NoneSerializer" + factories[i] = "yardl.None" + } else { + serializers[i] = typeSerializer(c.Type, contextNamespace, namedType) + factories[i] = fmt.Sprintf("@%s.%s", unionClassName, formatting.ToPascalCase(c.Tag)) + } + } + return fmt.Sprintf("yardl.binary.UnionSerializer('%s', {%s}, {%s})", unionClassName, strings.Join(serializers, ", "), strings.Join(factories, ", ")) + } + + switch td := t.Dimensionality.(type) { + case nil: + return getScalarSerializer() + case *dsl.Stream: + return fmt.Sprintf("yardl.binary.StreamSerializer(%s)", getScalarSerializer()) + case *dsl.Vector: + if td.Length != nil { + return fmt.Sprintf("yardl.binary.FixedVectorSerializer(%s, %d)", getScalarSerializer(), *td.Length) + } + return fmt.Sprintf("yardl.binary.VectorSerializer(%s)", getScalarSerializer()) + case *dsl.Array: + if td.IsFixed() { + dims := make([]string, len(*td.Dimensions)) + for i, d := range *td.Dimensions { + dims[len(*td.Dimensions)-i-1] = strconv.FormatUint(*d.Length, 10) + } + + return fmt.Sprintf("yardl.binary.FixedNDArraySerializer(%s, [%s])", getScalarSerializer(), strings.Join(dims, ", ")) + } + + if td.HasKnownNumberOfDimensions() { + return fmt.Sprintf("yardl.binary.NDArraySerializer(%s, %d)", getScalarSerializer(), len(*td.Dimensions)) + } + + return fmt.Sprintf("yardl.binary.DynamicNDArraySerializer(%s)", getScalarSerializer()) + + case *dsl.Map: + keySerializer := typeSerializer(td.KeyType, contextNamespace, namedType) + valueSerializer := typeSerializer(t.ToScalar(), contextNamespace, namedType) + + return fmt.Sprintf("yardl.binary.MapSerializer(%s, %s)", keySerializer, valueSerializer) + + default: + panic(fmt.Sprintf("Not implemented %T", t.Dimensionality)) + } + default: + panic(fmt.Sprintf("Not implemented %T", t)) + } +} + +func BinaryWriterName(p *dsl.ProtocolDefinition) string { + return fmt.Sprintf("%sWriter", formatting.ToPascalCase(p.Name)) +} + +func BinaryReaderName(p *dsl.ProtocolDefinition) string { + return fmt.Sprintf("%sReader", formatting.ToPascalCase(p.Name)) +} diff --git a/tooling/internal/matlab/common/common.go b/tooling/internal/matlab/common/common.go new file mode 100644 index 00000000..e94a514c --- /dev/null +++ b/tooling/internal/matlab/common/common.go @@ -0,0 +1,278 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +package common + +import ( + "bytes" + "fmt" + "os" + "path" + "strings" + + "github.com/microsoft/yardl/tooling/internal/formatting" + "github.com/microsoft/yardl/tooling/internal/iocommon" + "github.com/microsoft/yardl/tooling/pkg/dsl" + "github.com/rs/zerolog/log" +) + +var isReservedName = map[string]bool{ + "break": true, + "case": true, + "catch": true, + "classdef": true, + "continue": true, + "else": true, + "elseif": true, + "end": true, + "for": true, + "function": true, + "global": true, + "if": true, + "otherwise": true, + "parfor": true, + "persistent": true, + "return": true, + "spmd": true, + "switch": true, + "try": true, + "while": true, +} + +var TypeSyntaxWriter dsl.TypeSyntaxWriter[string] = func(self dsl.TypeSyntaxWriter[string], t dsl.Node, contextNamespace string) string { + switch t := t.(type) { + case dsl.PrimitiveDefinition: + switch t { + case dsl.Bool: + return "bool" + case dsl.Int8: + return "int8" + case dsl.Uint8: + return "uint8" + case dsl.Int16: + return "int16" + case dsl.Uint16: + return "uint16" + case dsl.Int32: + return "int32" + case dsl.Uint32: + return "uint32" + case dsl.Int64: + return "int64" + case dsl.Uint64, dsl.Size: + return "uint64" + case dsl.Float32, dsl.ComplexFloat32: + return "single" + case dsl.Float64, dsl.ComplexFloat64: + return "double" + case dsl.String: + return "string" + case dsl.Date: + return "yardl.Date" + case dsl.Time: + return "yardl.Time" + case dsl.DateTime: + return "yardl.DateTime" + default: + panic(fmt.Sprintf("primitive '%v' not recognized", t)) + } + case *dsl.GenericTypeParameter: + return TypeIdentifierName(t.Name) + case dsl.TypeDefinition: + meta := t.GetDefinitionMeta() + return fmt.Sprintf("%s.%s", NamespaceIdentifierName(meta.Namespace), TypeIdentifierName(meta.Name)) + + case nil: + return "None" + case *dsl.SimpleType: + return self.ToSyntax(t.ResolvedDefinition, contextNamespace) + case *dsl.GeneralizedType: + scalarString := func() string { + if t.Cases.IsSingle() { + return self.ToSyntax(t.Cases[0].Type, contextNamespace) + } + if t.Cases.IsOptional() { + return "yardl.Optional" + } + + return UnionClassName(t) + }() + + switch d := t.Dimensionality.(type) { + case nil, *dsl.Stream, *dsl.Vector, *dsl.Array: + return scalarString + case *dsl.Map: + return "dictionary" + default: + panic(fmt.Sprintf("unexpected type %T", d)) + } + default: + panic(fmt.Sprintf("unexpected type %T", t)) + } +} + +func TypeSyntax(typeOrTypeDefinition dsl.Node, contextNamespace string) string { + return TypeSyntaxWriter.ToSyntax(typeOrTypeDefinition, contextNamespace) +} + +func ComputedFieldIdentifierName(name string) string { + cased := formatting.ToSnakeCase(name) + if !isReservedName[name] { + return cased + } + + return cased + "_" +} + +func TypeIdentifierName(name string) string { + if !isReservedName[name] { + return name + } + + return name + "_" +} + +func PackageDir(name string) string { + return fmt.Sprintf("+%s", formatting.ToSnakeCase(name)) +} + +func NamespaceIdentifierName(namespace string) string { + return formatting.ToSnakeCase(namespace) +} + +func FieldIdentifierName(name string) string { + snakeCased := formatting.ToSnakeCase(name) + if !isReservedName[snakeCased] { + return snakeCased + } + + return snakeCased + "_" +} + +func EnumValueIdentifierName(name string) string { + cased := formatting.ToUpperSnakeCase(name) + if !isReservedName[cased] { + return cased + } + + return cased + "_" +} + +func UnionClassName(gt *dsl.GeneralizedType) (className string) { + if !gt.Cases.IsUnion() { + panic("Not a union") + } + + cases := make([]string, 0, len(gt.Cases)) + for _, typeCase := range gt.Cases { + if typeCase.Type == nil { + continue + } + cases = append(cases, formatting.ToPascalCase(typeCase.Tag)) + } + + return strings.Join(cases, "Or") +} + +func WriteBlockBody(w *formatting.IndentedWriter, f func()) { + defer func() { + w.WriteStringln("end") + }() + w.Indented(f) +} + +func WriteComment(w *formatting.IndentedWriter, comment string) { + comment = strings.TrimSpace(comment) + if comment != "" { + w = formatting.NewIndentedWriter(w, "% ").Indent() + w.WriteStringln(comment) + } +} + +func AbstractWriterName(p *dsl.ProtocolDefinition) string { + return fmt.Sprintf("%sWriterBase", formatting.ToPascalCase(p.Name)) +} + +func AbstractReaderName(p *dsl.ProtocolDefinition) string { + return fmt.Sprintf("%sReaderBase", formatting.ToPascalCase(p.Name)) +} + +func ProtocolWriteMethodName(s *dsl.ProtocolStep) string { + return fmt.Sprintf("write_%s", formatting.ToSnakeCase(s.Name)) +} + +func ProtocolWriteImplMethodName(s *dsl.ProtocolStep) string { + return fmt.Sprintf("write_%s_", formatting.ToSnakeCase(s.Name)) +} + +func ProtocolEndMethodName(s *dsl.ProtocolStep) string { + return fmt.Sprintf("end_%s", formatting.ToSnakeCase(s.Name)) +} + +func ProtocolReadMethodName(s *dsl.ProtocolStep) string { + return fmt.Sprintf("read_%s", formatting.ToSnakeCase(s.Name)) +} + +func ProtocolReadImplMethodName(s *dsl.ProtocolStep) string { + return fmt.Sprintf("read_%s_", formatting.ToSnakeCase(s.Name)) +} + +func ProtocolHasMoreMethodName(s *dsl.ProtocolStep) string { + return fmt.Sprintf("has_%s", formatting.ToSnakeCase(s.Name)) +} + +func ProtocolHasMoreImplMethodName(s *dsl.ProtocolStep) string { + return fmt.Sprintf("has_%s_", formatting.ToSnakeCase(s.Name)) +} + +func WriteGeneratedFileHeader(w *formatting.IndentedWriter) { + WriteComment(w, "This file was generated by the \"yardl\" tool. DO NOT EDIT.") + w.WriteStringln("") +} + +type MatlabFileWriter struct { + PackageDir string + filesWritten []string +} + +func (fw *MatlabFileWriter) WriteFile(name string, writeContents func(w *formatting.IndentedWriter)) error { + b := bytes.Buffer{} + w := formatting.NewIndentedWriter(&b, " ") + WriteGeneratedFileHeader(w) + + writeContents(w) + + filepath := path.Join(fw.PackageDir, fmt.Sprintf("%s.m", name)) + if err := iocommon.WriteFileIfNeeded(filepath, b.Bytes(), 0644); err != nil { + return err + } + fw.filesWritten = append(fw.filesWritten, filepath) + return nil +} + +func (fw *MatlabFileWriter) RemoveStaleFiles() error { + written := make(map[string]bool) + for _, fname := range fw.filesWritten { + written[fname] = true + } + + entries, err := os.ReadDir(fw.PackageDir) + if err != nil { + return err + } + + var stalePaths []string + for _, entry := range entries { + filename := path.Join(fw.PackageDir, entry.Name()) + if !entry.IsDir() && !written[filename] { + stalePaths = append(stalePaths, filename) + } + } + for _, name := range stalePaths { + log.Debug().Msgf("Removing stale file %s", name) + if err := os.Remove(name); err != nil { + return err + } + } + return nil +} diff --git a/tooling/internal/matlab/matlab.go b/tooling/internal/matlab/matlab.go new file mode 100644 index 00000000..63614918 --- /dev/null +++ b/tooling/internal/matlab/matlab.go @@ -0,0 +1,84 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +package matlab + +import ( + "embed" + "os" + "path" + + "github.com/microsoft/yardl/tooling/internal/iocommon" + "github.com/microsoft/yardl/tooling/internal/matlab/binary" + "github.com/microsoft/yardl/tooling/internal/matlab/common" + "github.com/microsoft/yardl/tooling/internal/matlab/mocks" + "github.com/microsoft/yardl/tooling/internal/matlab/protocols" + "github.com/microsoft/yardl/tooling/internal/matlab/types" + "github.com/microsoft/yardl/tooling/pkg/dsl" + "github.com/microsoft/yardl/tooling/pkg/packaging" +) + +//go:embed static_files/* +var staticFiles embed.FS + +func Generate(env *dsl.Environment, options packaging.MatlabCodegenOptions) error { + err := os.MkdirAll(options.OutputDir, 0775) + if err != nil { + return err + } + + staticDir := path.Join(options.OutputDir, common.PackageDir("yardl")) + if err := iocommon.CopyEmbeddedStaticFiles(staticDir, options.InternalSymlinkStaticFiles, staticFiles); err != nil { + return err + } + + for _, ns := range env.Namespaces { + // Write package Types and Protocol definitions + packageDir := path.Join(options.OutputDir, common.PackageDir(ns.Name)) + if err := updatePackage(packageDir, func(fw *common.MatlabFileWriter) error { + if err := types.WriteTypes(fw, ns, env.SymbolTable); err != nil { + return err + } + if ns.IsTopLevel { + if err := protocols.WriteProtocols(fw, ns, env.SymbolTable); err != nil { + return err + } + } + return nil + }); err != nil { + return err + } + + // Write binary serializers + binaryDir := path.Join(packageDir, common.PackageDir("binary")) + if err := updatePackage(binaryDir, func(fw *common.MatlabFileWriter) error { + return binary.WriteBinary(fw, ns) + }); err != nil { + return err + } + + // Write mocks and test support classes + if ns.IsTopLevel && options.InternalGenerateMocks { + mocksDir := path.Join(packageDir, common.PackageDir("testing")) + if err := updatePackage(mocksDir, func(fw *common.MatlabFileWriter) error { + return mocks.WriteMocks(fw, ns) + }); err != nil { + return err + } + } + } + + return nil +} + +// Creates `+package` directory, writes the package implementation, and removes stale files. +func updatePackage(packageDir string, writePackageImpl func(*common.MatlabFileWriter) error) error { + if err := os.MkdirAll(packageDir, 0775); err != nil { + return err + } + fw := &common.MatlabFileWriter{PackageDir: packageDir} + + writePackageImpl(fw) + + return fw.RemoveStaleFiles() +} diff --git a/tooling/internal/matlab/mocks/mocks.go b/tooling/internal/matlab/mocks/mocks.go new file mode 100644 index 00000000..8b579987 --- /dev/null +++ b/tooling/internal/matlab/mocks/mocks.go @@ -0,0 +1,231 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +package mocks + +import ( + "fmt" + + "github.com/microsoft/yardl/tooling/internal/formatting" + "github.com/microsoft/yardl/tooling/internal/matlab/common" + "github.com/microsoft/yardl/tooling/pkg/dsl" +) + +func WriteMocks(fw *common.MatlabFileWriter, ns *dsl.Namespace) error { + for _, p := range ns.Protocols { + if err := writeProtocolMock(fw, p); err != nil { + return err + } + if err := writeProtocolTestWriter(fw, p); err != nil { + return err + } + } + return nil +} + +func writeProtocolMock(fw *common.MatlabFileWriter, p *dsl.ProtocolDefinition) error { + expectedName := func(step *dsl.ProtocolStep) string { + return fmt.Sprintf("expected_%s", formatting.ToSnakeCase(step.Name)) + } + return fw.WriteFile(mockWriterName(p), func(w *formatting.IndentedWriter) { + abstractWriterName := fmt.Sprintf("%s.%s", common.NamespaceIdentifierName(p.Namespace), common.AbstractWriterName(p)) + fmt.Fprintf(w, "classdef %s < matlab.mixin.Copyable & %s\n", mockWriterName(p), abstractWriterName) + common.WriteBlockBody(w, func() { + w.WriteStringln("properties") + common.WriteBlockBody(w, func() { + w.WriteStringln("testCase_") + for _, step := range p.Sequence { + w.WriteStringln(expectedName(step)) + } + }) + w.WriteStringln("") + + w.WriteStringln("methods") + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "function self = %s(testCase)\n", mockWriterName(p)) + common.WriteBlockBody(w, func() { + w.WriteStringln("self.testCase_ = testCase;") + for _, step := range p.Sequence { + if step.IsStream() { + fmt.Fprintf(w, "self.%s = {};\n", expectedName(step)) + } else { + fmt.Fprintf(w, "self.%s = yardl.None;\n", expectedName(step)) + } + } + }) + w.WriteStringln("") + + for _, step := range p.Sequence { + fmt.Fprintf(w, "function expect_%s(self, value)\n", common.ProtocolWriteImplMethodName(step)) + common.WriteBlockBody(w, func() { + if step.IsStream() { + w.WriteStringln("if iscell(value)") + common.WriteBlockBody(w, func() { + w.WriteStringln("for n = 1:numel(value)") + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "self.%s{end+1} = value{n};\n", expectedName(step)) + }) + w.WriteStringln("return;") + }) + + w.WriteStringln("shape = size(value);") + w.WriteStringln("lastDim = ndims(value);") + w.WriteStringln("count = shape(lastDim);") + w.WriteStringln("index = repelem({':'}, lastDim-1);") + w.WriteStringln("for n = 1:count") + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "self.%s{end+1} = value(index{:}, n);\n", expectedName(step)) + }) + } else { + fmt.Fprintf(w, "self.%s = yardl.Optional(value);\n", expectedName(step)) + } + }) + w.WriteStringln("") + } + + w.WriteStringln("function verify(self)") + common.WriteBlockBody(w, func() { + for _, step := range p.Sequence { + diagnostic := fmt.Sprintf("Expected call to %s was not received", common.ProtocolWriteImplMethodName(step)) + if step.IsStream() { + fmt.Fprintf(w, "self.testCase_.verifyTrue(isempty(self.%s), \"%s\");\n", expectedName(step), diagnostic) + } else { + fmt.Fprintf(w, "self.testCase_.verifyEqual(self.%s, yardl.None, \"%s\");\n", expectedName(step), diagnostic) + } + } + }) + }) + w.WriteStringln("") + + w.WriteStringln("methods (Access=protected)") + common.WriteBlockBody(w, func() { + for _, step := range p.Sequence { + fmt.Fprintf(w, "function %s(self, value)\n", common.ProtocolWriteImplMethodName(step)) + common.WriteBlockBody(w, func() { + if step.IsStream() { + w.WriteStringln("assert(iscell(value));") + w.WriteStringln("assert(isscalar(value));") + fmt.Fprintf(w, "self.testCase_.verifyFalse(isempty(self.%s), \"Unexpected call to %s\");\n", expectedName(step), common.ProtocolWriteImplMethodName(step)) + fmt.Fprintf(w, "self.testCase_.verifyEqual(value{1}, self.%s{1}, \"Unexpected argument value for call to %s\");\n", expectedName(step), common.ProtocolWriteImplMethodName(step)) + fmt.Fprintf(w, "self.%s = self.%s(2:end);\n", expectedName(step), expectedName(step)) + } else { + fmt.Fprintf(w, "self.testCase_.verifyTrue(self.%s.has_value(), \"Unexpected call to %s\");\n", expectedName(step), common.ProtocolWriteImplMethodName(step)) + fmt.Fprintf(w, "self.testCase_.verifyEqual(value, self.%s.value, \"Unexpected argument value for call to %s\");\n", expectedName(step), common.ProtocolWriteImplMethodName(step)) + fmt.Fprintf(w, "self.%s = yardl.None;\n", expectedName(step)) + } + }) + w.WriteStringln("") + } + + w.WriteStringln("function close_(self)") + w.WriteStringln("end") + + w.WriteStringln("function end_stream_(self)") + w.WriteStringln("end") + }) + }) + }) +} + +func writeProtocolTestWriter(fw *common.MatlabFileWriter, p *dsl.ProtocolDefinition) error { + return fw.WriteFile(testWriterName(p), func(w *formatting.IndentedWriter) { + abstractWriterName := fmt.Sprintf("%s.%s", common.NamespaceIdentifierName(p.Namespace), common.AbstractWriterName(p)) + fmt.Fprintf(w, "classdef %s < %s\n", testWriterName(p), abstractWriterName) + common.WriteBlockBody(w, func() { + w.WriteStringln("properties (Access = private)") + common.WriteBlockBody(w, func() { + w.WriteStringln("writer_") + w.WriteStringln("create_reader_") + w.WriteStringln("mock_writer_") + w.WriteStringln("close_called_") + w.WriteStringln("filename_") + w.WriteStringln("format_") + }) + w.WriteStringln("") + + w.WriteStringln("methods") + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "function self = %s(testCase, format, create_writer, create_reader)\n", testWriterName(p)) + common.WriteBlockBody(w, func() { + w.WriteStringln("self.filename_ = tempname();") + w.WriteStringln("self.format_ = format;") + w.WriteStringln("self.writer_ = create_writer(self.filename_);") + w.WriteStringln("self.create_reader_ = create_reader;") + mockWriterName := fmt.Sprintf("%s.testing.%s", common.NamespaceIdentifierName(p.Namespace), mockWriterName(p)) + fmt.Fprintf(w, "self.mock_writer_ = %s(testCase);\n", mockWriterName) + w.WriteStringln("self.close_called_ = false;") + }) + w.WriteStringln("") + + w.WriteStringln("function delete(self)") + common.WriteBlockBody(w, func() { + w.WriteStringln("delete(self.filename_);") + w.WriteStringln("if ~self.close_called_") + common.WriteBlockBody(w, func() { + common.WriteComment(w, "ADD_FAILURE() << ...;") + fmt.Fprintf(w, "throw(yardl.RuntimeError(\"Close() must be called on '%s' to verify mocks\"));\n", testWriterName(p)) + }) + }) + + for _, step := range p.Sequence { + if step.IsStream() { + fmt.Fprintf(w, "function %s(self)\n", common.ProtocolEndMethodName(step)) + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "%s@%s(self);\n", common.ProtocolEndMethodName(step), abstractWriterName) + fmt.Fprintf(w, "self.writer_.%s();\n", common.ProtocolEndMethodName(step)) + }) + w.WriteStringln("") + } + } + }) + w.WriteStringln("") + + w.WriteStringln("methods (Access=protected)") + common.WriteBlockBody(w, func() { + for _, step := range p.Sequence { + fmt.Fprintf(w, "function %s(self, value)\n", common.ProtocolWriteImplMethodName(step)) + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "self.writer_.%s(value);\n", common.ProtocolWriteMethodName(step)) + fmt.Fprintf(w, "self.mock_writer_.expect_%s(value);\n", common.ProtocolWriteImplMethodName(step)) + }) + w.WriteStringln("") + } + + w.WriteStringln("function close_(self)") + common.WriteBlockBody(w, func() { + w.WriteStringln("self.close_called_ = true;") + w.WriteStringln("self.writer_.close();") + w.WriteStringln("mock_copy = copy(self.mock_writer_);") + + w.WriteStringln("") + w.WriteStringln("reader = self.create_reader_(self.filename_);") + w.WriteStringln("reader.copy_to(self.mock_writer_);") + w.WriteStringln("reader.close();") + w.WriteStringln("self.mock_writer_.verify();") + w.WriteStringln("self.mock_writer_.close();") + + w.WriteStringln("") + w.WriteStringln("translated = invoke_translator(self.filename_, self.format_, self.format_);") + w.WriteStringln("reader = self.create_reader_(translated);") + w.WriteStringln("reader.copy_to(mock_copy);") + w.WriteStringln("reader.close();") + w.WriteStringln("mock_copy.verify();") + w.WriteStringln("mock_copy.close();") + w.WriteStringln("delete(translated);") + }) + w.WriteStringln("") + + w.WriteStringln("function end_stream_(self)") + common.WriteBlockBody(w, func() {}) + }) + }) + }) +} + +func mockWriterName(p *dsl.ProtocolDefinition) string { + return fmt.Sprintf("Mock%sWriter", formatting.ToPascalCase(p.Name)) +} + +func testWriterName(p *dsl.ProtocolDefinition) string { + return fmt.Sprintf("Test%sWriter", formatting.ToPascalCase(p.Name)) +} diff --git a/tooling/internal/matlab/protocols/protocols.go b/tooling/internal/matlab/protocols/protocols.go new file mode 100644 index 00000000..3844d06d --- /dev/null +++ b/tooling/internal/matlab/protocols/protocols.go @@ -0,0 +1,300 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +package protocols + +import ( + "fmt" + + "github.com/microsoft/yardl/tooling/internal/formatting" + "github.com/microsoft/yardl/tooling/internal/matlab/common" + "github.com/microsoft/yardl/tooling/pkg/dsl" +) + +func WriteProtocols(fw *common.MatlabFileWriter, ns *dsl.Namespace, st dsl.SymbolTable) error { + for _, p := range ns.Protocols { + if err := writeAbstractWriter(fw, p, ns, st); err != nil { + return err + } + if err := writeAbstractReader(fw, p, ns); err != nil { + return err + } + } + + return nil +} + +func writeAbstractWriter(fw *common.MatlabFileWriter, p *dsl.ProtocolDefinition, ns *dsl.Namespace, st dsl.SymbolTable) error { + return fw.WriteFile(common.AbstractWriterName(p), func(w *formatting.IndentedWriter) { + common.WriteComment(w, fmt.Sprintf("Abstract writer for protocol %s", p.Name)) + common.WriteComment(w, p.Comment) + fmt.Fprintf(w, "classdef (Abstract) %s < handle\n", common.AbstractWriterName(p)) + + common.WriteBlockBody(w, func() { + + w.WriteStringln("properties (Access=protected)") + common.WriteBlockBody(w, func() { w.WriteStringln("state_") }) + w.WriteStringln("") + + w.WriteStringln("methods") + common.WriteBlockBody(w, func() { + // Constructor + fmt.Fprintf(w, "function self = %s()\n", common.AbstractWriterName(p)) + common.WriteBlockBody(w, func() { w.WriteStringln("self.state_ = 0;") }) + w.WriteStringln("") + + // Close method + w.WriteStringln("function close(self)") + common.WriteBlockBody(w, func() { + w.WriteStringln("self.close_();") + fmt.Fprintf(w, "if self.state_ ~= %d\n", len(p.Sequence)) + common.WriteBlockBody(w, func() { + w.WriteStringln("expected_method = self.state_to_method_name_(self.state_);") + w.WriteStringln(`throw(yardl.ProtocolError("Protocol writer closed before all steps were called. Expected call to '%s'.", expected_method));`) + }) + }) + w.WriteStringln("") + + // Public write methods + for i, step := range p.Sequence { + common.WriteComment(w, fmt.Sprintf("Ordinal %d", i)) + common.WriteComment(w, step.Comment) + fmt.Fprintf(w, "function %s(self, value)\n", common.ProtocolWriteMethodName(step)) + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "if self.state_ ~= %d\n", i) + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "self.raise_unexpected_state_(%d);\n", i) + }) + w.WriteStringln("") + + fmt.Fprintf(w, "self.%s(value);\n", common.ProtocolWriteImplMethodName(step)) + if !step.IsStream() { + fmt.Fprintf(w, "self.state_ = %d;\n", i+1) + } + }) + + if step.IsStream() { + // End stream method + w.WriteStringln("") + fmt.Fprintf(w, "function %s(self)\n", common.ProtocolEndMethodName(step)) + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "if self.state_ ~= %d\n", i) + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "self.raise_unexpected_state_(%d);\n", i) + }) + w.WriteStringln("") + fmt.Fprintf(w, "self.end_stream_();\n") + fmt.Fprintf(w, "self.state_ = %d;\n", i+1) + }) + } + + if i < len(p.Sequence)-1 { + w.WriteStringln("") + } + } + }) + w.WriteStringln("") + + w.WriteStringln("methods (Static)") + common.WriteBlockBody(w, func() { + w.WriteStringln("function res = schema()") + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "res = string('%s');\n", dsl.GetProtocolSchemaString(p, st)) + }) + }) + w.WriteStringln("") + + // Protected abstract write methods + w.WriteStringln("methods (Abstract, Access=protected)") + common.WriteBlockBody(w, func() { + for _, step := range p.Sequence { + fmt.Fprintf(w, "%s(self, value)\n", common.ProtocolWriteImplMethodName(step)) + } + w.WriteStringln("") + + // end_stream method + w.WriteStringln("end_stream_(self)") + // underlying close method + w.WriteStringln("close_(self)") + }) + w.WriteStringln("") + + // Private methods + w.WriteStringln("methods (Access=private)") + common.WriteBlockBody(w, func() { + // raise_unexpected_state method + w.WriteStringln("function raise_unexpected_state_(self, actual)") + common.WriteBlockBody(w, func() { + w.WriteStringln("expected_method = self.state_to_method_name_(self.state_);") + w.WriteStringln("actual_method = self.state_to_method_name_(actual);") + w.WriteStringln(`throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'", expected_method, actual_method));`) + }) + w.WriteStringln("") + + w.WriteStringln("function name = state_to_method_name_(self, state)") + common.WriteBlockBody(w, func() { + for i, step := range p.Sequence { + fmt.Fprintf(w, "if state == %d\n", i) + w.Indented(func() { + if step.IsStream() { + fmt.Fprintf(w, "name = \"%s or %s\";\n", common.ProtocolWriteMethodName(step), common.ProtocolEndMethodName(step)) + } else { + fmt.Fprintf(w, "name = \"%s\";\n", common.ProtocolWriteMethodName(step)) + } + }) + w.WriteString("else") + } + w.WriteStringln("") + common.WriteBlockBody(w, func() { + w.WriteStringln("name = '';") + }) + }) + }) + }) + }) +} + +func writeAbstractReader(fw *common.MatlabFileWriter, p *dsl.ProtocolDefinition, ns *dsl.Namespace) error { + return fw.WriteFile(common.AbstractReaderName(p), func(w *formatting.IndentedWriter) { + common.WriteComment(w, p.Comment) + fmt.Fprintf(w, "classdef %s < handle\n", common.AbstractReaderName(p)) + + common.WriteBlockBody(w, func() { + + w.WriteStringln("properties (Access=protected)") + common.WriteBlockBody(w, func() { + w.WriteStringln("state_") + }) + w.WriteStringln("") + + w.WriteStringln("methods") + common.WriteBlockBody(w, func() { + // Constructor + fmt.Fprintf(w, "function self = %s()\n", common.AbstractReaderName(p)) + common.WriteBlockBody(w, func() { + w.WriteStringln("self.state_ = 0;") + }) + w.WriteStringln("") + + // Close method + w.WriteStringln("function close(self)") + common.WriteBlockBody(w, func() { + w.WriteStringln("self.close_();") + fmt.Fprintf(w, "if self.state_ ~= %d\n", len(p.Sequence)) + common.WriteBlockBody(w, func() { + w.WriteStringln("expected_method = self.state_to_method_name_(self.state_);") + w.WriteStringln(`throw(yardl.ProtocolError("Protocol reader closed before all data was consumed. Expected call to '%s'.", expected_method));`) + }) + }) + w.WriteStringln("") + + // Public has/read methods + for i, step := range p.Sequence { + common.WriteComment(w, fmt.Sprintf("Ordinal %d", i)) + if step.IsStream() { + fmt.Fprintf(w, "function more = %s(self)\n", common.ProtocolHasMoreMethodName(step)) + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "if self.state_ ~= %d\n", i) + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "self.raise_unexpected_state_(%d);\n", i) + }) + w.WriteStringln("") + + fmt.Fprintf(w, "more = self.%s();\n", common.ProtocolHasMoreImplMethodName(step)) + w.WriteStringln("if ~more") + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "self.state_ = %d;\n", i+1) + }) + }) + w.WriteStringln("") + } + common.WriteComment(w, step.Comment) + fmt.Fprintf(w, "function value = %s(self)\n", common.ProtocolReadMethodName(step)) + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "if self.state_ ~= %d\n", i) + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "self.raise_unexpected_state_(%d);\n", i) + }) + w.WriteStringln("") + + fmt.Fprintf(w, "value = self.%s();\n", common.ProtocolReadImplMethodName(step)) + if !step.IsStream() { + fmt.Fprintf(w, "self.state_ = %d;\n", i+1) + } + }) + w.WriteStringln("") + } + + // copy_to method + fmt.Fprintf(w, "function copy_to(self, writer)\n") + common.WriteBlockBody(w, func() { + for _, step := range p.Sequence { + if step.IsStream() { + fmt.Fprintf(w, "while self.%s()\n", common.ProtocolHasMoreMethodName(step)) + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "item = self.%s();\n", common.ProtocolReadMethodName(step)) + fmt.Fprintf(w, "writer.%s({item});\n", common.ProtocolWriteMethodName(step)) + }) + fmt.Fprintf(w, "writer.%s();\n", common.ProtocolEndMethodName(step)) + } else { + fmt.Fprintf(w, "writer.%s(self.%s());\n", common.ProtocolWriteMethodName(step), common.ProtocolReadMethodName(step)) + } + } + }) + }) + w.WriteStringln("") + + w.WriteStringln("methods (Static)") + common.WriteBlockBody(w, func() { + w.WriteStringln("function res = schema()") + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "res = %s.%s.schema;\n", common.NamespaceIdentifierName(ns.Name), common.AbstractWriterName(p)) + }) + }) + w.WriteStringln("") + + // Protected abstract methods + w.WriteStringln("methods (Abstract, Access=protected)") + common.WriteBlockBody(w, func() { + for _, step := range p.Sequence { + if step.IsStream() { + fmt.Fprintf(w, "%s(self)\n", common.ProtocolHasMoreImplMethodName(step)) + } + fmt.Fprintf(w, "%s(self)\n", common.ProtocolReadImplMethodName(step)) + } + + w.WriteStringln("") + w.WriteStringln("close_(self)") + }) + w.WriteStringln("") + + w.WriteStringln("methods (Access=private)") + common.WriteBlockBody(w, func() { + // raise_unexpected_state method + w.WriteStringln("function raise_unexpected_state_(self, actual)") + common.WriteBlockBody(w, func() { + w.WriteStringln("actual_method = self.state_to_method_name_(actual);") + w.WriteStringln("expected_method = self.state_to_method_name_(self.state_);") + w.WriteStringln(`throw(yardl.ProtocolError("Expected call to '%s' but received call to '%s'.", expected_method, actual_method));`) + }) + w.WriteStringln("") + + // state_to_method_name method + w.WriteStringln("function name = state_to_method_name_(self, state)") + common.WriteBlockBody(w, func() { + for i, step := range p.Sequence { + fmt.Fprintf(w, "if state == %d\n", i) + w.Indented(func() { + fmt.Fprintf(w, "name = \"%s\";\n", common.ProtocolReadMethodName(step)) + }) + w.WriteString("else") + } + w.WriteStringln("") + common.WriteBlockBody(w, func() { + w.WriteStringln("name = \"\";") + }) + }) + }) + }) + }) +} diff --git a/tooling/internal/matlab/static_files/+binary/BinaryProtocolReader.m b/tooling/internal/matlab/static_files/+binary/BinaryProtocolReader.m new file mode 100755 index 00000000..11802692 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/BinaryProtocolReader.m @@ -0,0 +1,40 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef BinaryProtocolReader < handle + + properties (Access=protected) + stream_ + end + + methods + function self = BinaryProtocolReader(infile, expected_schema) + self.stream_ = yardl.binary.CodedInputStream(infile); + magic_bytes = self.stream_.read_bytes(length(yardl.binary.MAGIC_BYTES)); + if magic_bytes ~= yardl.binary.MAGIC_BYTES + throw(yardl.ProtocolError("Invalid magic bytes")); + end + + version = read_fixed_int32(self.stream_); + if version ~= yardl.binary.CURRENT_BINARY_FORMAT_VERSION + throw(yardl.ProtocolError("Invalid binary format version")); + end + + s = yardl.binary.StringSerializer(); + schema = s.read(self.stream_); + if ~isempty(expected_schema) & schema ~= expected_schema + throw(yardl.ProtocolError("Invalid schema")); + end + end + end + + methods (Access=protected) + function close_(self) + self.stream_.close(); + end + end +end + +function res = read_fixed_int32(stream) + res = typecast(stream.read_bytes(4), "int32"); +end diff --git a/tooling/internal/matlab/static_files/+binary/BinaryProtocolWriter.m b/tooling/internal/matlab/static_files/+binary/BinaryProtocolWriter.m new file mode 100755 index 00000000..4a5378a4 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/BinaryProtocolWriter.m @@ -0,0 +1,37 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef BinaryProtocolWriter < handle + + properties (Access=protected) + stream_ + end + + methods + function self = BinaryProtocolWriter(outfile, schema) + self.stream_ = yardl.binary.CodedOutputStream(outfile); + self.stream_.write_bytes(yardl.binary.MAGIC_BYTES); + write_fixed_int32(self.stream_, yardl.binary.CURRENT_BINARY_FORMAT_VERSION); + s = yardl.binary.StringSerializer(); + s.write(self.stream_, schema); + end + end + + methods (Access=protected) + function end_stream_(self) + self.stream_.write_byte(uint8(0)); + end + + function close_(self) + self.stream_.close(); + end + end +end + +function write_fixed_int32(stream, value) + arguments + stream (1,1) yardl.binary.CodedOutputStream + value (1,1) {mustBeA(value, "int32")} + end + stream.write_bytes(typecast(value, "uint8")); +end diff --git a/tooling/internal/matlab/static_files/+binary/BoolSerializer.m b/tooling/internal/matlab/static_files/+binary/BoolSerializer.m new file mode 100755 index 00000000..83112731 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/BoolSerializer.m @@ -0,0 +1,28 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef BoolSerializer < yardl.binary.TypeSerializer + methods (Static) + function write(outstream, value) + arguments + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) {mustBeInRange(value, 0, 1)} + end + byte = cast(value, "uint8"); + outstream.write_bytes(byte); + end + + function res = read(instream) + byte = instream.read_byte(); + res = cast(byte, "logical"); + end + + function c = get_class() + c = "logical"; + end + + function trivial = is_trivially_serializable() + trivial = true; + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/CURRENT_BINARY_FORMAT_VERSION.m b/tooling/internal/matlab/static_files/+binary/CURRENT_BINARY_FORMAT_VERSION.m new file mode 100755 index 00000000..2fcacad5 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/CURRENT_BINARY_FORMAT_VERSION.m @@ -0,0 +1,6 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +function res = CURRENT_BINARY_FORMAT_VERSION + res = int32(1); +end diff --git a/tooling/internal/matlab/static_files/+binary/CodedInputStream.m b/tooling/internal/matlab/static_files/+binary/CodedInputStream.m new file mode 100755 index 00000000..34e03ca6 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/CodedInputStream.m @@ -0,0 +1,74 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef CodedInputStream < handle + + properties (Access=private) + fid_ + owns_stream_ + end + + methods + function self = CodedInputStream(infile) + if isa(infile, "string") || isa(infile, "char") + [fileId, errMsg] = fopen(infile, "r"); + if fileId < 0 + throw(yardl.RuntimeError(errMsg)); + end + self.fid_ = fileId; + self.owns_stream_ = true; + else + self.fid_ = infile; + self.owns_stream_ = false; + end + end + + function close(self) + if self.owns_stream_ && self.fid_ > 2 + fclose(self.fid_); + self.fid_ = -1; + end + end + + function res = read_bytes(self, count) + res = fread(self.fid_, count, "*uint8"); + if iscolumn(res) + res = transpose(res); + end + end + + function res = read_byte(self) + res = fread(self.fid_, 1, "*uint8"); + end + + function res = read_values_directly(self, shape, precision) + res = fread(self.fid_, shape, "*"+precision); + if iscolumn(res) + res = transpose(res); + end + end + + function res = read_unsigned_varint(self) + res = uint64(0); + shift = uint8(0); + + while true + byte = self.read_byte(); + res = bitor(res, bitshift(uint64(bitand(byte, 0x7F)), shift)); + if byte < 0x80 + return + end + shift = shift + 7; + end + end + + function res = zigzag_decode(~, value) + value = uint64(value); + res = bitxor(int64(bitshift(value, -1)), -int64(bitand(value, 1))); + end + + function res = read_signed_varint(self) + res = self.zigzag_decode(self.read_unsigned_varint()); + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/CodedOutputStream.m b/tooling/internal/matlab/static_files/+binary/CodedOutputStream.m new file mode 100755 index 00000000..c2aedf38 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/CodedOutputStream.m @@ -0,0 +1,84 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef CodedOutputStream < handle + + properties (Access=private) + fid_ + owns_stream_ + end + + methods + function self = CodedOutputStream(outfile) + if isa(outfile, "string") || isa(outfile, "char") + [fileId, errMsg] = fopen(outfile, "W"); + if fileId < 0 + throw(yardl.RuntimeError(errMsg)); + end + self.fid_ = fileId; + self.owns_stream_ = true; + else + self.fid_ = outfile; + self.owns_stream_ = false; + end + end + + function close(self) + if self.owns_stream_ && self.fid_ > 2 + fclose(self.fid_); + self.fid_ = -1; + end + end + + function write_bytes(self, bytes) + arguments + self + bytes (1,:) {mustBeA(bytes, "uint8")} + end + fwrite(self.fid_, bytes, "uint8"); + end + + function write_byte(self, value) + arguments + self + value (1,1) {mustBeA(value, "uint8")} + end + fwrite(self.fid_, value, "uint8"); + end + + function write_values_directly(self, values, precision) + fwrite(self.fid_, values, precision); + end + + function write_unsigned_varint(self, value) + arguments + self + value (1,1) {mustBeInteger,mustBeNonnegative} + end + + int_val = uint64(value); + while true + if int_val < 0x80 + self.write_byte(uint8(int_val)); + return + end + + self.write_byte(uint8(bitor(bitand(int_val, uint64(0x7F)), uint64(0x80)))); + int_val = bitshift(int_val, -7); + end + end + + function res = zigzag_encode(~, value) + int_val = int64(value); + res = bitxor(bitshift(int_val, 1), bitshift(int_val, -63)); + end + + function write_signed_varint(self, value) + arguments + self + value (1,1) {mustBeInteger} + end + self.write_unsigned_varint(self.zigzag_encode(value)); + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/Complexfloat32Serializer.m b/tooling/internal/matlab/static_files/+binary/Complexfloat32Serializer.m new file mode 100755 index 00000000..041edb84 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/Complexfloat32Serializer.m @@ -0,0 +1,49 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef Complexfloat32Serializer < yardl.binary.TypeSerializer + methods (Static) + function write(outstream, value) + arguments + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) single + end + real_bytes = typecast(single(real(value)), "uint8"); + imag_bytes = typecast(single(imag(value)), "uint8"); + outstream.write_bytes(real_bytes); + outstream.write_bytes(imag_bytes); + end + + function res = read(instream) + real_bytes = instream.read_bytes(4); + imag_bytes = instream.read_bytes(4); + res = complex(typecast(real_bytes, "single"), typecast(imag_bytes, "single")); + end + + function c = get_class() + c = "single"; + end + + function trivial = is_trivially_serializable() + trivial = true; + end + end + + methods + function write_trivially(self, stream, values) + rp = real(values); + ip = imag(values); + parts(1, :) = rp(:); + parts(2, :) = ip(:); + stream.write_values_directly(parts, self.get_class()); + end + + function res = read_trivially(self, stream, shape) + assert(ndims(shape) == 2); + partshape = [2*shape(1) shape(2)]; + res = stream.read_values_directly(partshape, self.get_class()); + res = reshape(res, [2 shape]); + res = squeeze(complex(res(1, :, :), res(2, :, :))); + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/Complexfloat64Serializer.m b/tooling/internal/matlab/static_files/+binary/Complexfloat64Serializer.m new file mode 100755 index 00000000..5f6fba6f --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/Complexfloat64Serializer.m @@ -0,0 +1,49 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef Complexfloat64Serializer < yardl.binary.TypeSerializer + methods (Static) + function write(outstream, value) + arguments + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) double + end + real_bytes = typecast(double(real(value)), "uint8"); + imag_bytes = typecast(double(imag(value)), "uint8"); + outstream.write_bytes(real_bytes); + outstream.write_bytes(imag_bytes); + end + + function res = read(instream) + real_bytes = instream.read_bytes(8); + imag_bytes = instream.read_bytes(8); + res = complex(typecast(real_bytes, "double"), typecast(imag_bytes, "double")); + end + + function c = get_class() + c = "double"; + end + + function trivial = is_trivially_serializable() + trivial = true; + end + end + + methods + function write_trivially(self, stream, values) + rp = real(values); + ip = imag(values); + parts(1, :) = rp(:); + parts(2, :) = ip(:); + stream.write_values_directly(parts, self.get_class()); + end + + function res = read_trivially(self, stream, shape) + assert(ndims(shape) == 2); + partshape = [2*shape(1) shape(2)]; + res = stream.read_values_directly(partshape, self.get_class()); + res = reshape(res, [2 shape]); + res = squeeze(complex(res(1, :, :), res(2, :, :))); + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/DateSerializer.m b/tooling/internal/matlab/static_files/+binary/DateSerializer.m new file mode 100755 index 00000000..20f78c3e --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/DateSerializer.m @@ -0,0 +1,26 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef DateSerializer < yardl.binary.TypeSerializer + methods (Static) + function write(outstream, value) + if isa(value, "datetime") + value = yardl.Date.from_datetime(value).value; + elseif isa(value, "yardl.Date") + value = value.value; + else + throw(yardl.TypeError("Expected datetime or yardl.Date, got %s", class(value))); + end + outstream.write_signed_varint(value); + end + + function res = read(instream) + value = instream.read_signed_varint(); + res = yardl.Date(value); + end + + function c = get_class() + c = "yardl.Date"; + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/DatetimeSerializer.m b/tooling/internal/matlab/static_files/+binary/DatetimeSerializer.m new file mode 100755 index 00000000..07f813bc --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/DatetimeSerializer.m @@ -0,0 +1,26 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef DatetimeSerializer < yardl.binary.TypeSerializer + methods (Static) + function write(outstream, value) + if isa(value, "datetime") + value = yardl.DateTime.from_datetime(value).value; + elseif isa(value, "yardl.DateTime") + value = value.value; + else + throw(yardl.TypeError("Expected datetime or yardl.DateTime, got %s", class(value))); + end + outstream.write_signed_varint(value); + end + + function res = read(instream) + value = instream.read_signed_varint(); + res = yardl.DateTime(value); + end + + function c = get_class() + c = "yardl.DateTime"; + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/DynamicNDArraySerializer.m b/tooling/internal/matlab/static_files/+binary/DynamicNDArraySerializer.m new file mode 100644 index 00000000..4f7f8c51 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/DynamicNDArraySerializer.m @@ -0,0 +1,47 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef DynamicNDArraySerializer < yardl.binary.NDArraySerializerBase + + methods + function self = DynamicNDArraySerializer(item_serializer) + self@yardl.binary.NDArraySerializerBase(item_serializer); + end + + function write(self, outstream, values) + item_shape = self.item_serializer_.get_shape(); + shape = size(values); + if isempty(item_shape) + % values is an array of variable-length vectors or arrays + values = values(:); + elseif isscalar(item_shape) + % values is an array of scalars + values = values(:); + else + % values is an array of fixed-length vectors or arrays + item_shape = item_shape(item_shape > 1); + outer_shape = shape(length(item_shape) + 1:end); + values = reshape(values, [item_shape prod(outer_shape)]); + shape = outer_shape; + end + + outstream.write_unsigned_varint(length(shape)); + flipped_shape = flip(shape); + for dim = 1:length(flipped_shape) + outstream.write_unsigned_varint(flipped_shape(dim)); + end + + self.write_data_(outstream, values); + end + + function value = read(self, instream) + ndims = instream.read_unsigned_varint(); + flipped_shape = zeros(1, ndims); + for dim = 1:ndims + flipped_shape(dim) = instream.read_unsigned_varint(); + end + shape = flip(flipped_shape); + value = self.read_data_(instream, shape); + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/EnumSerializer.m b/tooling/internal/matlab/static_files/+binary/EnumSerializer.m new file mode 100644 index 00000000..307eeb9b --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/EnumSerializer.m @@ -0,0 +1,43 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef EnumSerializer < yardl.binary.TypeSerializer + properties + classname_; + constructor_; + integer_serializer_; + end + + methods + function self = EnumSerializer(classname, classconstructor, integer_serializer) + self.classname_ = classname; + self.constructor_ = classconstructor; + self.integer_serializer_ = integer_serializer; + end + + function write(self, outstream, value) + self.integer_serializer_.write(outstream, value); + end + + function res = read(self, instream) + int_value = self.integer_serializer_.read(instream); + res = self.constructor_(int_value); + end + + function c = get_class(self) + c = self.classname_; + end + + function trivial = is_trivially_serializable(self) + trivial = self.integer_serializer_.is_trivially_serializable(); + end + + function write_trivially(self, outstream, values) + self.integer_serializer_.write_trivially(outstream, values); + end + + function res = read_trivially(self, instream, shape) + res = self.integer_serializer_.read_trivially(instream, shape); + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/FixedNDArraySerializer.m b/tooling/internal/matlab/static_files/+binary/FixedNDArraySerializer.m new file mode 100644 index 00000000..58871f4f --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/FixedNDArraySerializer.m @@ -0,0 +1,72 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef FixedNDArraySerializer < yardl.binary.NDArraySerializerBase + + properties + shape_ + end + + methods + function self = FixedNDArraySerializer(item_serializer, shape) + self@yardl.binary.NDArraySerializerBase(item_serializer); + self.shape_ = shape; + end + + function write(self, outstream, values) + if numel(values) == prod(self.shape_) + % This is an NDArray of scalars + self.write_data_(outstream, values(:)); + return; + end + + sz = size(values); + if length(sz) < length(self.shape_) + expected = sprintf("%d ", self.shape_); + actual = sprintf("%d ", sz); + throw(yardl.ValueError("Expected shape [%s], got [%s]", expected, actual)); + end + + fixedSize = sz(end-length(self.shape_)+1:end); + if fixedSize ~= self.shape_ + expected = sprintf("%d ", self.shape_); + actual = sprintf("%d ", fixedSize); + throw(yardl.ValueError("Expected shape [%s], got [%s]", expected, actual)); + end + + inner_shape = sz(1:end-length(self.shape_)); + values = reshape(values, [inner_shape prod(self.shape_)]); + + self.write_data_(outstream, values); + end + + function value = read(self, instream) + value = self.read_data_(instream, self.shape_); + end + + function s = get_shape(self) + item_shape = self.item_serializer_.get_shape(); + if isempty(item_shape) + s = self.shape_; + else + s = [item_shape self.shape_]; + end + + if length(s) > 2 + s = s(s>1); + end + end + + function trivial = is_trivially_serializable(self) + trivial = self.item_serializer_.is_trivially_serializable(); + end + + function write_trivially(self, outstream, values) + self.item_serializer_.write_trivially(outstream, values); + end + + function res = read_trivially(self, instream, shape) + res = self.item_serializer_.read_trivially(instream, shape); + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/FixedVectorSerializer.m b/tooling/internal/matlab/static_files/+binary/FixedVectorSerializer.m new file mode 100644 index 00000000..35dafc2b --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/FixedVectorSerializer.m @@ -0,0 +1,51 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef FixedVectorSerializer < yardl.binary.VectorSerializerBase + properties + length_; + end + + methods (Access=protected) + function handle_write_count_(self, ~, count) + if count ~= self.length_ + throw(yardl.ValueError("Expected an array of length %d, got %d", self.length_, count)); + end + end + + function count = get_read_count_(self, ~) + count = self.length_; + end + end + + methods + function self = FixedVectorSerializer(item_serializer, length) + self@yardl.binary.VectorSerializerBase(item_serializer); + self.length_ = length; + end + + function s = get_shape(self) + item_shape = self.item_serializer_.get_shape(); + if isempty(item_shape) + s = [1, self.length_]; + elseif isscalar(item_shape) + s = [item_shape self.length_]; + else + s = [item_shape self.length_]; + s = s(s>1); + end + end + + function trivial = is_trivially_serializable(self) + trivial = self.item_serializer_.is_trivially_serializable(); + end + + function write_trivially(self, outstream, values) + self.item_serializer_.write_trivially(outstream, values); + end + + function res = read_trivially(self, instream, shape) + res = self.item_serializer_.read_trivially(instream, shape); + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/Float32Serializer.m b/tooling/internal/matlab/static_files/+binary/Float32Serializer.m new file mode 100755 index 00000000..021e6230 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/Float32Serializer.m @@ -0,0 +1,29 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef Float32Serializer < yardl.binary.TypeSerializer + methods (Static) + function write(outstream, value) + arguments + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) single + end + + bytes = typecast(single(value), "uint8"); + outstream.write_bytes(bytes); + end + + function res = read(instream) + bytes = instream.read_bytes(4); + res = typecast(bytes, "single"); + end + + function c = get_class() + c = "single"; + end + + function trivial = is_trivially_serializable() + trivial = true; + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/Float64Serializer.m b/tooling/internal/matlab/static_files/+binary/Float64Serializer.m new file mode 100755 index 00000000..4f583677 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/Float64Serializer.m @@ -0,0 +1,28 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef Float64Serializer < yardl.binary.TypeSerializer + methods (Static) + function write(outstream, value) + arguments + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) double + end + bytes = typecast(double(value), "uint8"); + outstream.write_bytes(bytes); + end + + function res = read(instream) + bytes = instream.read_bytes(8); + res = typecast(bytes, "double"); + end + + function c = get_class() + c = "double"; + end + + function trivial = is_trivially_serializable() + trivial = true; + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/Int16Serializer.m b/tooling/internal/matlab/static_files/+binary/Int16Serializer.m new file mode 100755 index 00000000..8f140d8d --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/Int16Serializer.m @@ -0,0 +1,22 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef Int16Serializer < yardl.binary.TypeSerializer + methods (Static) + function write(outstream, value) + arguments + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) {mustBeInRange(value, -32768, 32767)} + end + outstream.write_signed_varint(value); + end + + function res = read(instream) + res = int16(instream.read_signed_varint()); + end + + function c = get_class() + c = "int16"; + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/Int32Serializer.m b/tooling/internal/matlab/static_files/+binary/Int32Serializer.m new file mode 100755 index 00000000..20fc3d3c --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/Int32Serializer.m @@ -0,0 +1,22 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef Int32Serializer < yardl.binary.TypeSerializer + methods (Static) + function write(outstream, value) + arguments + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) {mustBeInRange(value, -2147483648, 2147483647)} + end + outstream.write_signed_varint(value); + end + + function res = read(instream) + res = int32(instream.read_signed_varint()); + end + + function c = get_class() + c = "int32"; + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/Int64Serializer.m b/tooling/internal/matlab/static_files/+binary/Int64Serializer.m new file mode 100755 index 00000000..2176a933 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/Int64Serializer.m @@ -0,0 +1,22 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef Int64Serializer < yardl.binary.TypeSerializer + methods (Static) + function write(outstream, value) + arguments + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) {mustBeInRange(value, -9223372036854775808, 9223372036854775807)} + end + outstream.write_signed_varint(value); + end + + function res = read(instream) + res = int64(instream.read_signed_varint()); + end + + function c = get_class() + c = "int64"; + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/Int8Serializer.m b/tooling/internal/matlab/static_files/+binary/Int8Serializer.m new file mode 100755 index 00000000..ecf037c9 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/Int8Serializer.m @@ -0,0 +1,27 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef Int8Serializer < yardl.binary.TypeSerializer + methods (Static) + function write(outstream, value) + arguments + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) {mustBeInRange(value, -128, 127)} + end + byte = typecast(int8(value), "uint8"); + outstream.write_byte(byte); + end + + function res = read(instream) + res = typecast(instream.read_byte(), "int8"); + end + + function c = get_class() + c = "int8"; + end + + function trivial = is_trivially_serializable() + trivial = true; + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/MAGIC_BYTES.m b/tooling/internal/matlab/static_files/+binary/MAGIC_BYTES.m new file mode 100755 index 00000000..43919757 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/MAGIC_BYTES.m @@ -0,0 +1,6 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +function res = MAGIC_BYTES + res = unicode2native('yardl'); +end diff --git a/tooling/internal/matlab/static_files/+binary/MapSerializer.m b/tooling/internal/matlab/static_files/+binary/MapSerializer.m new file mode 100644 index 00000000..73ad04d4 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/MapSerializer.m @@ -0,0 +1,51 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef MapSerializer < yardl.binary.TypeSerializer + properties + key_serializer_; + value_serializer_; + end + + methods + function self = MapSerializer(key_serializer, value_serializer) + self.key_serializer_ = key_serializer; + self.value_serializer_ = value_serializer; + end + + function write(self, outstream, value) + arguments + self (1,1) + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) dictionary + end + + count = numEntries(value); + outstream.write_unsigned_varint(count); + if count == 0 + return + end + + ks = keys(value); + vs = values(value); + for i = 1:count + self.key_serializer_.write(outstream, ks(i)); + self.value_serializer_.write(outstream, vs(i)); + end + end + + function res = read(self, instream) + count = instream.read_unsigned_varint(); + res = dictionary(); + for i = 1:count + k = self.key_serializer_.read(instream); + v = self.value_serializer_.read(instream); + res(k) = v; + end + end + + function c = get_class(~) + c = "dictionary"; + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/NDArraySerializer.m b/tooling/internal/matlab/static_files/+binary/NDArraySerializer.m new file mode 100644 index 00000000..cde64343 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/NDArraySerializer.m @@ -0,0 +1,51 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef NDArraySerializer < yardl.binary.NDArraySerializerBase + + properties + ndims_ + end + + methods + function self = NDArraySerializer(item_serializer, ndims) + self@yardl.binary.NDArraySerializerBase(item_serializer); + self.ndims_ = ndims; + end + + function write(self, outstream, values) + sz = size(values); + if ndims(values) < self.ndims_ + sz = [sz ones(1, self.ndims_-ndims(values))]; + end + + flipped_shape = flip(sz); + for dim = 1:self.ndims_ + len = flipped_shape(dim); + outstream.write_unsigned_varint(len); + end + + if length(sz) == self.ndims_ + % This is an NDArray of scalars + self.write_data_(outstream, values(:)); + return + end + + % This is an NDArray of vectors/arrays + inner_shape = sz(1:end-self.ndims_); + outer_shape = sz(end-self.ndims_+1:end); + values = reshape(values, [inner_shape prod(outer_shape)]); + + self.write_data_(outstream, values); + end + + function value = read(self, instream) + flipped_shape = zeros(1, self.ndims_); + for dim = 1:self.ndims_ + flipped_shape(dim) = instream.read_unsigned_varint(); + end + shape = flip(flipped_shape); + value = self.read_data_(instream, shape); + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/NDArraySerializerBase.m b/tooling/internal/matlab/static_files/+binary/NDArraySerializerBase.m new file mode 100644 index 00000000..12cf7750 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/NDArraySerializerBase.m @@ -0,0 +1,106 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef NDArraySerializerBase < yardl.binary.TypeSerializer + + properties + item_serializer_ + end + + methods (Abstract) + write(self, outstream, values) + read(self, instream) + end + + methods (Access=protected) + function self = NDArraySerializerBase(item_serializer) + self.item_serializer_ = item_serializer; + end + + function write_data_(self, outstream, values) + % values is an array of shape [A, B, ..., N], where + % N is the "flattened" dimension of the NDArray, and + % A, B, ... are the dimensions of the inner items. + + if ~iscell(values) && self.item_serializer_.is_trivially_serializable() + self.item_serializer_.write_trivially(outstream, values); + return; + end + + sz = size(values); + + if ndims(values) > 2 + count = sz(end); + inner_shape = sz(1:end-1); + r = reshape(values, [], count); + for i = 1:count + val = reshape(r(:, i), inner_shape); + self.item_serializer_.write(outstream, val); + end + elseif isrow(values) || iscolumn(values) + count = prod(sz); + if iscell(values) + for i = 1:count + self.item_serializer_.write(outstream, values{i}); + end + else + for i = 1:count + self.item_serializer_.write(outstream, values(i)); + end + end + else + count = sz(end); + for i = 1:count + self.item_serializer_.write(outstream, values(:, i)); + end + end + end + + function res = read_data_(self, instream, shape) + flat_length = prod(shape); + + item_shape = self.item_serializer_.get_shape(); + + if isempty(item_shape) + res = cell(shape); + for i = 1:flat_length + res{i} = self.item_serializer_.read(instream); + end + return + end + + if self.item_serializer_.is_trivially_serializable() + res = self.item_serializer_.read_trivially(instream, [prod(item_shape), flat_length]); + else + res = yardl.allocate(self.get_class(), [prod(item_shape), flat_length]); + for i = 1:flat_length + item = self.item_serializer_.read(instream); + res(:, i) = item(:); + end + end + + % Tricky reshaping to remove unnecessary singleton dimensions in + % subarrays, arrays of fixed vectors, etc. + item_shape = item_shape(item_shape > 1); + if isempty(item_shape) && isscalar(shape) + item_shape = 1; + end + newshape = [item_shape shape]; + res = reshape(res, newshape); + + if iscolumn(res) + res = transpose(res); + end + end + end + + methods + function c = get_class(self) + c = self.item_serializer_.get_class(); + end + + function s = get_shape(~) + s = []; + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/NoneSerializer.m b/tooling/internal/matlab/static_files/+binary/NoneSerializer.m new file mode 100755 index 00000000..99865941 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/NoneSerializer.m @@ -0,0 +1,17 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef NoneSerializer < yardl.binary.TypeSerializer + methods (Static) + function write(~, ~) + end + + function res = read(~) + res = yardl.None; + end + + function c = get_class() + c = "yardl.Optional"; + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/OptionalSerializer.m b/tooling/internal/matlab/static_files/+binary/OptionalSerializer.m new file mode 100644 index 00000000..a4f7960d --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/OptionalSerializer.m @@ -0,0 +1,43 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef OptionalSerializer < yardl.binary.TypeSerializer + properties + item_serializer_; + end + + methods + function self = OptionalSerializer(item_serializer) + self.item_serializer_ = item_serializer; + end + + function write(self, outstream, value) + if isa(value, "yardl.Optional") + if value.has_value() + outstream.write_byte(uint8(1)); + self.item_serializer_.write(outstream, value.value()); + else + outstream.write_byte(uint8(0)); + return + end + else + outstream.write_byte(uint8(1)); + self.item_serializer_.write(outstream, value); + end + end + + function res = read(self, instream) + % Returns either yardl.None or the inner optional value + has_value = instream.read_byte(); + if has_value == 0 + res = yardl.None; + else + res = self.item_serializer_.read(instream); + end + end + + function c = get_class(~) + c = "yardl.Optional"; + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/RecordSerializer.m b/tooling/internal/matlab/static_files/+binary/RecordSerializer.m new file mode 100755 index 00000000..d6a2fb59 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/RecordSerializer.m @@ -0,0 +1,39 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef RecordSerializer < yardl.binary.TypeSerializer + + properties + field_serializers + classname + end + + methods + function self = RecordSerializer(classname, field_serializers) + self.classname = classname; + self.field_serializers = field_serializers; + end + + function c = get_class(self) + c = self.classname; + end + end + + methods (Access=protected) + function write_(self, outstream, varargin) + for i = 1:nargin-2 + fs = self.field_serializers{i}; + field_value = varargin{i}; + fs.write(outstream, field_value); + end + end + + function res = read_(self, instream) + res = cell(size(self.field_serializers)); + for i = 1:length(self.field_serializers) + fs = self.field_serializers{i}; + res{i} = fs.read(instream); + end + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/SizeSerializer.m b/tooling/internal/matlab/static_files/+binary/SizeSerializer.m new file mode 100755 index 00000000..a613e233 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/SizeSerializer.m @@ -0,0 +1,5 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef SizeSerializer < yardl.binary.Uint64Serializer +end diff --git a/tooling/internal/matlab/static_files/+binary/StreamSerializer.m b/tooling/internal/matlab/static_files/+binary/StreamSerializer.m new file mode 100644 index 00000000..233bf2b6 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/StreamSerializer.m @@ -0,0 +1,79 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef StreamSerializer < yardl.binary.TypeSerializer + properties + item_serializer_; + items_remaining_; + end + + methods + function self = StreamSerializer(item_serializer) + self.item_serializer_ = item_serializer; + self.items_remaining_ = 0; + end + + function write(self, outstream, values) + if isempty(values) + return; + end + + if iscolumn(values) + values = transpose(values); + end + s = size(values); + count = s(end); + outstream.write_unsigned_varint(count); + + if iscell(values) + if ~isvector(s) + throw(yardl.ValueError("cell array must be a vector")); + end + for i = 1:count + self.item_serializer_.write(outstream, values{i}); + end + else + if ndims(values) > 2 + r = reshape(values, [], count); + inner_shape = s(1:end-1); + for i = 1:count + val = reshape(r(:, i), inner_shape); + self.item_serializer_.write(outstream, val); + end + else + for i = 1:count + self.item_serializer_.write(outstream, transpose(values(:, i))); + end + end + end + end + + function res = hasnext(self, instream) + if self.items_remaining_ <= 0 + self.items_remaining_ = instream.read_unsigned_varint(); + if self.items_remaining_ <= 0 + res = false; + return; + end + end + res = true; + end + + function res = read(self, instream) + if self.items_remaining_ <= 0 + throw(yardl.RuntimeError("Stream has been exhausted")); + end + + res = self.item_serializer_.read(instream); + self.items_remaining_ = self.items_remaining_ - 1; + end + + function c = get_class(self) + c = self.item_serializer_.get_class(); + end + + function s = get_shape(~) + s = []; + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/StringSerializer.m b/tooling/internal/matlab/static_files/+binary/StringSerializer.m new file mode 100755 index 00000000..d96ff6c1 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/StringSerializer.m @@ -0,0 +1,26 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef StringSerializer < yardl.binary.TypeSerializer + methods (Static) + function write(outstream, value) + arguments + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) {mustBeTextScalar} + end + bytes = unicode2native(value, "utf-8"); + outstream.write_unsigned_varint(length(bytes)); + outstream.write_bytes(bytes); + end + + function res = read(instream) + len = instream.read_unsigned_varint(); + bytes = instream.read_bytes(len); + res = convertCharsToStrings(native2unicode(bytes, "utf-8")); + end + + function c = get_class() + c = "string"; + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/TimeSerializer.m b/tooling/internal/matlab/static_files/+binary/TimeSerializer.m new file mode 100755 index 00000000..e612d9fb --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/TimeSerializer.m @@ -0,0 +1,27 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef TimeSerializer < yardl.binary.TypeSerializer + methods (Static) + function write(outstream, value) + if isa(value, "datetime") + value = yardl.Time.from_datetime(value).value; + elseif isa(value, "yardl.Time") + value = value.value; + else + throw(yardl.TypeError("Expected datetime or yardl.Time, got %s", class(value))); + end + + outstream.write_signed_varint(value); + end + + function res = read(instream) + value = instream.read_signed_varint(); + res = yardl.Time(value); + end + + function c = get_class() + c = "yardl.Time"; + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/TypeSerializer.m b/tooling/internal/matlab/static_files/+binary/TypeSerializer.m new file mode 100755 index 00000000..0cbb6f15 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/TypeSerializer.m @@ -0,0 +1,36 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef TypeSerializer < handle + methods (Static, Abstract) + write(self, stream, value) + res = read(self, stream) + c = get_class(self) + end + + methods (Static) + function s = get_shape() + s = 1; + end + + function trivial = is_trivially_serializable() + trivial = false; + end + end + + methods + function write_trivially(self, stream, values) + if ~self.is_trivially_serializable() + throw(yardl.TypeError("Not implemented for non-trivially-serializable types")); + end + stream.write_values_directly(values, self.get_class()); + end + + function res = read_trivially(self, stream, shape) + if ~self.is_trivially_serializable() + throw(yardl.TypeError("Not implemented for non-trivially-serializable types")); + end + res = stream.read_values_directly(shape, self.get_class()); + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/Uint16Serializer.m b/tooling/internal/matlab/static_files/+binary/Uint16Serializer.m new file mode 100755 index 00000000..5e33f7df --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/Uint16Serializer.m @@ -0,0 +1,22 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef Uint16Serializer < yardl.binary.TypeSerializer + methods (Static) + function write(outstream, value) + arguments + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) {mustBeInRange(value, 0, 65535)} + end + outstream.write_unsigned_varint(value); + end + + function res = read(instream) + res = uint16(instream.read_unsigned_varint()); + end + + function c = get_class() + c = "uint16"; + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/Uint32Serializer.m b/tooling/internal/matlab/static_files/+binary/Uint32Serializer.m new file mode 100755 index 00000000..5bf4c543 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/Uint32Serializer.m @@ -0,0 +1,22 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef Uint32Serializer < yardl.binary.TypeSerializer + methods (Static) + function write(outstream, value) + arguments + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) {mustBeInRange(value, 0, 4294967295)} + end + outstream.write_unsigned_varint(value); + end + + function res = read(instream) + res = uint32(instream.read_unsigned_varint()); + end + + function c = get_class() + c = "uint32"; + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/Uint64Serializer.m b/tooling/internal/matlab/static_files/+binary/Uint64Serializer.m new file mode 100755 index 00000000..3d51f625 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/Uint64Serializer.m @@ -0,0 +1,22 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef Uint64Serializer < yardl.binary.TypeSerializer + methods (Static) + function write(outstream, value) + arguments + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) {mustBeInRange(value, 0, 18446744073709551615)} + end + outstream.write_unsigned_varint(value); + end + + function res = read(instream) + res = uint64(instream.read_unsigned_varint()); + end + + function c = get_class() + c = "uint64"; + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/Uint8Serializer.m b/tooling/internal/matlab/static_files/+binary/Uint8Serializer.m new file mode 100755 index 00000000..28c873b2 --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/Uint8Serializer.m @@ -0,0 +1,26 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef Uint8Serializer < yardl.binary.TypeSerializer + methods (Static) + function write(outstream, value) + arguments + outstream (1,1) yardl.binary.CodedOutputStream + value (1,1) {mustBeInRange(value, 0, 255)} + end + outstream.write_byte(uint8(value)); + end + + function res = read(instream) + res = instream.read_byte(); + end + + function c = get_class() + c = "uint8"; + end + + function trivial = is_trivially_serializable() + trivial = true; + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/UnionSerializer.m b/tooling/internal/matlab/static_files/+binary/UnionSerializer.m new file mode 100755 index 00000000..ba935c9b --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/UnionSerializer.m @@ -0,0 +1,81 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef UnionSerializer < handle + + properties (Access=protected) + classname_ + case_serializers_ + case_factories_ + offset_ + end + + methods + function self = UnionSerializer(union_class, case_serializers, case_factories) + self.classname_ = union_class; + self.case_serializers_ = case_serializers; + self.case_factories_ = case_factories; + + if isa(case_serializers{1}, "yardl.binary.NoneSerializer") + self.offset_ = 1; + else + self.offset_ = 0; + end + end + + function write(self, outstream, value) + if isa(value, "yardl.Optional") + if ~isa(self.case_serializers_{1}, "yardl.binary.NoneSerializer") + throw(yardl.TypeError("Optional is not valid for this union type")) + end + + if value.has_value() + value = value.value; + else + outstream.write_byte(uint8(0)); + return; + end + end + + if ~isa(value, self.classname_) + throw(yardl.TypeError("Expected union value of type %s, got %s", self.classname_, class(value))) + end + + tag_index = uint8(value.index + self.offset_); + outstream.write_byte(tag_index-1); + + serializer = self.case_serializers_{tag_index}; + serializer.write(outstream, value.value); + end + + function res = read(self, instream) + case_index = instream.read_byte() + 1; + + if case_index == 1 && self.offset_ == 1 + res = yardl.None; + return + end + + serializer = self.case_serializers_{case_index}; + value = serializer.read(instream); + + factory = self.case_factories_{case_index}; + res = factory(value); + end + + function c = get_class(self) + if isa(self.case_serializers_{1}, "yardl.binary.NoneSerializer") + c = "yardl.Optional"; + else + c = self.classname_; + end + end + + end + + methods (Static) + function s = get_shape() + s = 1; + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/VectorSerializer.m b/tooling/internal/matlab/static_files/+binary/VectorSerializer.m new file mode 100644 index 00000000..04982eff --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/VectorSerializer.m @@ -0,0 +1,25 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef VectorSerializer < yardl.binary.VectorSerializerBase + + methods (Access=protected) + function handle_write_count_(~, outstream, count) + outstream.write_unsigned_varint(count); + end + + function count = get_read_count_(~, instream) + count = instream.read_unsigned_varint(); + end + end + + methods + function self = VectorSerializer(item_serializer) + self@yardl.binary.VectorSerializerBase(item_serializer); + end + + function s = get_shape(~) + s = []; + end + end +end diff --git a/tooling/internal/matlab/static_files/+binary/VectorSerializerBase.m b/tooling/internal/matlab/static_files/+binary/VectorSerializerBase.m new file mode 100644 index 00000000..dbe1694b --- /dev/null +++ b/tooling/internal/matlab/static_files/+binary/VectorSerializerBase.m @@ -0,0 +1,95 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef VectorSerializerBase < yardl.binary.TypeSerializer + properties + item_serializer_; + end + + methods (Abstract, Access=protected) + handle_write_count_(self, outstream, values) + get_read_count_(self, instream) + end + + methods (Access=protected) + function self = VectorSerializerBase(item_serializer) + self.item_serializer_ = item_serializer; + end + end + + methods + function write(self, outstream, values) + if iscolumn(values) + values = transpose(values); + end + s = size(values); + count = s(end); + + self.handle_write_count_(outstream, count); + + if iscell(values) + % values is a cell array, so must be a vector of shape [1, COUNT] + if ~isvector(s) + throw(yardl.ValueError("cell array must be a vector")); + end + for i = 1:count + self.item_serializer_.write(outstream, values{i}); + end + else + % values is an array, so must have shape [A, B, ..., COUNT] + if self.item_serializer_.is_trivially_serializable() + self.item_serializer_.write_trivially(outstream, values); + return + end + + if ndims(values) > 2 + r = reshape(values, [], count); + for i = 1:count + val = reshape(r(:, i), s(1:end-1)); + self.item_serializer_.write(outstream, val); + end + else + for i = 1:count + self.item_serializer_.write(outstream, transpose(values(:, i))); + end + end + end + end + + function res = read(self, instream) + count = self.get_read_count_(instream); + if count == 0 + res = yardl.allocate(self.get_class(), 0); + return; + end + + item_shape = self.item_serializer_.get_shape(); + if isempty(item_shape) + res = cell(1, count); + for i = 1:count + res{i} = self.item_serializer_.read(instream); + end + return + end + + if self.item_serializer_.is_trivially_serializable() + res = self.item_serializer_.read_trivially(instream, [prod(item_shape), count]); + else + res = yardl.allocate(self.get_class(), [prod(item_shape), count]); + for i = 1:count + item = self.item_serializer_.read(instream); + res(:, i) = item(:); + end + end + + res = squeeze(reshape(res, [item_shape, count])); + if iscolumn(res) + res = transpose(res); + end + end + + function c = get_class(self) + c = self.item_serializer_.get_class(); + end + end +end diff --git a/tooling/internal/matlab/static_files/Date.m b/tooling/internal/matlab/static_files/Date.m new file mode 100644 index 00000000..ed28ebd9 --- /dev/null +++ b/tooling/internal/matlab/static_files/Date.m @@ -0,0 +1,66 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef Date < handle + + properties (SetAccess=private) + days_since_epoch + end + + methods + function self = Date(days_since_epoch) + if nargin > 0 + self.days_since_epoch = days_since_epoch; + else + self.days_since_epoch = 0; + end + end + + function value = value(self) + value = self.days_since_epoch; + end + + function dt = to_datetime(self) + dt = datetime(0, 'ConvertFrom', 'epochtime') + days(self.days_since_epoch); + end + + function eq = eq(self, other) + if isa(other, 'datetime') + other = yardl.Date.from_datetime(other); + end + + eq = isa(other, 'yardl.Date') && ... + all([self.value] == [other.value]); + end + + function ne = new(self, other) + ne = ~self.eq(other); + end + end + + methods (Static) + function d = from_datetime(value) + dur = value - datetime(0, 'ConvertFrom', 'epochtime'); + d = yardl.Date(days(dur)); + end + + function d = from_components(y, m, d) + d = yardl.Date.from_datetime(datetime(y, m, d)); + end + + function z = zeros(varargin) + elem = yardl.Date(0); + if nargin == 0 + z = elem; + return + end + + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + +end diff --git a/tooling/internal/matlab/static_files/DateTime.m b/tooling/internal/matlab/static_files/DateTime.m new file mode 100644 index 00000000..5a5ba903 --- /dev/null +++ b/tooling/internal/matlab/static_files/DateTime.m @@ -0,0 +1,77 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef DateTime < handle + % A basic datetime with nanosecond precision, always in UTC. + + properties (SetAccess=private) + nanoseconds_since_epoch + end + + methods + function self = DateTime(nanoseconds_since_epoch) + if nargin > 0 + self.nanoseconds_since_epoch = nanoseconds_since_epoch; + else + self.nanoseconds_since_epoch = 0; + end + end + + function value = value(self) + value = self.nanoseconds_since_epoch; + end + + function dt = to_datetime(self) + dt = datetime(self.nanoseconds_since_epoch, 'ConvertFrom', 'epochtime', 'TicksPerSecond', 1e9); + end + + function eq = eq(self, other) + if isa(other, 'datetime') + other = yardl.DateTime.from_datetime(other); + end + + eq = isa(other, 'yardl.DateTime') && ... + all([self.value] == [other.value]); + end + + function ne = new(self, other) + ne = ~self.eq(other); + end + end + + methods (Static) + function dt = from_datetime(value) + value.TimeZone = 'UTC'; + nanoseconds_since_epoch = convertTo(value, 'epochtime', 'TicksPerSecond', 1e9); + dt = yardl.DateTime(nanoseconds_since_epoch); + end + + function dt = from_components(year, month, day, hour, minute, second, nanosecond) + if ~(nanosecond >= 0 && nanosecond < 999999999) + throw(yardl.ValueError("nanosecond must be in 0..1e9")); + end + mdt = datetime(year, month, day, hour, minute, second, 'TimeZone', 'UTC'); + seconds_since_epoch = convertTo(mdt, 'epochtime'); + dt = yardl.DateTime(seconds_since_epoch * 1e9 + nanosecond); + end + + function dt = now(~) + dt = yardl.DateTime.from_datetime(datetime('now')); + end + + function z = zeros(varargin) + elem = yardl.DateTime(0); + if nargin == 0 + z = elem; + return + end + + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + +end diff --git a/tooling/internal/matlab/static_files/Exception.m b/tooling/internal/matlab/static_files/Exception.m new file mode 100755 index 00000000..131fd049 --- /dev/null +++ b/tooling/internal/matlab/static_files/Exception.m @@ -0,0 +1,6 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +function err = Exception(id, varargin) + err = MException(id, varargin{:}); +end diff --git a/tooling/internal/matlab/static_files/None.m b/tooling/internal/matlab/static_files/None.m new file mode 100644 index 00000000..728123da --- /dev/null +++ b/tooling/internal/matlab/static_files/None.m @@ -0,0 +1,6 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +function n = None() + n = yardl.Optional(); +end diff --git a/tooling/internal/matlab/static_files/Optional.m b/tooling/internal/matlab/static_files/Optional.m new file mode 100644 index 00000000..574bd797 --- /dev/null +++ b/tooling/internal/matlab/static_files/Optional.m @@ -0,0 +1,83 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef Optional < handle + properties (SetAccess=protected) + has_value + end + + properties (Access=protected) + value_ + end + + methods + function self = Optional(varargin) + if nargin > 0 + self.value_ = varargin{1}; + self.has_value = true; + else + self.has_value = false; + end + end + + function v = value(self) + if ~self.has_value + throw(yardl.ValueError("Optional type does not have a value")); + end + v = self.value_; + end + + function eq = eq(a, b) + if isa(a, 'yardl.Optional') + if isa(b, 'yardl.Optional') + if all([a.has_value]) && all([b.has_value]) + eq = isequal([a.value_], [b.value_]); + else + eq = [a.has_value] == [b.has_value]; + end + else + if all([a.has_value]) + eq = isequal(b, [a.value_]); + else + eq = false; + end + end + else + % b is the Optional + if all([b.has_value]) + eq = isequal(a, [b.value_]); + else + eq = false; + end + end + end + + function ne = ne(a, b) + ne = ~eq(a, b); + end + + function isequal = isequal(a, varargin) + isequal = all(eq(a, [varargin{:}])); + end + + function isequaln = isequaln(a, varargin) + isequaln = isequal(a, [varargin{:}]); + end + end + + methods (Static) + function z = zeros(varargin) + elem = yardl.None; + if nargin == 0 + z = elem; + return + end + + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end +end diff --git a/tooling/internal/matlab/static_files/ProtocolError.m b/tooling/internal/matlab/static_files/ProtocolError.m new file mode 100644 index 00000000..eac33ad3 --- /dev/null +++ b/tooling/internal/matlab/static_files/ProtocolError.m @@ -0,0 +1,6 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +function err = ProtocolError(varargin) + err = yardl.Exception("yardl:ProtocolError", varargin{:}); +end diff --git a/tooling/internal/matlab/static_files/RuntimeError.m b/tooling/internal/matlab/static_files/RuntimeError.m new file mode 100644 index 00000000..d2a2d612 --- /dev/null +++ b/tooling/internal/matlab/static_files/RuntimeError.m @@ -0,0 +1,6 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +function err = RuntimeError(varargin) + err = yardl.Exception("yardl:RuntimeError", varargin{:}); +end diff --git a/tooling/internal/matlab/static_files/Time.m b/tooling/internal/matlab/static_files/Time.m new file mode 100644 index 00000000..e00dea4d --- /dev/null +++ b/tooling/internal/matlab/static_files/Time.m @@ -0,0 +1,86 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef Time < handle + % A basic time of day with nanosecond precision. It is not timezone-aware and is + % meant to represent a wall clock time. + + properties (SetAccess=private) + nanoseconds_since_midnight + end + + methods + function self = Time(nanoseconds_since_midnight) + if nargin > 0 + if nanoseconds_since_midnight < 0 || nanoseconds_since_midnight >= 24*60*60*1e9 + throw(yardl.ValuError("Time must be between 00:00:00 and 23:59:59.999999999")); + end + self.nanoseconds_since_midnight = nanoseconds_since_midnight; + else + self.nanoseconds_since_midnight = 0; + end + end + + function value = value(self) + value = self.nanoseconds_since_midnight; + end + + function dt = to_datetime(self) + dt = datetime(self.nanoseconds_since_midnight, 'ConvertFrom', 'epochtime', 'Epoch', datetime('today'), 'TicksPerSecond', 1e9); + end + + function eq = eq(self, other) + if isa(other, 'datetime') + other = yardl.Time.from_datetime(other); + end + + eq = isa(other, 'yardl.Time') && ... + all([self.value] == [other.value]); + end + + function ne = new(self, other) + ne = ~self.eq(other); + end + end + + methods (Static) + function t = from_datetime(value) + nanoseconds_since_midnight = convertTo(value, 'epochtime', ... + 'Epoch', datetime(value.Year, value.Month, value.Day, 'TimeZone', value.TimeZone), ... + 'TicksPerSecond', 1e9); + t = yardl.Time(nanoseconds_since_midnight); + end + + function t = from_components(hour, minute, second, nanosecond) + if ~(hour >= 0 && hour <= 23) + throw(yardl.ValueError("hour must be between 0 and 23")); + end + if ~(minute >= 0 && minute <= 59) + throw(yardl.ValueError("minute must be between 0 and 59")); + end + if ~(second >= 0 && second <= 59) + throw(yardl.ValueError("second must be between 0 and 59")); + end + if ~(nanosecond >= 0 && nanosecond <= 999999999) + throw(yardl.ValueError("nanosecond must be between 0 and 999999999")); + end + + t = yardl.Time(hour * 60*60*1e9 + minute * 60*1e9 + second * 1e9 + nanosecond); + end + + function z = zeros(varargin) + elem = yardl.Time(0); + if nargin == 0 + z = elem; + return + end + + sz = [varargin{:}]; + if isscalar(sz) + sz = [sz, sz]; + end + z = reshape(repelem(elem, prod(sz)), sz); + end + end + +end diff --git a/tooling/internal/matlab/static_files/TypeError.m b/tooling/internal/matlab/static_files/TypeError.m new file mode 100644 index 00000000..d37b4d6f --- /dev/null +++ b/tooling/internal/matlab/static_files/TypeError.m @@ -0,0 +1,6 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +function err = TypeError(varargin) + err = yardl.Exception("yardl:TypeError", varargin{:}); +end diff --git a/tooling/internal/matlab/static_files/Union.m b/tooling/internal/matlab/static_files/Union.m new file mode 100644 index 00000000..60b2750a --- /dev/null +++ b/tooling/internal/matlab/static_files/Union.m @@ -0,0 +1,37 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +classdef Union < handle & matlab.mixin.CustomDisplay + properties (Access=protected) + index_ + end + + properties (SetAccess=protected) + value + end + + methods + function self = Union(index, value) + self.index_ = index; + self.value = value; + end + + function i = index(self) + i = self.index_; + end + end + + methods (Abstract) + t = tag(self) + end + + methods (Access=protected) + function displayScalarObject(obj) + className = matlab.mixin.CustomDisplay.getClassNameForHeader(obj); + header = sprintf('%s.%s\n', className, obj.tag()); + disp(header) + propgroup = getPropertyGroups(obj); + matlab.mixin.CustomDisplay.displayPropertyGroups(obj,propgroup) + end + end +end diff --git a/tooling/internal/matlab/static_files/ValueError.m b/tooling/internal/matlab/static_files/ValueError.m new file mode 100644 index 00000000..3c0bd3f2 --- /dev/null +++ b/tooling/internal/matlab/static_files/ValueError.m @@ -0,0 +1,6 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +function err = ValueError(varargin) + err = yardl.Exception("yardl:ValueError", varargin{:}); +end diff --git a/tooling/internal/matlab/static_files/allocate.m b/tooling/internal/matlab/static_files/allocate.m new file mode 100644 index 00000000..f99f87fb --- /dev/null +++ b/tooling/internal/matlab/static_files/allocate.m @@ -0,0 +1,11 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +function res = allocate(classname, varargin) + % Wrapper around zeros, used to preallocate arrays of yardl objects + if classname == "string" + res = strings(varargin{:}); + else + res = zeros(varargin{:}, classname); + end +end diff --git a/tooling/internal/matlab/static_files/dimension_count.m b/tooling/internal/matlab/static_files/dimension_count.m new file mode 100644 index 00000000..21567677 --- /dev/null +++ b/tooling/internal/matlab/static_files/dimension_count.m @@ -0,0 +1,9 @@ +% Copyright (c) Microsoft Corporation. +% Licensed under the MIT License. + +function c = dimension_count(arr) + % Alternative to Matlab's `ndims` function + % Collapses dimensions of size 1 (making it behave like numpy.array.ndim) + s = size(arr); + c = length(s(s > 1)); +end diff --git a/tooling/internal/matlab/types/types.go b/tooling/internal/matlab/types/types.go new file mode 100644 index 00000000..3a8a7a63 --- /dev/null +++ b/tooling/internal/matlab/types/types.go @@ -0,0 +1,1099 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +package types + +import ( + "fmt" + "slices" + "strconv" + "strings" + + "github.com/microsoft/yardl/tooling/internal/formatting" + "github.com/microsoft/yardl/tooling/internal/matlab/common" + "github.com/microsoft/yardl/tooling/pkg/dsl" +) + +func WriteTypes(fw *common.MatlabFileWriter, ns *dsl.Namespace, st dsl.SymbolTable) error { + unionGenerated := make(map[string]bool) + + for _, td := range ns.TypeDefinitions { + if err := writeUnionClasses(fw, td, unionGenerated); err != nil { + return err + } + } + + for _, td := range ns.TypeDefinitions { + var err error + switch td := td.(type) { + case *dsl.NamedType: + if !unionGenerated[td.Name] { + err = writeNamedType(fw, td) + } + case *dsl.EnumDefinition: + err = writeEnum(fw, td, nil) + case *dsl.RecordDefinition: + err = writeRecord(fw, td, st) + default: + panic(fmt.Sprintf("unsupported type definition: %T", td)) + } + if err != nil { + return err + } + } + + for _, p := range ns.Protocols { + if err := writeUnionClasses(fw, p, unionGenerated); err != nil { + return err + } + } + + return nil +} + +func writeUnionClasses(fw *common.MatlabFileWriter, td dsl.TypeDefinition, unionGenerated map[string]bool) error { + var writeError error + dsl.Visit(td, func(self dsl.Visitor, node dsl.Node) { + switch node := node.(type) { + case *dsl.GeneralizedType: + if node.Cases.IsUnion() { + unionClassName := common.UnionClassName(node) + if !unionGenerated[unionClassName] { + if _, isNamedType := td.(*dsl.NamedType); isNamedType { + // This is a named type defining a union, so we will use the named type's name instead + unionClassName = td.GetDefinitionMeta().Name + } + writeError = fw.WriteFile(unionClassName, func(w *formatting.IndentedWriter) { + writeUnionClass(w, unionClassName, node, td.GetDefinitionMeta().Namespace) + }) + if writeError != nil { + return + } + unionGenerated[unionClassName] = true + } + } + } + self.VisitChildren(node) + }) + + return writeError +} + +func writeUnionClass(w *formatting.IndentedWriter, className string, generalizedType *dsl.GeneralizedType, contextNamespace string) error { + qualifiedClassName := fmt.Sprintf("%s.%s", common.NamespaceIdentifierName(contextNamespace), className) + fmt.Fprintf(w, "classdef %s < yardl.Union\n", className) + common.WriteBlockBody(w, func() { + w.WriteStringln("methods (Static)") + common.WriteBlockBody(w, func() { + index := 1 + for _, tc := range generalizedType.Cases { + if tc.Type == nil { + continue + } + + fmt.Fprintf(w, "function res = %s(value)\n", formatting.ToPascalCase(tc.Tag)) + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "res = %s(%d, value);\n", qualifiedClassName, index) + }) + index += 1 + w.WriteStringln("") + } + + writeZerosStaticMethod(w, qualifiedClassName, []string{"0", "yardl.None"}) + }) + w.WriteStringln("") + + w.WriteStringln("methods") + common.WriteBlockBody(w, func() { + index := 1 + var tags []string + for _, tc := range generalizedType.Cases { + if tc.Type == nil { + continue + } + tag := formatting.ToPascalCase(tc.Tag) + tags = append(tags, fmt.Sprintf(`"%s"`, tag)) + fmt.Fprintf(w, "function res = is%s(self)\n", tag) + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "res = self.index == %d;\n", index) + }) + index += 1 + w.WriteStringln("") + } + + w.WriteStringln("function eq = eq(self, other)") + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "eq = isa(other, \"%s\") && isequal(self.index, other.index) && isequal(self.value, other.value);\n", qualifiedClassName) + }) + w.WriteStringln("") + w.WriteStringln("function ne = ne(self, other)") + common.WriteBlockBody(w, func() { + w.WriteStringln("ne = ~self.eq(other);") + }) + w.WriteStringln("") + w.WriteStringln("function t = tag(self)") + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "tags_ = [%s];\n", strings.Join(tags, ", ")) + w.WriteStringln("t = tags_(self.index_);") + }) + }) + + }) + + return nil +} + +func writeNamedType(fw *common.MatlabFileWriter, td *dsl.NamedType) error { + return fw.WriteFile(common.TypeIdentifierName(td.Name), func(w *formatting.IndentedWriter) { + ut := dsl.GetUnderlyingType(td.Type) + // If the underlying type is a RecordDefinition, PrimitiveString, Optional, + // Vector, Array, or Map - we will generate a "function" alias + if st, ok := ut.(*dsl.SimpleType); ok { + if _, ok := st.ResolvedDefinition.(*dsl.RecordDefinition); ok { + fmt.Fprintf(w, "function c = %s(varargin)\n", common.TypeIdentifierName(td.Name)) + common.WriteBlockBody(w, func() { + common.WriteComment(w, td.Comment) + fmt.Fprintf(w, "c = %s(varargin{:});\n", common.TypeSyntax(td.Type, td.Namespace)) + }) + return + } else if pd, ok := st.ResolvedDefinition.(dsl.PrimitiveDefinition); ok { + if pd == dsl.PrimitiveString { + fmt.Fprintf(w, "function s = %s(varargin)\n", common.TypeIdentifierName(td.Name)) + common.WriteBlockBody(w, func() { + common.WriteComment(w, td.Comment) + fmt.Fprintf(w, "s = %s(varargin{:});\n", common.TypeSyntax(td.Type, td.Namespace)) + }) + return + } + } + } else if gt, ok := ut.(*dsl.GeneralizedType); ok { + if gt.Cases.IsOptional() { + innerType := gt.Cases[1].Type + fmt.Fprintf(w, "function o = %s(value)\n", common.TypeIdentifierName(td.Name)) + common.WriteBlockBody(w, func() { + common.WriteComment(w, td.Comment) + if !dsl.TypeContainsGenericTypeParameter(innerType) { + w.WriteStringln("arguments") + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "value %s\n", common.TypeSyntax(innerType, td.Namespace)) + }) + } + fmt.Fprintf(w, "o = %s(value);\n", common.TypeSyntax(td.Type, td.Namespace)) + }) + return + } + + switch gt.Dimensionality.(type) { + case *dsl.Vector, *dsl.Array: + scalar := gt.ToScalar() + fmt.Fprintf(w, "function a = %s(array)\n", common.TypeIdentifierName(td.Name)) + common.WriteBlockBody(w, func() { + common.WriteComment(w, td.Comment) + if !dsl.TypeContainsGenericTypeParameter(scalar) { + w.WriteStringln("arguments") + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "array %s\n", common.TypeSyntax(scalar, td.Namespace)) + }) + } + w.WriteStringln("a = array;") + }) + return + case *dsl.Map: + fmt.Fprintf(w, "function m = %s(varargin)\n", common.TypeIdentifierName(td.Name)) + common.WriteBlockBody(w, func() { + common.WriteComment(w, td.Comment) + fmt.Fprintf(w, "m = %s(varargin{:});\n", common.TypeSyntax(td.Type, td.Namespace)) + }) + return + } + } + + // Otherwise, it's a subclass of the underlying type + fmt.Fprintf(w, "classdef %s < %s\n", common.TypeIdentifierName(td.Name), common.TypeSyntax(td.Type, td.Namespace)) + common.WriteBlockBody(w, func() { + common.WriteComment(w, td.Comment) + }) + }) +} + +func writeEnum(fw *common.MatlabFileWriter, enum *dsl.EnumDefinition, namedType *dsl.NamedType) error { + enumName := common.TypeIdentifierName(enum.Name) + if namedType != nil { + enumName = common.TypeIdentifierName(namedType.Name) + } + return fw.WriteFile(enumName, func(w *formatting.IndentedWriter) { + var base string + if enum.BaseType == nil { + base = "uint64" + } else { + base = common.TypeSyntax(enum.BaseType, enum.Namespace) + } + + fmt.Fprintf(w, "classdef %s < %s\n", enumName, base) + common.WriteBlockBody(w, func() { + common.WriteComment(w, enum.Comment) + w.WriteStringln("methods (Static)") + common.WriteBlockBody(w, func() { + for _, value := range enum.Values { + common.WriteComment(w, value.Comment) + fmt.Fprintf(w, "function v = %s\n", common.EnumValueIdentifierName(value.Symbol)) + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "v = %s(%d);\n", common.TypeSyntax(enum, enum.Namespace), &value.IntegerValue) + }) + } + w.WriteStringln("") + writeZerosStaticMethod(w, common.TypeSyntax(enum, enum.Namespace), []string{"0"}) + }) + + if enum.IsFlags { + // Additional methods for flag checks + w.WriteStringln("") + w.WriteStringln("methods") + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "function self = %s(varargin)\n", enumName) + common.WriteBlockBody(w, func() { + w.WriteStringln("if nargin == 0") + w.Indented(func() { + w.WriteStringln("value = 0;") + }) + w.WriteStringln("elseif nargin == 1") + w.Indented(func() { + w.WriteStringln("value = varargin{1};") + }) + w.WriteStringln("else") + common.WriteBlockBody(w, func() { + w.WriteStringln("value = 0;") + w.WriteStringln("for i = 1:nargin") + common.WriteBlockBody(w, func() { + w.WriteStringln("value = bitor(value, varargin{i});") + }) + }) + fmt.Fprintf(w, "self@%s(value);\n", base) + }) + w.WriteStringln("") + w.WriteStringln("function res = has_flags(self, flag)") + common.WriteBlockBody(w, func() { + w.WriteStringln("res = bitand(self, flag) == flag;") + }) + w.WriteStringln("") + w.WriteStringln("function res = with_flags(self, flag)") + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "res = %s(bitor(self, flag));\n", common.TypeSyntax(enum, enum.Namespace)) + }) + w.WriteStringln("") + w.WriteStringln("function res = without_flags(self, flag)") + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "res = %s(bitand(self, bitcmp(flag)));\n", common.TypeSyntax(enum, enum.Namespace)) + }) + }) + } + }) + }) +} + +func writeRecord(fw *common.MatlabFileWriter, rec *dsl.RecordDefinition, st dsl.SymbolTable) error { + recordName := common.TypeIdentifierName(rec.Name) + return fw.WriteFile(recordName, func(w *formatting.IndentedWriter) { + fmt.Fprintf(w, "classdef %s < handle\n", recordName) + common.WriteBlockBody(w, func() { + common.WriteComment(w, rec.Comment) + + w.WriteStringln("properties") + var fieldNames []string + requiresArgsToConstruct := false + common.WriteBlockBody(w, func() { + for _, field := range rec.Fields { + common.WriteComment(w, field.Comment) + fieldName := common.FieldIdentifierName(field.Name) + fieldNames = append(fieldNames, fieldName) + w.WriteStringln(fieldName) + _, defaultExpressionKind := typeDefault(field.Type, rec.Namespace, "", st) + switch defaultExpressionKind { + case defaultValueKindNone: + requiresArgsToConstruct = true + } + } + }) + w.WriteStringln("") + + w.WriteStringln("methods") + common.WriteBlockBody(w, func() { + + fmt.Fprintf(w, "function self = %s(kwargs)\n", recordName) + common.WriteBlockBody(w, func() { + w.WriteStringln("arguments") + common.WriteBlockBody(w, func() { + for _, field := range rec.Fields { + fieldName := common.FieldIdentifierName(field.Name) + defaultExpression, defaultExpressionKind := typeDefault(field.Type, rec.Namespace, "", st) + switch defaultExpressionKind { + case defaultValueKindNone: + fmt.Fprintf(w, "kwargs.%s;\n", fieldName) + case defaultValueKindImmutable, defaultValueKindMutable: + fmt.Fprintf(w, "kwargs.%s = %s;\n", fieldName, defaultExpression) + } + } + }) + for _, field := range rec.Fields { + fieldName := common.FieldIdentifierName(field.Name) + _, defaultExpressionKind := typeDefault(field.Type, rec.Namespace, "", st) + switch defaultExpressionKind { + case defaultValueKindNone: + fmt.Fprintf(w, "if ~isfield(kwargs, \"%s\")\n", fieldName) + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "throw(yardl.TypeError(\"Missing required keyword argument '%s'\"))\n", fieldName) + }) + } + fmt.Fprintf(w, "self.%s = kwargs.%s;\n", fieldName, fieldName) + } + }) + w.WriteStringln("") + + // Computed Fields + if len(rec.ComputedFields) > 0 { + for _, computedField := range rec.ComputedFields { + fieldName := common.ComputedFieldIdentifierName(computedField.Name) + + fmt.Fprintf(w, "function res = %s(self)\n", fieldName) + common.WriteBlockBody(w, func() { + common.WriteComment(w, computedField.Comment) + writeComputedFieldExpression(w, computedField.Expression, rec.Namespace) + }) + w.WriteStringln("") + } + w.WriteStringln("") + } + + // eq method + w.WriteStringln("function res = eq(self, other)") + common.WriteBlockBody(w, func() { + w.WriteStringln("res = ...") + w.Indented(func() { + fmt.Fprintf(w, "isa(other, \"%s\")", common.TypeSyntax(rec, rec.Namespace)) + for _, field := range rec.Fields { + w.WriteStringln(" && ...") + fieldIdentifier := common.FieldIdentifierName(field.Name) + fmt.Fprintf(w, "isequal(%s, %s)", "self."+fieldIdentifier, "other."+fieldIdentifier) + } + w.WriteStringln(";") + }) + }) + w.WriteStringln("") + + // neq method + w.WriteStringln("function res = ne(self, other)") + common.WriteBlockBody(w, func() { + w.WriteStringln("res = ~self.eq(other);") + }) + }) + w.WriteStringln("") + + if !requiresArgsToConstruct { + w.WriteStringln("methods (Static)") + common.WriteBlockBody(w, func() { + writeZerosStaticMethod(w, common.TypeSyntax(rec, rec.Namespace), []string{}) + }) + } + }) + }) +} + +func writeZerosStaticMethod(w *formatting.IndentedWriter, typeSyntax string, defaultArgs []string) { + // zeros method, only if can be constructed without arguments + w.WriteStringln("function z = zeros(varargin)") + common.WriteBlockBody(w, func() { + fmt.Fprintf(w, "elem = %s(%s);\n", typeSyntax, strings.Join(defaultArgs, ", ")) + w.WriteStringln("if nargin == 0") + common.WriteBlockBody(w, func() { + w.WriteStringln("z = elem;") + w.WriteStringln("return;") + }) + + w.WriteStringln("sz = [varargin{:}];") + w.WriteStringln("if isscalar(sz)") + common.WriteBlockBody(w, func() { + w.WriteStringln("sz = [sz, sz];") + }) + w.WriteStringln("z = reshape(repelem(elem, prod(sz)), sz);") + }) +} + +type tailHandler func(next func()) + +type tailWrapper struct { + outer *tailWrapper + handler tailHandler +} + +func (t tailWrapper) Append(handler tailHandler) tailWrapper { + return tailWrapper{ + outer: &t, + handler: handler, + } +} + +func (t tailWrapper) Run(body func()) { + t.composeFunc(body)() +} + +func (t tailWrapper) composeFunc(next func()) func() { + if t.handler == nil { + return next + } + this := func() { t.handler(next) } + if t.outer == nil { + return this + } + + return t.outer.composeFunc(this) +} + +func writeComputedFieldExpression(w *formatting.IndentedWriter, expression dsl.Expression, contextNamespace string) { + helperFunctionLookup := make(map[any]string) + dsl.Visit(expression, func(self dsl.Visitor, node dsl.Node) { + switch t := node.(type) { + case *dsl.FunctionCallExpression: + if t.FunctionName == dsl.FunctionDimensionIndex { + arrType := (t.Arguments[0].GetResolvedType()) + if _, ok := helperFunctionLookup[arrType]; !ok { + funcName := fmt.Sprintf("helper_%d_", len(helperFunctionLookup)) + helperFunctionLookup[arrType] = funcName + fmt.Fprintf(w, "function dim = %s(dim_name)\n", funcName) + common.WriteBlockBody(w, func() { + dims := dsl.ToGeneralizedType(arrType).Dimensionality.(*dsl.Array).Dimensions + for i, d := range *dims { + fmt.Fprintf(w, "if dim_name == \"%s\"\n", *d.Name) + w.Indented(func() { + fmt.Fprintf(w, "dim = %d;\n", i) + }) + w.WriteString("else") + } + w.WriteStringln("") + common.WriteBlockBody(w, func() { + w.WriteStringln(`throw(yardl.ValueError("Unknown dimension name: '%s'", dim_name));`) + }) + w.WriteStringln("") + }) + } + } + } + self.VisitChildren(node) + }) + + varCounter := 0 + newVarName := func() string { + varCounter++ + return fmt.Sprintf("var%d", varCounter) + } + + tail := tailWrapper{}.Append(func(next func()) { + w.WriteString("res = ") + next() + w.WriteStringln(";") + w.WriteStringln("return") + }) + + dsl.VisitWithContext(expression, tail, func(self dsl.VisitorWithContext[tailWrapper], node dsl.Node, tail tailWrapper) { + switch t := node.(type) { + case *dsl.UnaryExpression: + tail.Run(func() { + if t.Operator != dsl.UnaryOpNegate { + panic(fmt.Sprintf("unexpected unary operator %d", t.Operator)) + } + w.WriteString("-(") + self.Visit(t.Expression, tailWrapper{}) + w.WriteString(")") + }) + + case *dsl.BinaryExpression: + tail.Run(func() { + requiresParentheses := false + if l, ok := t.Left.(*dsl.BinaryExpression); ok && l.Operator.Precedence() < t.Operator.Precedence() { + requiresParentheses = true + } + + if requiresParentheses { + w.WriteString("(") + } + self.Visit(t.Left, tailWrapper{}) + if requiresParentheses { + w.WriteString(")") + } + + w.WriteString(" ") + + switch t.Operator { + case dsl.BinaryOpAdd: + w.WriteString("+") + case dsl.BinaryOpSub: + w.WriteString("-") + case dsl.BinaryOpMul: + w.WriteString(".*") + case dsl.BinaryOpDiv: + w.WriteString("./") + case dsl.BinaryOpPow: + w.WriteString("^") + default: + panic(fmt.Sprintf("unexpected binary operator %d", t.Operator)) + } + + w.WriteString(" ") + + requiresParentheses = false + if r, ok := t.Right.(*dsl.BinaryExpression); ok && r.Operator.Precedence() < t.Operator.Precedence() { + requiresParentheses = true + } + + if requiresParentheses { + w.WriteString("(") + } + self.Visit(t.Right, tailWrapper{}) + if requiresParentheses { + w.WriteString(")") + } + }) + + case *dsl.IntegerLiteralExpression: + tail.Run(func() { + fmt.Fprintf(w, "%d", &t.Value) + }) + case *dsl.FloatingPointLiteralExpression: + tail.Run(func() { + w.WriteString(t.Value) + }) + case *dsl.StringLiteralExpression: + tail.Run(func() { + fmt.Fprintf(w, "%q", t.Value) + }) + case *dsl.MemberAccessExpression: + tail.Run(func() { + if t.Target == nil { + if t.Kind == dsl.MemberAccessVariable { + w.WriteString(common.FieldIdentifierName(t.Member)) + return + } + + w.WriteString("self") + } else { + self.Visit(t.Target, tailWrapper{}) + } + w.WriteString(".") + if t.Kind == dsl.MemberAccessComputedField { + fmt.Fprintf(w, "%s()", common.ComputedFieldIdentifierName(t.Member)) + } else { + w.WriteString(common.FieldIdentifierName(t.Member)) + } + }) + + case *dsl.SubscriptExpression: + // Collapse adjacent subscript expressions (you can't do `array[x][y]` in Matlab, only `array(x,y)`) + target := t.Target + arguments := t.Arguments + dsl.Visit(t.Target, func(self dsl.Visitor, node dsl.Node) { + if t, ok := node.(*dsl.SubscriptExpression); ok { + target = t.Target + arguments = append(t.Arguments, arguments...) + self.VisitChildren(t.Target) + } + }) + + tail.Run(func() { + self.Visit(target, tailWrapper{}) + + startSubscript := "(" + delimeter := ", " + dsl.Visit(target.GetResolvedType(), func(self dsl.Visitor, node dsl.Node) { + switch t := node.(type) { + case *dsl.GeneralizedType: + switch t.Dimensionality.(type) { + case *dsl.Vector, *dsl.Array: + startSubscript = "(1+" + delimeter = ", 1+" + return + } + } + self.VisitChildren(node) + }) + + w.WriteString(startSubscript) + slices.Reverse(arguments) + formatting.Delimited(w, delimeter, arguments, func(w *formatting.IndentedWriter, i int, a *dsl.SubscriptArgument) { + self.Visit(a.Value, tailWrapper{}) + }) + w.WriteString(")") + }) + + case *dsl.FunctionCallExpression: + tail.Run(func() { + switch t.FunctionName { + case dsl.FunctionSize: + switch dsl.ToGeneralizedType(dsl.GetUnderlyingType(t.Arguments[0].GetResolvedType())).Dimensionality.(type) { + case *dsl.Map: + fmt.Fprintf(w, "numEntries(") + self.Visit(t.Arguments[0], tailWrapper{}) + fmt.Fprintf(w, ")") + + case *dsl.Vector: + fmt.Fprintf(w, "length(") + self.Visit(t.Arguments[0], tailWrapper{}) + fmt.Fprintf(w, ")") + + case *dsl.Array: + if len(t.Arguments) > 1 { + w.WriteString("size(") + self.Visit(t.Arguments[0], tailWrapper{}) + for _, arg := range t.Arguments[1:] { + w.WriteString(", ") + w.WriteString("ndims(") + self.Visit(t.Arguments[0], tailWrapper{}) + w.WriteString(")-(") + self.Visit(arg, tailWrapper{}) + w.WriteString(")") + } + } else { + w.WriteString("numel(") + self.Visit(t.Arguments[0], tailWrapper{}) + } + w.WriteString(")") + } + + case dsl.FunctionDimensionIndex: + helperFuncName := helperFunctionLookup[t.Arguments[0].GetResolvedType()] + fmt.Fprintf(w, "%s(", helperFuncName) + self.Visit(t.Arguments[1], tailWrapper{}) + w.WriteString(")") + + case dsl.FunctionDimensionCount: + w.WriteString("yardl.dimension_count(") + self.Visit(t.Arguments[0], tailWrapper{}) + w.WriteString(")") + + default: + panic(fmt.Sprintf("Unknown function '%s'", t.FunctionName)) + } + }) + + case *dsl.SwitchExpression: + targetType := dsl.ToGeneralizedType(dsl.GetUnderlyingType(t.Target.GetResolvedType())) + + unionVariableName := newVarName() + fmt.Fprintf(w, "%s = ", unionVariableName) + self.Visit(t.Target, tailWrapper{}) + w.WriteStringln(";") + + if targetType.Cases.IsOptional() { + for i, switchCase := range t.Cases { + writeSwitchCaseOverOptional(w, switchCase, unionVariableName, i == len(targetType.Cases)-1, self, tail) + } + return + } + + if targetType.Cases.IsUnion() { + // Special handling for SwitchExpression over a Union from an imported namespace + targetTypeNamespace := "" + dsl.Visit(t.Target, func(self dsl.Visitor, node dsl.Node) { + switch node := node.(type) { + case *dsl.SimpleType: + self.Visit(node.ResolvedDefinition) + case *dsl.RecordDefinition: + for _, field := range node.Fields { + u := dsl.GetUnderlyingType(field.Type) + if u == t.Target.GetResolvedType() { + if targetTypeNamespace == "" { + meta := node.GetDefinitionMeta() + targetTypeNamespace = meta.Namespace + } + return + } + } + case dsl.Expression: + t := node.GetResolvedType() + if t != nil { + self.Visit(t) + } + } + self.VisitChildren(node) + }) + if targetTypeNamespace == "" { + targetTypeNamespace = contextNamespace + } + + unionClassName := fmt.Sprintf("%s.%s", common.NamespaceIdentifierName(targetTypeNamespace), common.UnionClassName(targetType)) + for _, switchCase := range t.Cases { + writeSwitchCaseOverUnion(w, targetType, unionClassName, switchCase, unionVariableName, self, tail) + } + + if _, ok := t.Cases[len(t.Cases)-1].Pattern.(*dsl.DiscardPattern); !ok { + w.WriteStringln(`throw(yardl.RuntimeError("Unexpected union case"))`) + } + return + } + + // this is over a single type + if len(t.Cases) != 1 { + panic("switch expression over a single type expected to have exactly one case") + } + switchCase := t.Cases[0] + switch pattern := switchCase.Pattern.(type) { + case *dsl.DeclarationPattern: + fmt.Fprintf(w, "%s = %s;\n", common.FieldIdentifierName(pattern.Identifier), unionVariableName) + self.Visit(switchCase.Expression, tail) + case *dsl.TypePattern, *dsl.DiscardPattern: + self.Visit(switchCase.Expression, tail) + default: + panic(fmt.Sprintf("Unexpected pattern type %T", t.Cases[0].Pattern)) + } + + case *dsl.TypeConversionExpression: + tail = tail.Append(func(next func()) { + writeTypeConversion(w, t.Type, next) + }) + + self.Visit(t.Expression, tail) + + default: + panic(fmt.Sprintf("Unknown expression type '%T'", t)) + } + }) +} + +func writeSwitchCaseOverOptional(w *formatting.IndentedWriter, switchCase *dsl.SwitchCase, variableName string, isLastCase bool, visitor dsl.VisitorWithContext[tailWrapper], tail tailWrapper) { + writeCore := func(declarationIdentifier string) { + if declarationIdentifier != "" { + fmt.Fprintf(w, "%s = %s;\n", declarationIdentifier, variableName) + } + visitor.Visit(switchCase.Expression, tail) + } + + writeTypeCase := func(typePattern *dsl.TypePattern, declarationIdentifier string) { + if isLastCase { + writeCore(declarationIdentifier) + return + } + + if typePattern.Type == nil { + fmt.Fprintf(w, "if %s == yardl.None\n", variableName) + } else { + fmt.Fprintf(w, "if %s ~= yardl.None\n", variableName) + } + + common.WriteBlockBody(w, func() { + writeCore(declarationIdentifier) + }) + } + + switch t := switchCase.Pattern.(type) { + case *dsl.TypePattern: + writeTypeCase(t, "") + case *dsl.DeclarationPattern: + writeTypeCase(&t.TypePattern, common.FieldIdentifierName(t.Identifier)) + case *dsl.DiscardPattern: + writeCore("") + default: + panic(fmt.Sprintf("Unknown pattern type '%T'", switchCase.Pattern)) + } +} + +func writeSwitchCaseOverUnion(w *formatting.IndentedWriter, unionType *dsl.GeneralizedType, unionClassName string, switchCase *dsl.SwitchCase, variableName string, visitor dsl.VisitorWithContext[tailWrapper], tail tailWrapper) { + caseIndexOffset := 1 + writeTypeCase := func(typePattern *dsl.TypePattern, declarationIdentifier string) { + for i, typeCase := range unionType.Cases { + if typeCase.Type == nil { + caseIndexOffset = 0 + } + + if dsl.TypesEqual(typePattern.Type, typeCase.Type) { + if typePattern.Type == nil { + fmt.Fprintf(w, "if %s == yardl.None\n", variableName) + common.WriteBlockBody(w, func() { + visitor.Visit(switchCase.Expression, tail) + }) + } else { + fmt.Fprintf(w, "if isa(%s, \"%s\") && %s.index == %d\n", variableName, unionClassName, variableName, i+caseIndexOffset) + common.WriteBlockBody(w, func() { + if declarationIdentifier != "" { + fmt.Fprintf(w, "%s = %s.value;\n", declarationIdentifier, variableName) + } + visitor.Visit(switchCase.Expression, tail) + }) + } + return + } + } + panic(fmt.Sprintf("Did not find pattern type '%s'", dsl.TypeToShortSyntax(typePattern.Type, false))) + } + + switch t := switchCase.Pattern.(type) { + case *dsl.TypePattern: + writeTypeCase(t, "") + case *dsl.DeclarationPattern: + writeTypeCase(&t.TypePattern, common.FieldIdentifierName(t.Identifier)) + case *dsl.DiscardPattern: + visitor.Visit(switchCase.Expression, tail) + default: + panic(fmt.Sprintf("Unknown pattern type '%T'", switchCase.Pattern)) + } +} + +func writeTypeConversion(w *formatting.IndentedWriter, t dsl.Type, next func()) { + getWrapper := func(t dsl.Type) (string, string) { + switch t := t.(type) { + case *dsl.SimpleType: + switch t := t.ResolvedDefinition.(type) { + case dsl.PrimitiveDefinition: + switch t { + case dsl.Bool: + return "logical(", ")" + case dsl.Int8: + return "int8(", ")" + case dsl.Uint8: + return "uint8(", ")" + case dsl.Int16: + return "int32(", ")" + case dsl.Uint16: + return "uint16(", ")" + case dsl.Int32: + return "int32(", ")" + case dsl.Uint32: + return "uint32(", ")" + case dsl.Int64: + return "int64(", ")" + case dsl.Uint64, dsl.Size: + return "uint64(", ")" + case dsl.Float32: + return "single(", ")" + case dsl.Float64: + return "double(", ")" + case dsl.ComplexFloat32: + return "complex(single(", "))" + case dsl.ComplexFloat64: + return "complex(double(", "))" + case dsl.String: + return "string(", ")" + case dsl.Date: + return "yardl.Date(", ")" + case dsl.Time: + return "yardl.Time(", ")" + case dsl.DateTime: + return "yardl.DateTime(", ")" + } + } + } + panic(fmt.Sprintf("Unsupported type '%s'", t)) + } + + open, close := getWrapper(t) + w.WriteString(open) + next() + w.WriteString(close) +} + +type defaultValueKind int + +const ( + defaultValueKindNone defaultValueKind = iota + defaultValueKindImmutable + defaultValueKindMutable +) + +func typeDefault(t dsl.Type, contextNamespace string, namedType string, st dsl.SymbolTable) (string, defaultValueKind) { + switch t := t.(type) { + case nil: + return "yardl.None", defaultValueKindImmutable + case *dsl.SimpleType: + return typeDefinitionDefault(t.ResolvedDefinition, contextNamespace, st) + case *dsl.GeneralizedType: + switch td := t.Dimensionality.(type) { + case nil: + defaultExpression, defaultKind := typeDefault(t.Cases[0].Type, contextNamespace, "", st) + if t.Cases.IsSingle() || t.Cases.HasNullOption() { + return defaultExpression, defaultKind + } + + var unionClassName string + if namedType != "" { + unionClassName = namedType + } else { + unionClassName = fmt.Sprintf("%s.%s", common.NamespaceIdentifierName(contextNamespace), common.UnionClassName(t)) + } + + unionCaseConstructor := fmt.Sprintf("%s.%s", unionClassName, formatting.ToPascalCase(t.Cases[0].Tag)) + + switch defaultKind { + case defaultValueKindNone: + return "", defaultKind + case defaultValueKindImmutable: + return fmt.Sprintf(`%s(%s)`, unionCaseConstructor, defaultExpression), defaultKind + case defaultValueKindMutable: + if t, ok := dsl.GetUnderlyingType(t.Cases[0].Type).(*dsl.SimpleType); ok { + if _, ok := t.ResolvedDefinition.(*dsl.RecordDefinition); ok { + return fmt.Sprintf(`%s(%s())`, unionCaseConstructor, defaultExpression), defaultValueKindMutable + } + } + return fmt.Sprintf(`%s(%s)`, unionCaseConstructor, defaultExpression), defaultValueKindMutable + } + + return fmt.Sprintf(`("%s", %s)`, t.Cases[0].Tag, defaultExpression), defaultValueKindImmutable + + case *dsl.Vector: + scalar := t.ToScalar() + if dsl.TypeContainsGenericTypeParameter(scalar) { + return "", defaultValueKindNone + } + + dtype := common.TypeSyntax(scalar, contextNamespace) + if td.Length == nil { + return fmt.Sprintf("%s.empty()", dtype), defaultValueKindMutable + } + + scalarDefault, scalarDefaultKind := typeDefault(t.Cases[0].Type, contextNamespace, "", st) + switch scalarDefaultKind { + case defaultValueKindNone: + return "", defaultValueKindNone + case defaultValueKindImmutable, defaultValueKindMutable: + if gt, ok := t.Cases[0].Type.(*dsl.GeneralizedType); ok { + switch gt.Dimensionality.(type) { + case *dsl.Vector, *dsl.Array: + return fmt.Sprintf("repelem({%s}, %d)", scalarDefault, *td.Length), scalarDefaultKind + } + } + return fmt.Sprintf("repelem(%s, %d)", scalarDefault, *td.Length), defaultValueKindMutable + } + + case *dsl.Array: + scalar := t.ToScalar() + if dsl.TypeContainsGenericTypeParameter(scalar) { + return "", defaultValueKindNone + } + + if td.IsFixed() { + dims := make([]string, len(*td.Dimensions)) + for i, d := range *td.Dimensions { + dims[len(*td.Dimensions)-i-1] = strconv.FormatUint(*d.Length, 10) + } + if len(dims) == 1 { + dims = append(dims, "1") + } + + scalarDefault, _ := typeDefault(scalar, contextNamespace, "", st) + + return fmt.Sprintf("repelem(%s, %s)", scalarDefault, strings.Join(dims, ", ")), defaultValueKindMutable + } + + dtype := common.TypeSyntax(scalar, contextNamespace) + if td.HasKnownNumberOfDimensions() { + shape := strings.Repeat("0, ", len(*td.Dimensions))[0 : len(*td.Dimensions)*3-2] + return fmt.Sprintf("%s.empty(%s)", dtype, shape), defaultValueKindMutable + } + return fmt.Sprintf("%s.empty()", dtype), defaultValueKindMutable + + case *dsl.Map: + return "dictionary", defaultValueKindMutable + } + } + + return "", defaultValueKindNone +} + +func typeDefinitionDefault(t dsl.TypeDefinition, contextNamespace string, st dsl.SymbolTable) (string, defaultValueKind) { + switch t := t.(type) { + case dsl.PrimitiveDefinition: + switch t { + case dsl.Bool: + return "false", defaultValueKindImmutable + case dsl.Int8: + return "int8(0)", defaultValueKindImmutable + case dsl.Uint8: + return "uint8(0)", defaultValueKindImmutable + case dsl.Int16: + return "int16(0)", defaultValueKindImmutable + case dsl.Uint16: + return "uint16(0)", defaultValueKindImmutable + case dsl.Int32: + return "int32(0)", defaultValueKindImmutable + case dsl.Uint32: + return "uint32(0)", defaultValueKindImmutable + case dsl.Int64: + return "int64(0)", defaultValueKindImmutable + case dsl.Uint64, dsl.Size: + return "uint64(0)", defaultValueKindImmutable + case dsl.Float32: + return "single(0)", defaultValueKindImmutable + case dsl.Float64: + return "double(0)", defaultValueKindImmutable + case dsl.ComplexFloat32: + return "complex(single(0))", defaultValueKindImmutable + case dsl.ComplexFloat64: + return "complex(0)", defaultValueKindImmutable + case dsl.String: + return `""`, defaultValueKindImmutable + case dsl.Date: + return "yardl.Date()", defaultValueKindImmutable + case dsl.Time: + return "yardl.Time()", defaultValueKindImmutable + case dsl.DateTime: + return "yardl.DateTime()", defaultValueKindImmutable + } + + case *dsl.EnumDefinition: + zeroValue := t.GetZeroValue() + if t.IsFlags { + if zeroValue == nil { + return fmt.Sprintf("%s(0)", common.TypeSyntax(t, contextNamespace)), defaultValueKindImmutable + } else { + return fmt.Sprintf("%s.%s", common.TypeSyntax(t, contextNamespace), common.EnumValueIdentifierName(zeroValue.Symbol)), defaultValueKindImmutable + } + } + + if zeroValue == nil { + return "", defaultValueKindNone + } + + return fmt.Sprintf("%s.%s", common.TypeSyntax(t, contextNamespace), common.EnumValueIdentifierName(zeroValue.Symbol)), defaultValueKindImmutable + + case *dsl.NamedType: + return typeDefault(t.Type, contextNamespace, common.TypeSyntax(t, contextNamespace), st) + + case *dsl.RecordDefinition: + if len(t.TypeArguments) == 0 { + if len(t.TypeParameters) > 0 { + // *Open* Generic Record type + // Should never get here - typeDefault is only called on Fields, which must be closed if generic + panic(fmt.Sprintf("No typeDefault for open generic record %s", t.Name)) + } + + for _, f := range t.Fields { + _, fieldDefaultKind := typeDefault(f.Type, contextNamespace, "", st) + if fieldDefaultKind == defaultValueKindNone { + // Basic, closed record type + // Should never get here - a Field in a closed record should always have a default type + panic(fmt.Sprintf("No typeDefault for record field %s.%s", t.Name, f.Name)) + } + } + + // Basic record type + return fmt.Sprintf("%s()", common.TypeSyntax(t, contextNamespace)), defaultValueKindMutable + } + + // t is a *closed* generic record type + // genericDef is its original generic type definition + genericDef := st[t.GetQualifiedName()].(*dsl.RecordDefinition) + args := make([]string, 0) + for i, f := range t.Fields { + fieldDefaultExpr, fieldDefaultKind := typeDefault(f.Type, contextNamespace, "", st) + if fieldDefaultKind == defaultValueKindNone { + return "", defaultValueKindNone + } + + // Only write a constructor argument if it is needed, e.g. the record definition's field is generic and doesn't have a default value + _, genDefaultKind := typeDefault(genericDef.Fields[i].Type, contextNamespace, "", st) + if genDefaultKind == defaultValueKindNone { + args = append(args, fmt.Sprintf("%s=%s", common.FieldIdentifierName(f.Name), fieldDefaultExpr)) + } + } + + return fmt.Sprintf("%s(%s)", common.TypeSyntax(t, contextNamespace), strings.Join(args, ", ")), defaultValueKindMutable + } + + return "", defaultValueKindNone +} diff --git a/tooling/internal/python/static_files/_binary.py b/tooling/internal/python/static_files/_binary.py index c76ad41e..8e193074 100644 --- a/tooling/internal/python/static_files/_binary.py +++ b/tooling/internal/python/static_files/_binary.py @@ -408,7 +408,7 @@ def write(self, stream: CodedOutputStream, value: Int16) -> None: f"Value {value} is outside the range of a signed 16-bit integer" ) elif not isinstance(value, cast(type, np.int16)): - raise ValueError(f"Value in not an signed 16-bit integer: {value}") + raise ValueError(f"Value is not a signed 16-bit integer: {value}") stream.write_signed_varint(value) @@ -436,7 +436,7 @@ def write(self, stream: CodedOutputStream, value: UInt16) -> None: f"Value {value} is outside the range of an unsigned 16-bit integer" ) elif not isinstance(value, cast(type, np.uint16)): - raise ValueError(f"Value in not an unsigned 16-bit integer: {value}") + raise ValueError(f"Value is not an unsigned 16-bit integer: {value}") stream.write_unsigned_varint(value) @@ -464,7 +464,7 @@ def write(self, stream: CodedOutputStream, value: Int32) -> None: f"Value {value} is outside the range of a signed 32-bit integer" ) elif not isinstance(value, cast(type, np.int32)): - raise ValueError(f"Value in not a signed 32-bit integer: {value}") + raise ValueError(f"Value is not a signed 32-bit integer: {value}") stream.write_signed_varint(value) @@ -492,7 +492,7 @@ def write(self, stream: CodedOutputStream, value: UInt32) -> None: f"Value {value} is outside the range of an unsigned 32-bit integer" ) elif not isinstance(value, cast(type, np.uint32)): - raise ValueError(f"Value in not an unsigned 32-bit integer: {value}") + raise ValueError(f"Value is not an unsigned 32-bit integer: {value}") stream.write_unsigned_varint(value) @@ -520,7 +520,7 @@ def write(self, stream: CodedOutputStream, value: Int64) -> None: f"Value {value} is outside the range of a signed 64-bit integer" ) elif not isinstance(value, cast(type, np.int64)): - raise ValueError(f"Value in not a signed 64-bit integer: {value}") + raise ValueError(f"Value is not a signed 64-bit integer: {value}") stream.write_signed_varint(value) @@ -548,7 +548,7 @@ def write(self, stream: CodedOutputStream, value: UInt64) -> None: f"Value {value} is outside the range of an unsigned 64-bit integer" ) elif not isinstance(value, cast(type, np.uint64)): - raise ValueError(f"Value in not an unsigned 64-bit integer: {value}") + raise ValueError(f"Value is not an unsigned 64-bit integer: {value}") stream.write_unsigned_varint(value) @@ -576,7 +576,7 @@ def write(self, stream: CodedOutputStream, value: Size) -> None: f"Value {value} is outside the range of an unsigned 64-bit integer" ) elif not isinstance(value, cast(type, np.uint64)): - raise ValueError(f"Value in not an unsigned 64-bit integer: {value}") + raise ValueError(f"Value is not an unsigned 64-bit integer: {value}") stream.write_unsigned_varint(value) diff --git a/tooling/pkg/packaging/packageinfo.go b/tooling/pkg/packaging/packageinfo.go index 3a96e654..5debad1a 100644 --- a/tooling/pkg/packaging/packageinfo.go +++ b/tooling/pkg/packaging/packageinfo.go @@ -33,6 +33,7 @@ type PackageInfo struct { Json *JsonCodegenOptions `yaml:"json,omitempty"` Cpp *CppCodegenOptions `yaml:"cpp,omitempty"` Python *PythonCodegenOptions `yaml:"python,omitempty"` + Matlab *MatlabCodegenOptions `yaml:"matlab,omitempty"` } func (p *PackageInfo) PackageDir() string { @@ -112,6 +113,15 @@ func (p *PackageInfo) validate() error { } } + if p.Matlab != nil { + p.Matlab.PackageInfo = p + if p.Matlab.OutputDir == "" { + errorSink.Add(validation.NewValidationError(errors.New("the 'matlab.outputDir' field must not be empty"), p.FilePath)) + } else { + p.Matlab.OutputDir = filepath.Join(p.PackageDir(), p.Matlab.OutputDir) + } + } + return errorSink.AsError() } @@ -206,7 +216,14 @@ type PythonCodegenOptions struct { InternalSymlinkStaticFiles bool `yaml:"internalSymlinkStaticFiles"` } -// Parses PackageInfo in dir then loads all package Imports and Versions +type MatlabCodegenOptions struct { + PackageInfo *PackageInfo `yaml:"-"` + OutputDir string `yaml:"outputDir"` + InternalSymlinkStaticFiles bool `yaml:"internalSymlinkStaticFiles"` + InternalGenerateMocks bool `yaml:"internalGenerateMocks"` +} + +// Parses PackageInfo in dir then loads all package Imports and Predecessors func LoadPackage(dir string) (*PackageInfo, error) { packageInfo, err := loadPackageVersion(dir) if err != nil {