Thorbenl opened a new pull request, #279:
URL: https://github.com/apache/pulsar-dotpulsar/pull/279

   ## Summary
   
   Implements `ISchema<T>` for JSON and Protobuf message types, addressing #254.
   
   - **`JsonSchema<T>`**: Serializes/deserializes using `System.Text.Json`. 
Supports optional `JsonSerializerOptions` for customization and an optional 
JSON schema definition string for broker-side schema compatibility checking. 
Uses `SchemaType.Json`.
   - **`ProtobufSchema<T>`**: Constrained to `Google.Protobuf.IMessage<T>`. 
Uses native protobuf serialization with `SchemaType.ProtobufNative` (type 20). 
Extracts the file descriptor from the message type as schema data. No new 
dependencies — `Google.Protobuf` is already a project dependency.
   - **`Schema.Json<T>()` and `Schema.Protobuf<T>()`** factory methods added to 
`Schema.cs`, following the existing pattern for `AvroISpecificRecord<T>()` and 
`AvroGenericRecord<T>()`.
   - Added inner exception constructor to `SchemaSerializationException` to 
properly wrap serialization errors (matching `SchemaException` which already 
has this overload).
   - Added `System.Text.Json` package reference for `netstandard2.0` and 
`netstandard2.1` targets only (already part of the BCL for `net8.0`+).
   
   ### Design decisions worth discussing
   
   1. **`ProtobufNative` (type 20) vs `Protobuf` (type 3)**: We chose 
`ProtobufNative` which uses the native protobuf file descriptor as schema data. 
This is the more modern approach. Type 3 (`Protobuf`) uses Avro-encoded schema 
representation, which would require an Avro dependency. Happy to adjust if the 
maintainers prefer type 3.
   
   2. **JSON schema data**: The default constructor sends empty schema data 
(matching how primitive schemas like `BooleanSchema` work). An overload 
accepting a schema definition string is available for broker-side schema 
evolution checking. Auto-generation of JSON Schema from the type could be added 
in a follow-up.
   
   3. **`IMessage<T>` disambiguation**: `Google.Protobuf.IMessage<T>` is fully 
qualified in the constraint to avoid ambiguity with 
`DotPulsar.Abstractions.IMessage<T>`.
   
   ## Test plan
   
   - [x] 12 unit tests for `JsonSchema<T>` (round-trip, camelCase options, 
schema definition, empty bytes error handling)
   - [x] 9 unit tests for `ProtobufSchema<T>` (round-trip with `StringValue` 
and `Int32Value`, empty message, empty bytes, schema info)
   - [x] All 21 new tests pass
   - [x] All 224 existing tests still pass (1 pre-existing 
`ZstdCompressionTests` failure unrelated to this change)
   - [x] Solution builds with 0 warnings, 0 errors across all 5 target 
frameworks
   
   Fix #254


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to