avrotize 2.22.0__tar.gz → 2.22.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {avrotize-2.22.0 → avrotize-2.22.2}/PKG-INFO +1 -1
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/_version.py +3 -3
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotocsharp/class_test.cs.jinja +33 -2
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotocsharp/dataclass_core.jinja +26 -5
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotocsharp/project.csproj.jinja +3 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotocsharp.py +19 -1
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotojsons.py +25 -3
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/commands.json +31 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/constants.py +5 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/dependencies/cs/net90/dependencies.csproj +1 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretocsharp/dataclass_core.jinja +110 -3
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretocsharp/project.csproj.jinja +3 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretocsharp.py +108 -28
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretots.py +2 -2
- {avrotize-2.22.0 → avrotize-2.22.2}/LICENSE +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/README.md +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/__init__.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/__main__.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/asn1toavro.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotize.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotocpp/CMakeLists.txt.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotocpp/build.bat.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotocpp/build.sh.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotocpp/dataclass_body.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotocpp/vcpkg.json.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotocpp.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotocsharp/README.md.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotocsharp/enum_test.cs.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotocsharp/project.sln.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotocsharp/run_coverage.ps1.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotocsharp/run_coverage.sh.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotocsharp/testproject.csproj.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotocsv.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotodatapackage.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotodb.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotogo/go_enum.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotogo/go_helpers.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotogo/go_struct.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotogo/go_test.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotogo/go_union.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotogo.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotographql.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotoiceberg.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotojava/class_test.java.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotojava/enum_test.java.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotojava/testproject.pom.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotojava.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotojs.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotojstruct.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotokusto.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotomd/README.md.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotomd.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotools.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotoparquet.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotoproto.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotopython/dataclass_core.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotopython/enum_core.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotopython/pyproject_toml.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotopython/test_class.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotopython/test_enum.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotopython.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotorust/dataclass_enum.rs.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotorust/dataclass_struct.rs.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotorust/dataclass_union.rs.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotorust.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotots/class_core.ts.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotots/class_test.ts.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotots/enum_core.ts.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotots/gitignore.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotots/index.ts.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotots/package.json.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotots/tsconfig.json.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotots.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/avrotoxsd.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/cddltostructure.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/common.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/csvtoavro.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/datapackagetoavro.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/dependencies/cpp/vcpkg/vcpkg.json +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/dependencies/go/go121/go.mod +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/dependencies/java/jdk21/pom.xml +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/dependencies/python/py312/requirements.txt +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/dependencies/rust/stable/Cargo.toml +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/dependencies/typescript/node22/package.json +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/dependency_resolver.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/dependency_version.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/generic/generic.avsc +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/jsonstoavro.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/jsonstostructure.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/jstructtoavro.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/kstructtoavro.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/kustotoavro.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/openapitostructure.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/parquettoavro.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/proto2parser.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/proto3parser.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/prototoavro.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/prototypes/any.avsc +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/prototypes/api.avsc +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/prototypes/duration.avsc +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/prototypes/field_mask.avsc +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/prototypes/struct.avsc +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/prototypes/timestamp.avsc +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/prototypes/type.avsc +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/prototypes/wrappers.avsc +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretocddl.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretocpp/CMakeLists.txt.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretocpp/build.bat.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretocpp/build.sh.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretocpp/dataclass_body.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretocpp/vcpkg.json.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretocpp.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretocsharp/class_test.cs.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretocsharp/enum_test.cs.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretocsharp/json_structure_converters.cs.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretocsharp/program.cs.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretocsharp/project.sln.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretocsharp/testproject.csproj.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretocsharp/tuple_converter.cs.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretocsv.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretodatapackage.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretodb.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretogo/go_enum.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretogo/go_helpers.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretogo/go_interface.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretogo/go_struct.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretogo/go_test.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretogo.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretographql.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretoiceberg.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretojava/choice_core.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretojava/class_core.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretojava/enum_core.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretojava/equals_hashcode.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretojava/pom.xml.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretojava/tuple_core.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretojava.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretojs/class_core.js.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretojs/enum_core.js.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretojs/package.json.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretojs/test_class.js.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretojs/test_enum.js.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretojs/test_runner.js.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretojs.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretojsons.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretokusto.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretomd/README.md.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretomd.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretoproto.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretopython/dataclass_core.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretopython/enum_core.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretopython/map_alias.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretopython/pyproject_toml.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretopython/test_class.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretopython/test_enum.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretopython.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretorust/dataclass_enum.rs.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretorust/dataclass_struct.rs.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretorust/dataclass_union.rs.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretorust.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretots/class_core.ts.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretots/enum_core.ts.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretots/gitignore.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretots/index.ts.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretots/package.json.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretots/test_class.ts.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretots/tsconfig.json.jinja +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/structuretoxsd.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/avrotize/xsdtoavro.py +0 -0
- {avrotize-2.22.0 → avrotize-2.22.2}/pyproject.toml +0 -0
|
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
|
|
|
28
28
|
commit_id: COMMIT_ID
|
|
29
29
|
__commit_id__: COMMIT_ID
|
|
30
30
|
|
|
31
|
-
__version__ = version = '2.22.
|
|
32
|
-
__version_tuple__ = version_tuple = (2, 22,
|
|
31
|
+
__version__ = version = '2.22.2'
|
|
32
|
+
__version_tuple__ = version_tuple = (2, 22, 2)
|
|
33
33
|
|
|
34
|
-
__commit_id__ = commit_id = '
|
|
34
|
+
__commit_id__ = commit_id = 'g25efcf5da'
|
|
@@ -166,7 +166,18 @@ public class {{ test_class_name }}
|
|
|
166
166
|
Assert.That(newInstance, Is.EqualTo(_instance));
|
|
167
167
|
}
|
|
168
168
|
{%- endif %}
|
|
169
|
-
{%- if
|
|
169
|
+
{%- if cbor_annotation %}
|
|
170
|
+
/// <summary> Testing CBOR serializer </summary>
|
|
171
|
+
[Test]
|
|
172
|
+
public void Test_ToByteArray_FromData_Cbor()
|
|
173
|
+
{
|
|
174
|
+
var mediaType = "application/cbor";
|
|
175
|
+
var bytes = _instance.ToByteArray(mediaType);
|
|
176
|
+
var newInstance = {{ class_base_name }}.FromData(bytes, mediaType);
|
|
177
|
+
Assert.That(newInstance, Is.EqualTo(_instance));
|
|
178
|
+
}
|
|
179
|
+
{%- endif %}
|
|
180
|
+
{%- if avro_annotation or system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation or msgpack_annotation or cbor_annotation or protobuf_net_annotation %}
|
|
170
181
|
|
|
171
182
|
/// <summary> Testing FromData with edge cases </summary>
|
|
172
183
|
[Test]
|
|
@@ -188,6 +199,9 @@ public class {{ test_class_name }}
|
|
|
188
199
|
{%- elif msgpack_annotation %}
|
|
189
200
|
// Test null data - FromData returns null for null input
|
|
190
201
|
Assert.That({{ class_base_name }}.FromData((byte[])null!, "application/msgpack"), Is.Null);
|
|
202
|
+
{%- elif cbor_annotation %}
|
|
203
|
+
// Test null data - FromData returns null for null input
|
|
204
|
+
Assert.That({{ class_base_name }}.FromData((byte[])null!, "application/cbor"), Is.Null);
|
|
191
205
|
{%- elif protobuf_net_annotation %}
|
|
192
206
|
// Test null data - FromData returns null for null input
|
|
193
207
|
Assert.That({{ class_base_name }}.FromData((byte[])null!, "application/x-protobuf"), Is.Null);
|
|
@@ -242,7 +256,24 @@ public class {{ test_class_name }}
|
|
|
242
256
|
Assert.That(newInstance, Is.EqualTo(_instance));
|
|
243
257
|
}
|
|
244
258
|
{%- endif %}
|
|
245
|
-
{%- if
|
|
259
|
+
{%- if cbor_annotation and not (system_text_json_annotation or newtonsoft_json_annotation or msgpack_annotation) %}
|
|
260
|
+
|
|
261
|
+
/// <summary> Testing Gzip compression with CBOR </summary>
|
|
262
|
+
[Test]
|
|
263
|
+
public void Test_ToByteArray_Gzip_Cbor()
|
|
264
|
+
{
|
|
265
|
+
var mediaType = "application/cbor";
|
|
266
|
+
var gzipMediaType = "application/cbor+gzip";
|
|
267
|
+
var plainBytes = _instance.ToByteArray(mediaType);
|
|
268
|
+
var gzipBytes = _instance.ToByteArray(gzipMediaType);
|
|
269
|
+
// Gzip compressed data should start with magic bytes 0x1f 0x8b
|
|
270
|
+
Assert.That(gzipBytes.Length >= 2 && gzipBytes[0] == 0x1f && gzipBytes[1] == 0x8b, Is.True,
|
|
271
|
+
"Gzip compressed data should have correct magic bytes");
|
|
272
|
+
var newInstance = {{ class_base_name }}.FromData(gzipBytes, gzipMediaType);
|
|
273
|
+
Assert.That(newInstance, Is.EqualTo(_instance));
|
|
274
|
+
}
|
|
275
|
+
{%- endif %}
|
|
276
|
+
{%- if protobuf_net_annotation and not (system_text_json_annotation or newtonsoft_json_annotation or msgpack_annotation or cbor_annotation) %}
|
|
246
277
|
|
|
247
278
|
/// <summary> Testing Gzip compression with Protobuf </summary>
|
|
248
279
|
[Test]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
{%- if avro_annotation or system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation or protobuf_net_annotation or msgpack_annotation %}
|
|
1
|
+
{%- if avro_annotation or system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation or protobuf_net_annotation or msgpack_annotation or cbor_annotation %}
|
|
2
2
|
/// <summary>
|
|
3
3
|
/// Creates an object from the data
|
|
4
4
|
/// </summary>
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
if ( data is {{ class_name }}) return ({{ class_name }})data;
|
|
12
12
|
if ( contentTypeString == null ) contentTypeString = System.Net.Mime.MediaTypeNames.Application.Octet;
|
|
13
13
|
var contentType = new System.Net.Mime.ContentType(contentTypeString);
|
|
14
|
-
{%- if avro_annotation or system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation or protobuf_net_annotation or msgpack_annotation %}
|
|
14
|
+
{%- if avro_annotation or system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation or protobuf_net_annotation or msgpack_annotation or cbor_annotation %}
|
|
15
15
|
if ( contentType.MediaType.EndsWith("+gzip"))
|
|
16
16
|
{
|
|
17
17
|
var stream = data switch
|
|
@@ -149,12 +149,25 @@
|
|
|
149
149
|
};
|
|
150
150
|
return MessagePack.MessagePackSerializer.Deserialize<{{ class_name }}>(bytes);
|
|
151
151
|
}
|
|
152
|
+
{%- endif %}
|
|
153
|
+
{%- if cbor_annotation %}
|
|
154
|
+
if (contentType.MediaType.StartsWith("application/cbor"))
|
|
155
|
+
{
|
|
156
|
+
var bytes = data switch
|
|
157
|
+
{
|
|
158
|
+
byte[] b => b,
|
|
159
|
+
System.IO.Stream s => ReadStreamToBytes(s),
|
|
160
|
+
System.BinaryData bd => bd.ToArray(),
|
|
161
|
+
_ => throw new NotSupportedException("Data type not supported for CBOR")
|
|
162
|
+
};
|
|
163
|
+
return Dahomey.Cbor.Cbor.Deserialize<{{ class_name }}>(new ReadOnlySpan<byte>(bytes));
|
|
164
|
+
}
|
|
152
165
|
{%- endif %}
|
|
153
166
|
throw new System.NotSupportedException($"Unsupported media type {contentType.MediaType}");
|
|
154
167
|
}
|
|
155
168
|
{%- endif %}
|
|
156
169
|
|
|
157
|
-
{%- if msgpack_annotation %}
|
|
170
|
+
{%- if msgpack_annotation or cbor_annotation %}
|
|
158
171
|
private static byte[] ReadStreamToBytes(System.IO.Stream stream)
|
|
159
172
|
{
|
|
160
173
|
using (var memoryStream = new System.IO.MemoryStream())
|
|
@@ -190,7 +203,7 @@
|
|
|
190
203
|
{%- if avro_annotation %}
|
|
191
204
|
{%- endif%}
|
|
192
205
|
|
|
193
|
-
{%- if avro_annotation or system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation or protobuf_net_annotation or msgpack_annotation %}
|
|
206
|
+
{%- if avro_annotation or system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation or protobuf_net_annotation or msgpack_annotation or cbor_annotation %}
|
|
194
207
|
/// <summary>
|
|
195
208
|
/// Converts the object to a byte array
|
|
196
209
|
/// </summary>
|
|
@@ -263,7 +276,15 @@
|
|
|
263
276
|
result = MessagePack.MessagePackSerializer.Serialize(this);
|
|
264
277
|
}
|
|
265
278
|
{%- endif %}
|
|
266
|
-
{%- if
|
|
279
|
+
{%- if cbor_annotation %}
|
|
280
|
+
if (contentType.MediaType.StartsWith("application/cbor"))
|
|
281
|
+
{
|
|
282
|
+
var bufferWriter = new System.Buffers.ArrayBufferWriter<byte>();
|
|
283
|
+
Dahomey.Cbor.Cbor.Serialize(this, bufferWriter);
|
|
284
|
+
result = bufferWriter.WrittenSpan.ToArray();
|
|
285
|
+
}
|
|
286
|
+
{%- endif %}
|
|
287
|
+
{%- if avro_annotation or system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation or protobuf_net_annotation or msgpack_annotation or cbor_annotation %}
|
|
267
288
|
if (result != null && contentType.MediaType.EndsWith("+gzip"))
|
|
268
289
|
{
|
|
269
290
|
var stream = new System.IO.MemoryStream();
|
|
@@ -20,6 +20,9 @@
|
|
|
20
20
|
{%- if msgpack_annotation %}
|
|
21
21
|
<PackageReference Include="MessagePack" Version="{{ MSGPACK_VERSION }}" />
|
|
22
22
|
{%- endif %}
|
|
23
|
+
{%- if cbor_annotation %}
|
|
24
|
+
<PackageReference Include="Dahomey.Cbor" Version="{{ CBOR_VERSION }}" />
|
|
25
|
+
{%- endif %}
|
|
23
26
|
<PackageReference Include="System.Memory.Data" Version="{{ SYSTEM_MEMORY_DATA_VERSION }}" />
|
|
24
27
|
</ItemGroup>
|
|
25
28
|
<ItemGroup>
|
|
@@ -16,6 +16,7 @@ from avrotize.constants import (
|
|
|
16
16
|
SYSTEM_MEMORY_DATA_VERSION,
|
|
17
17
|
PROTOBUF_NET_VERSION,
|
|
18
18
|
MSGPACK_VERSION,
|
|
19
|
+
CBOR_VERSION,
|
|
19
20
|
NUNIT_VERSION,
|
|
20
21
|
NUNIT_ADAPTER_VERSION,
|
|
21
22
|
MSTEST_SDK_VERSION,
|
|
@@ -53,6 +54,7 @@ class AvroToCSharp:
|
|
|
53
54
|
self.newtonsoft_json_annotation = False
|
|
54
55
|
self.system_xml_annotation = False
|
|
55
56
|
self.msgpack_annotation = False
|
|
57
|
+
self.cbor_annotation = False
|
|
56
58
|
self.avro_annotation = False
|
|
57
59
|
self.protobuf_net_annotation = False
|
|
58
60
|
self.generated_types: Dict[str,str] = {}
|
|
@@ -267,6 +269,7 @@ class AvroToCSharp:
|
|
|
267
269
|
newtonsoft_json_annotation=self.newtonsoft_json_annotation,
|
|
268
270
|
system_xml_annotation=self.system_xml_annotation,
|
|
269
271
|
msgpack_annotation=self.msgpack_annotation,
|
|
272
|
+
cbor_annotation=self.cbor_annotation,
|
|
270
273
|
json_match_clauses=self.create_is_json_match_clauses(avro_schema, avro_namespace, class_name)
|
|
271
274
|
)
|
|
272
275
|
|
|
@@ -768,6 +771,10 @@ class AvroToCSharp:
|
|
|
768
771
|
if self.msgpack_annotation:
|
|
769
772
|
prop += f"{INDENT}[Key({field_index})]\n"
|
|
770
773
|
|
|
774
|
+
# Add CBOR serialization attribute if enabled
|
|
775
|
+
if self.cbor_annotation:
|
|
776
|
+
prop += f"{INDENT}[Dahomey.Cbor.Attributes.CborProperty(\"{annotation_name}\")]\n"
|
|
777
|
+
|
|
771
778
|
if self.system_text_json_annotation:
|
|
772
779
|
prop += f"{INDENT}[System.Text.Json.Serialization.JsonPropertyName(\"{annotation_name}\")]\n"
|
|
773
780
|
if is_enum_type:
|
|
@@ -831,6 +838,8 @@ class AvroToCSharp:
|
|
|
831
838
|
file_content += "using System.Xml.Serialization;\n"
|
|
832
839
|
if self.msgpack_annotation: # Add MessagePack serialization using directive
|
|
833
840
|
file_content += "using MessagePack;\n"
|
|
841
|
+
if self.cbor_annotation: # Add CBOR serialization using directive
|
|
842
|
+
file_content += "using Dahomey.Cbor.Attributes;\n"
|
|
834
843
|
|
|
835
844
|
if namespace:
|
|
836
845
|
# Namespace declaration with correct indentation for the definition
|
|
@@ -874,7 +883,8 @@ class AvroToCSharp:
|
|
|
874
883
|
system_text_json_annotation=self.system_text_json_annotation,
|
|
875
884
|
newtonsoft_json_annotation=self.newtonsoft_json_annotation,
|
|
876
885
|
protobuf_net_annotation=self.protobuf_net_annotation,
|
|
877
|
-
msgpack_annotation=self.msgpack_annotation
|
|
886
|
+
msgpack_annotation=self.msgpack_annotation,
|
|
887
|
+
cbor_annotation=self.cbor_annotation
|
|
878
888
|
)
|
|
879
889
|
elif type_kind == "enum":
|
|
880
890
|
test_class_definition = process_template(
|
|
@@ -1028,12 +1038,14 @@ class AvroToCSharp:
|
|
|
1028
1038
|
newtonsoft_json_annotation=self.newtonsoft_json_annotation,
|
|
1029
1039
|
protobuf_net_annotation=self.protobuf_net_annotation,
|
|
1030
1040
|
msgpack_annotation=self.msgpack_annotation,
|
|
1041
|
+
cbor_annotation=self.cbor_annotation,
|
|
1031
1042
|
CSHARP_AVRO_VERSION=CSHARP_AVRO_VERSION,
|
|
1032
1043
|
NEWTONSOFT_JSON_VERSION=NEWTONSOFT_JSON_VERSION,
|
|
1033
1044
|
SYSTEM_TEXT_JSON_VERSION=SYSTEM_TEXT_JSON_VERSION,
|
|
1034
1045
|
SYSTEM_MEMORY_DATA_VERSION=SYSTEM_MEMORY_DATA_VERSION,
|
|
1035
1046
|
PROTOBUF_NET_VERSION=PROTOBUF_NET_VERSION,
|
|
1036
1047
|
MSGPACK_VERSION=MSGPACK_VERSION,
|
|
1048
|
+
CBOR_VERSION=CBOR_VERSION,
|
|
1037
1049
|
NUNIT_VERSION=NUNIT_VERSION,
|
|
1038
1050
|
NUNIT_ADAPTER_VERSION=NUNIT_ADAPTER_VERSION,
|
|
1039
1051
|
MSTEST_SDK_VERSION=MSTEST_SDK_VERSION))
|
|
@@ -1107,6 +1119,7 @@ def convert_avro_to_csharp(
|
|
|
1107
1119
|
newtonsoft_json_annotation=False,
|
|
1108
1120
|
system_xml_annotation=False,
|
|
1109
1121
|
msgpack_annotation=False,
|
|
1122
|
+
cbor_annotation=False,
|
|
1110
1123
|
avro_annotation=False,
|
|
1111
1124
|
protobuf_net_annotation=False
|
|
1112
1125
|
):
|
|
@@ -1122,6 +1135,7 @@ def convert_avro_to_csharp(
|
|
|
1122
1135
|
newtonsoft_json_annotation (bool, optional): Use Newtonsoft.Json annotations. Defaults to False.
|
|
1123
1136
|
system_xml_annotation (bool, optional): Use System.Xml.Serialization annotations. Defaults to False.
|
|
1124
1137
|
msgpack_annotation (bool, optional): Use MessagePack annotations. Defaults to False.
|
|
1138
|
+
cbor_annotation (bool, optional): Use Dahomey.Cbor annotations. Defaults to False.
|
|
1125
1139
|
avro_annotation (bool, optional): Use Avro annotations. Defaults to False.
|
|
1126
1140
|
protobuf_net_annotation (bool, optional): Use protobuf-net annotations. Defaults to False.
|
|
1127
1141
|
"""
|
|
@@ -1135,6 +1149,7 @@ def convert_avro_to_csharp(
|
|
|
1135
1149
|
avrotocs.newtonsoft_json_annotation = newtonsoft_json_annotation
|
|
1136
1150
|
avrotocs.system_xml_annotation = system_xml_annotation
|
|
1137
1151
|
avrotocs.msgpack_annotation = msgpack_annotation
|
|
1152
|
+
avrotocs.cbor_annotation = cbor_annotation
|
|
1138
1153
|
avrotocs.avro_annotation = avro_annotation
|
|
1139
1154
|
avrotocs.protobuf_net_annotation = protobuf_net_annotation
|
|
1140
1155
|
avrotocs.convert(avro_schema_path, cs_file_path)
|
|
@@ -1150,6 +1165,7 @@ def convert_avro_schema_to_csharp(
|
|
|
1150
1165
|
newtonsoft_json_annotation: bool = False,
|
|
1151
1166
|
system_xml_annotation: bool = False,
|
|
1152
1167
|
msgpack_annotation: bool = False,
|
|
1168
|
+
cbor_annotation: bool = False,
|
|
1153
1169
|
avro_annotation: bool = False,
|
|
1154
1170
|
protobuf_net_annotation: bool = False
|
|
1155
1171
|
):
|
|
@@ -1165,6 +1181,7 @@ def convert_avro_schema_to_csharp(
|
|
|
1165
1181
|
newtonsoft_json_annotation (bool, optional): Use Newtonsoft.Json annotations. Defaults to False.
|
|
1166
1182
|
system_xml_annotation (bool, optional): Use System.Xml.Serialization annotations. Defaults to False.
|
|
1167
1183
|
msgpack_annotation (bool, optional): Use MessagePack annotations. Defaults to False.
|
|
1184
|
+
cbor_annotation (bool, optional): Use Dahomey.Cbor annotations. Defaults to False.
|
|
1168
1185
|
avro_annotation (bool, optional): Use Avro annotations. Defaults to False.
|
|
1169
1186
|
protobuf_net_annotation (bool, optional): Use protobuf-net annotations. Defaults to False.
|
|
1170
1187
|
"""
|
|
@@ -1175,6 +1192,7 @@ def convert_avro_schema_to_csharp(
|
|
|
1175
1192
|
avrotocs.newtonsoft_json_annotation = newtonsoft_json_annotation
|
|
1176
1193
|
avrotocs.system_xml_annotation = system_xml_annotation
|
|
1177
1194
|
avrotocs.msgpack_annotation = msgpack_annotation
|
|
1195
|
+
avrotocs.cbor_annotation = cbor_annotation
|
|
1178
1196
|
avrotocs.avro_annotation = avro_annotation
|
|
1179
1197
|
avrotocs.protobuf_net_annotation = protobuf_net_annotation
|
|
1180
1198
|
avrotocs.convert_schema(avro_schema, output_dir)
|
|
@@ -184,16 +184,38 @@ class AvroToJsonSchemaConverter:
|
|
|
184
184
|
def handle_type_union(self, types: List[Union[str, Dict[str, Any]]]) -> Dict[str, Any] | List[Dict[str, Any]| str] | str:
|
|
185
185
|
"""
|
|
186
186
|
Handle Avro type unions, returning a JSON schema that validates against any of the types.
|
|
187
|
+
Preserves nullability from Avro unions containing 'null'.
|
|
187
188
|
"""
|
|
189
|
+
is_nullable = 'null' in types
|
|
188
190
|
non_null_types = [t for t in types if t != 'null']
|
|
191
|
+
|
|
189
192
|
if len(non_null_types) == 1:
|
|
190
|
-
# Single non-null type
|
|
191
|
-
|
|
193
|
+
# Single non-null type - check if it's a primitive that can use type array
|
|
194
|
+
single_type = non_null_types[0]
|
|
195
|
+
json_schema = self.parse_avro_schema(single_type)
|
|
196
|
+
|
|
197
|
+
if is_nullable and isinstance(json_schema, dict):
|
|
198
|
+
# For primitives with a simple 'type' field, we can use type array notation
|
|
199
|
+
if 'type' in json_schema and isinstance(json_schema['type'], str) and '$ref' not in json_schema:
|
|
200
|
+
# Primitive type - add null to type array
|
|
201
|
+
json_schema = copy.deepcopy(json_schema)
|
|
202
|
+
json_schema['type'] = [json_schema['type'], 'null']
|
|
203
|
+
elif '$ref' in json_schema:
|
|
204
|
+
# Reference type - use oneOf with null
|
|
205
|
+
json_schema = {
|
|
206
|
+
'oneOf': [
|
|
207
|
+
{'type': 'null'},
|
|
208
|
+
json_schema
|
|
209
|
+
]
|
|
210
|
+
}
|
|
211
|
+
return json_schema
|
|
192
212
|
else:
|
|
193
213
|
# Multiple non-null types
|
|
194
|
-
union_types = [self.convert_reference(t) if isinstance(t,str) and t in self.defined_types else self.avro_primitive_to_json_type(t)
|
|
214
|
+
union_types = [self.convert_reference(t) if isinstance(t, str) and t in self.defined_types else self.avro_primitive_to_json_type(t)
|
|
195
215
|
if isinstance(t, str) else self.parse_avro_schema(t)
|
|
196
216
|
for t in non_null_types]
|
|
217
|
+
if is_nullable:
|
|
218
|
+
union_types.insert(0, {'type': 'null'})
|
|
197
219
|
return {
|
|
198
220
|
'oneOf': union_types
|
|
199
221
|
}
|
|
@@ -1255,6 +1255,8 @@
|
|
|
1255
1255
|
"system_text_json_annotation": "args.system_text_json_annotation",
|
|
1256
1256
|
"newtonsoft_json_annotation": "args.newtonsoft_json_annotation",
|
|
1257
1257
|
"system_xml_annotation": "args.system_xml_annotation",
|
|
1258
|
+
"msgpack_annotation": "args.msgpack_annotation",
|
|
1259
|
+
"cbor_annotation": "args.cbor_annotation",
|
|
1258
1260
|
"pascal_properties": "args.pascal_properties",
|
|
1259
1261
|
"base_namespace": "args.namespace"
|
|
1260
1262
|
}
|
|
@@ -1323,6 +1325,20 @@
|
|
|
1323
1325
|
"default": false,
|
|
1324
1326
|
"required": false
|
|
1325
1327
|
},
|
|
1328
|
+
{
|
|
1329
|
+
"name": "--msgpack-annotation",
|
|
1330
|
+
"type": "bool",
|
|
1331
|
+
"help": "Use MessagePack annotations",
|
|
1332
|
+
"default": false,
|
|
1333
|
+
"required": false
|
|
1334
|
+
},
|
|
1335
|
+
{
|
|
1336
|
+
"name": "--cbor-annotation",
|
|
1337
|
+
"type": "bool",
|
|
1338
|
+
"help": "Use Dahomey.Cbor annotations",
|
|
1339
|
+
"default": false,
|
|
1340
|
+
"required": false
|
|
1341
|
+
},
|
|
1326
1342
|
{
|
|
1327
1343
|
"name": "--pascal-properties",
|
|
1328
1344
|
"type": "bool",
|
|
@@ -1375,6 +1391,7 @@
|
|
|
1375
1391
|
"system_text_json_annotation": "args.system_text_json_annotation",
|
|
1376
1392
|
"newtonsoft_json_annotation": "args.newtonsoft_json_annotation",
|
|
1377
1393
|
"system_xml_annotation": "args.system_xml_annotation",
|
|
1394
|
+
"avro_annotation": "args.avro_annotation",
|
|
1378
1395
|
"pascal_properties": "args.pascal_properties",
|
|
1379
1396
|
"base_namespace": "args.namespace",
|
|
1380
1397
|
"project_name": "args.project_name"
|
|
@@ -1437,6 +1454,13 @@
|
|
|
1437
1454
|
"default": false,
|
|
1438
1455
|
"required": false
|
|
1439
1456
|
},
|
|
1457
|
+
{
|
|
1458
|
+
"name": "--avro-annotation",
|
|
1459
|
+
"type": "bool",
|
|
1460
|
+
"help": "Use Avro annotations",
|
|
1461
|
+
"default": false,
|
|
1462
|
+
"required": false
|
|
1463
|
+
},
|
|
1440
1464
|
{
|
|
1441
1465
|
"name": "--pascal-properties",
|
|
1442
1466
|
"type": "bool",
|
|
@@ -1468,6 +1492,13 @@
|
|
|
1468
1492
|
"default": false,
|
|
1469
1493
|
"required": false
|
|
1470
1494
|
},
|
|
1495
|
+
{
|
|
1496
|
+
"name": "--avro-annotation",
|
|
1497
|
+
"message": "Use Avro annotations?",
|
|
1498
|
+
"type": "bool",
|
|
1499
|
+
"default": false,
|
|
1500
|
+
"required": false
|
|
1501
|
+
},
|
|
1471
1502
|
{
|
|
1472
1503
|
"name": "--pascal-properties",
|
|
1473
1504
|
"message": "Use PascalCase properties?",
|
|
@@ -70,6 +70,11 @@ try:
|
|
|
70
70
|
except ValueError:
|
|
71
71
|
MSGPACK_VERSION = '2.5.187'
|
|
72
72
|
|
|
73
|
+
try:
|
|
74
|
+
CBOR_VERSION = get_dependency_version('cs', 'net90', 'Dahomey.Cbor')
|
|
75
|
+
except ValueError:
|
|
76
|
+
CBOR_VERSION = '1.25.1'
|
|
77
|
+
|
|
73
78
|
# Java test dependencies
|
|
74
79
|
try:
|
|
75
80
|
JUNIT_VERSION = get_dependency_version('java', 'jdk21', 'org.junit.jupiter:junit-jupiter-api')
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
<PackageReference Include="System.Memory.Data" Version="9.0.3" />
|
|
19
19
|
<PackageReference Include="protobuf-net" Version="3.2.30" />
|
|
20
20
|
<PackageReference Include="MessagePack" Version="3.1.4" />
|
|
21
|
+
<PackageReference Include="Dahomey.Cbor" Version="1.25.1" />
|
|
21
22
|
</ItemGroup>
|
|
22
23
|
|
|
23
24
|
<!-- Testing -->
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
{%- if
|
|
1
|
+
{%- if avro_annotation %}
|
|
2
|
+
/// <summary>
|
|
3
|
+
/// The Avro schema for this class
|
|
4
|
+
/// </summary>
|
|
5
|
+
private static readonly Avro.Schema AvroSchema = Avro.Schema.Parse("{{ avro_schema_json }}");
|
|
6
|
+
{%- endif %}
|
|
7
|
+
|
|
8
|
+
{%- if system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation or avro_annotation %}
|
|
2
9
|
/// <summary>
|
|
3
10
|
/// Creates an object from the data
|
|
4
11
|
/// </summary>
|
|
@@ -11,7 +18,7 @@
|
|
|
11
18
|
if ( data is {{ class_name }}) return ({{ class_name }})data;
|
|
12
19
|
if ( contentTypeString == null ) contentTypeString = System.Net.Mime.MediaTypeNames.Application.Octet;
|
|
13
20
|
var contentType = new System.Net.Mime.ContentType(contentTypeString);
|
|
14
|
-
{%- if system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation %}
|
|
21
|
+
{%- if system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation or avro_annotation %}
|
|
15
22
|
if ( contentType.MediaType.EndsWith("+gzip"))
|
|
16
23
|
{
|
|
17
24
|
var stream = data switch
|
|
@@ -92,12 +99,72 @@
|
|
|
92
99
|
return ({{ class_name }}?)serializer.Deserialize(memoryStream);
|
|
93
100
|
}
|
|
94
101
|
}
|
|
102
|
+
{%- endif %}
|
|
103
|
+
{%- if avro_annotation %}
|
|
104
|
+
if ( contentType.MediaType == "avro/binary" || contentType.MediaType == "application/vnd.apache.avro+avro")
|
|
105
|
+
{
|
|
106
|
+
if (data is byte[])
|
|
107
|
+
{
|
|
108
|
+
using (var stream = new System.IO.MemoryStream((byte[])data))
|
|
109
|
+
{
|
|
110
|
+
var reader = new Avro.Generic.GenericDatumReader<Avro.Generic.GenericRecord>(AvroSchema, AvroSchema);
|
|
111
|
+
var decoder = new Avro.IO.BinaryDecoder(stream);
|
|
112
|
+
var record = reader.Read(null, decoder);
|
|
113
|
+
return FromAvroRecord(record);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else if (data is System.IO.Stream)
|
|
117
|
+
{
|
|
118
|
+
var reader = new Avro.Generic.GenericDatumReader<Avro.Generic.GenericRecord>(AvroSchema, AvroSchema);
|
|
119
|
+
var decoder = new Avro.IO.BinaryDecoder((System.IO.Stream)data);
|
|
120
|
+
var record = reader.Read(null, decoder);
|
|
121
|
+
return FromAvroRecord(record);
|
|
122
|
+
}
|
|
123
|
+
else if (data is System.BinaryData)
|
|
124
|
+
{
|
|
125
|
+
using (var stream = new System.IO.MemoryStream(((System.BinaryData)data).ToArray()))
|
|
126
|
+
{
|
|
127
|
+
var reader = new Avro.Generic.GenericDatumReader<Avro.Generic.GenericRecord>(AvroSchema, AvroSchema);
|
|
128
|
+
var decoder = new Avro.IO.BinaryDecoder(stream);
|
|
129
|
+
var record = reader.Read(null, decoder);
|
|
130
|
+
return FromAvroRecord(record);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
95
134
|
{%- endif %}
|
|
96
135
|
throw new System.NotSupportedException($"Unsupported media type {contentType.MediaType}");
|
|
97
136
|
}
|
|
98
137
|
{%- endif %}
|
|
99
138
|
|
|
100
|
-
{%- if
|
|
139
|
+
{%- if avro_annotation %}
|
|
140
|
+
/// <summary>
|
|
141
|
+
/// Creates an instance from an Avro GenericRecord
|
|
142
|
+
/// </summary>
|
|
143
|
+
/// <param name="record">The Avro record</param>
|
|
144
|
+
/// <returns>The converted object</returns>
|
|
145
|
+
/// <remarks>
|
|
146
|
+
/// This method uses JSON as an intermediate format for conversion. This approach works well
|
|
147
|
+
/// for simple types but may have limitations with complex Avro union types that use
|
|
148
|
+
/// different JSON encoding than System.Text.Json. For complex schemas with unions,
|
|
149
|
+
/// consider implementing custom mapping logic directly from GenericRecord properties.
|
|
150
|
+
/// </remarks>
|
|
151
|
+
private static {{ class_name }}? FromAvroRecord(Avro.Generic.GenericRecord record)
|
|
152
|
+
{
|
|
153
|
+
// Convert Avro record to JSON and then deserialize
|
|
154
|
+
// This approach works for simple cases; for complex types, you may need custom mapping
|
|
155
|
+
using (var jsonStream = new System.IO.MemoryStream())
|
|
156
|
+
{
|
|
157
|
+
var jsonEncoder = new Avro.IO.JsonEncoder(AvroSchema, jsonStream);
|
|
158
|
+
var writer = new Avro.Generic.GenericDatumWriter<Avro.Generic.GenericRecord>(AvroSchema);
|
|
159
|
+
writer.Write(record, jsonEncoder);
|
|
160
|
+
jsonEncoder.Flush();
|
|
161
|
+
jsonStream.Position = 0;
|
|
162
|
+
return System.Text.Json.JsonSerializer.Deserialize<{{ class_name }}>(jsonStream);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
{%- endif %}
|
|
166
|
+
|
|
167
|
+
{%- if system_text_json_annotation or newtonsoft_json_annotation or system_xml_annotation or avro_annotation %}
|
|
101
168
|
/// <summary>
|
|
102
169
|
/// Converts the object to a byte array
|
|
103
170
|
/// </summary>
|
|
@@ -138,6 +205,20 @@
|
|
|
138
205
|
}
|
|
139
206
|
}
|
|
140
207
|
}
|
|
208
|
+
{%- endif %}
|
|
209
|
+
{%- if avro_annotation %}
|
|
210
|
+
if (contentType.MediaType == "avro/binary" || contentType.MediaType == "application/vnd.apache.avro+avro")
|
|
211
|
+
{
|
|
212
|
+
using (var stream = new System.IO.MemoryStream())
|
|
213
|
+
{
|
|
214
|
+
var record = ToAvroRecord();
|
|
215
|
+
var writer = new Avro.Generic.GenericDatumWriter<Avro.Generic.GenericRecord>(AvroSchema);
|
|
216
|
+
var encoder = new Avro.IO.BinaryEncoder(stream);
|
|
217
|
+
writer.Write(record, encoder);
|
|
218
|
+
encoder.Flush();
|
|
219
|
+
result = stream.ToArray();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
141
222
|
{%- endif %}
|
|
142
223
|
if ( result == null ) throw new System.NotSupportedException($"Unsupported media type {contentType.MediaType}");
|
|
143
224
|
if ( contentType.MediaType.EndsWith("+gzip"))
|
|
@@ -154,3 +235,29 @@
|
|
|
154
235
|
return result;
|
|
155
236
|
}
|
|
156
237
|
{%- endif %}
|
|
238
|
+
|
|
239
|
+
{%- if avro_annotation %}
|
|
240
|
+
/// <summary>
|
|
241
|
+
/// Converts this object to an Avro GenericRecord
|
|
242
|
+
/// </summary>
|
|
243
|
+
/// <returns>The Avro record</returns>
|
|
244
|
+
/// <remarks>
|
|
245
|
+
/// This method uses JSON as an intermediate format for conversion. This approach works well
|
|
246
|
+
/// for simple types but may have limitations with complex types containing unions, as
|
|
247
|
+
/// Avro's JSON encoding for unions differs from System.Text.Json's encoding. For complex
|
|
248
|
+
/// schemas with unions or other advanced Avro features, consider implementing custom
|
|
249
|
+
/// mapping logic directly to GenericRecord properties.
|
|
250
|
+
/// </remarks>
|
|
251
|
+
private Avro.Generic.GenericRecord ToAvroRecord()
|
|
252
|
+
{
|
|
253
|
+
// Convert to JSON first, then use Avro's JSON decoder
|
|
254
|
+
// This approach works for simple cases; for complex types, you may need custom mapping
|
|
255
|
+
var jsonBytes = System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(this, this.GetType());
|
|
256
|
+
using (var jsonStream = new System.IO.MemoryStream(jsonBytes))
|
|
257
|
+
{
|
|
258
|
+
var decoder = new Avro.IO.JsonDecoder(AvroSchema, jsonStream);
|
|
259
|
+
var reader = new Avro.Generic.GenericDatumReader<Avro.Generic.GenericRecord>(AvroSchema, AvroSchema);
|
|
260
|
+
return reader.Read(reuse: null, decoder);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
{%- endif %}
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
{%- if system_text_json_annotation %}
|
|
12
12
|
<PackageReference Include="System.Text.Json" Version="{{ SYSTEM_TEXT_JSON_VERSION }}" />
|
|
13
13
|
{%- endif %}
|
|
14
|
+
{%- if avro_annotation %}
|
|
15
|
+
<PackageReference Include="Apache.Avro" Version="{{ CSHARP_AVRO_VERSION }}" />
|
|
16
|
+
{%- endif %}
|
|
14
17
|
<PackageReference Include="System.Memory.Data" Version="{{ SYSTEM_MEMORY_DATA_VERSION }}" />
|
|
15
18
|
</ItemGroup>
|
|
16
19
|
</Project>
|