[ https://issues.apache.org/jira/browse/THRIFT-5840?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17903768#comment-17903768 ]
Jens Geyer commented on THRIFT-5840: ------------------------------------ Do you have a use case for this? Given the above decls what would I do with them? And how do I make sure that a {{PagedList<T>}} or a {{Nullable<T>}} supplies the necessary minimum to fit into the serialization system? I use C++ as an example, but it applies to most if not all: {code} virtual uint32_t read(protocol::TProtocol* iprot) = 0; virtual uint32_t write(protocol::TProtocol* oprot) const = 0; {code} In certain languages that behaviour could be by changing the expected argument type from TBase (or the equivalent of it) into an interface, which must be implemented by whatever T is to satisfy the requirement. So that part seems possible and not too hard. Now we can read and write arbitrary data structures. Let's take a closer look on what we achieved: * We produced an API that is no longer described by its IDL alone plus the implicit contract around, baked into the existing type system and protocols. * Instead, we need something extra to describe the parts we just added. For example, what the wire layout of a Nullable<T> might be. Without that extra knowledge, nobody is able to read the data, fully or in parts. * These extra knowledge/algorithms must be manually implemented by anyone who wants to communicate with your API and happens to use some language you do not publicly support. Each implementation should also be thoroughly tested and validated, which requires more extra work. * It becomes also quite easy, to create data formats that introduce subtle security issues due to bad design and/or implementation. Once you debug the case it might become obvious, who's to blame, but the first fingerpointing will almost always go into Thrift direction. Surely not the kind of publicity one wants to have. Thoughts? > Add support for custom generic types (definition time) > ------------------------------------------------------ > > Key: THRIFT-5840 > URL: https://issues.apache.org/jira/browse/THRIFT-5840 > Project: Thrift > Issue Type: Improvement > Components: Compiler (General) > Affects Versions: 0.21.0 > Reporter: Konstantin > Priority: Major > > It would be great to have custom generics support. (Like existing set<> > list<>) > Generics probably should exist only in definition & compilation time. For > example: > {code:c#} > // definiton > struct PagedList<T> > { > 1: list<T> Collection > 2: i32 PageSize > 3: i64 PageNumber > 4: i64 TotalCount > } > struct Nullable<T> > { > 1: T Value > } > // usage > enum SomeTypes > { > Type1 = 1 > Type2 = 2 > } > struct Data > { > 1: string Name > 2: i32 Age > 3: string Blabla > } > service AService > { > PagedList<Nullable<SomeTypes>> GetPagedTypes (1: i64 pageNumber, 2: i32 > pageSize) // etc > PagedList<Data> GetPagedData(1: i64 pageNumber, 2: i32 pageSize) > } > {code} > that would generate generic types where it is possible, and types like > PagedListData (or DataPagedList etc) in case if there is no generics support. > Right now it's required to define those PagedListData manually, which is > annoying and requires some extra effort. > What do you think? -- This message was sent by Atlassian Jira (v8.20.10#820010)