fsprojects / pulsar-client-dotnet

Apache Pulsar native client for .NET (C#/F#/VB)
MIT License
301 stars 47 forks source link

DateTime is not supported when using Protobuf native schema #194

Closed RobertIndie closed 2 years ago

RobertIndie commented 2 years ago

We found a problem with F# client parsing protobuf native with DateTime type field. In the F# client, the VirtualFile implementation only supports reading a single proto file, but not other dependent proto files. Here is the current VirtualFile implementation:

type VirtualFile(content:string)=
    member private this.Content = content
    interface IFileSystem with
        member this.Exists _ = true
        member this.OpenText _ =
            new StringReader(this.Content) :> TextReader

As an example, if we use the following class to generate a protobuf definition.

[ProtoContract]
class SimpleProtoRecordV1
{
    [ProtoMember(1, IsRequired = true), Required]
    public string Name { get; set; }
    [ProtoMember(2), DefaultValue(30)]
    public int Age { get; set; }
    [ProtoMember(3, IsRequired = false)]
    [CompatibilityLevel(CompatibilityLevel.Level300)]
    public DateTime Time { get; set; }
}

The DateTime type depends on /google/protobuf/timestamp.proto, so the FileDescriptorSet will try to read /google/protobuf/timestamp.proto from the VirtualFile, but the wrong VirtualFile implementation causes it to return only the original SimpleProtoRecordV1 protobuf definition, making /google/protobuf/timestamp.proto's dependency is still itself. This causes a stack overflow on the broker side when parsing this circular dependency.

I have created a PR to fix this problem: https://github.com/fsharplang-ru/pulsar-client-dotnet/pull/195