thrift-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "J W (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (THRIFT-4722) Netcore union "data" should be strongly-typed
Date Sat, 05 Jan 2019 04:03:00 GMT

     [ https://issues.apache.org/jira/browse/THRIFT-4722?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

J W updated THRIFT-4722:
------------------------
    Description: 
Following thrift:
```thrift
struct PlayMsg

{ 1: string url, }

union RequestMsg

{ 1: PlayMsg Play, }

```

Generates:
{code:java}
public abstract partial class RequestMsg : TAbstractBase {
public abstract void Write(TProtocol protocol);
public readonly bool Isset;
public abstract object Data { get; }
protected RequestMsg(bool isset) {
Isset = isset;
}

// SNIP

public class Play : RequestMsg {
private PlayMsg _data;
public override object Data { get { return _data; } }
public Play(PlayMsg data) : base(true) {
this._data = data;
}
//SNIP{code}
Usage:
{code:java}
// RequestMsg message = ...
switch (message)
{
case RequestMsg.Play msg:
    // Need a cast here T_T
    PlayMsg play = (PlayMsg)msg.Data;
{code}
If we get rid of that and instead generate a strongly-type getter we don't need to cast `Data`:
{code:java}
public class Play : RequestMsg{ 
    public PlayMsg Data { get; private set; }
    public Play(PlayMsg data) : base(true)
    { this.Data = data; }
//SNIP
{code}
 

> Netcore union "data" should be strongly-typed
> ---------------------------------------------
>
>                 Key: THRIFT-4722
>                 URL: https://issues.apache.org/jira/browse/THRIFT-4722
>             Project: Thrift
>          Issue Type: Improvement
>          Components: netcore - Compiler
>    Affects Versions: 0.12.0
>            Reporter: J W
>            Priority: Minor
>
> Following thrift:
> ```thrift
> struct PlayMsg
> { 1: string url, }
> union RequestMsg
> { 1: PlayMsg Play, }
> ```
> Generates:
> {code:java}
> public abstract partial class RequestMsg : TAbstractBase {
> public abstract void Write(TProtocol protocol);
> public readonly bool Isset;
> public abstract object Data { get; }
> protected RequestMsg(bool isset) {
> Isset = isset;
> }
> // SNIP
> public class Play : RequestMsg {
> private PlayMsg _data;
> public override object Data { get { return _data; } }
> public Play(PlayMsg data) : base(true) {
> this._data = data;
> }
> //SNIP{code}
> Usage:
> {code:java}
> // RequestMsg message = ...
> switch (message)
> {
> case RequestMsg.Play msg:
>     // Need a cast here T_T
>     PlayMsg play = (PlayMsg)msg.Data;
> {code}
> If we get rid of that and instead generate a strongly-type getter we don't need to cast
`Data`:
> {code:java}
> public class Play : RequestMsg{ 
>     public PlayMsg Data { get; private set; }
>     public Play(PlayMsg data) : base(true)
>     { this.Data = data; }
> //SNIP
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message