[ 
https://issues.apache.org/jira/browse/THRIFT-2067?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14904671#comment-14904671
 ] 

Konrad Grochowski commented on THRIFT-2067:
-------------------------------------------

"internal structures" are also normal structs and they can be treated similary 
:) - especially, printing them might help debugging/logging operations.

as for making printing virtual and extendable/overridable - sound like a good 
plan, those are not protocol related methods so nobody should care about 
`virtual` keyword ;)

just remember - introducing new method added to generated classes will break 
some people code (for example for those who use `print` field), AFAIR you had 
such problems with methd `what` in exceptions, so please think carefully about 
name for that virtual function (`toString`? `printTo`? something that shall not 
sound like field name :) )

good luck :)

> Thrift objects should have a default string representation
> ----------------------------------------------------------
>
>                 Key: THRIFT-2067
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2067
>             Project: Thrift
>          Issue Type: Improvement
>          Components: C++ - Compiler, C++ - Library
>            Reporter: Vitali Lovich
>            Assignee: Konrad Grochowski
>             Fix For: 0.9.2
>
>
> Just like thrift objects implement a custom toString in Java, there should be 
> an inline friend function that writes a text representation of the struct to 
> a std::ostream.  Probably makes sense for the text representation to be 
> similar to C++:
> {code}
> class MyThriftClass {
>     friend std::ostream& operator<<(std::ostream& o, MyThriftClass) {
>         o << "MyThriftClass[";
>         o << "field1=" << field1;
>         if (__isset.field2) {
>              o << ", field2=" << field2;
>         }
>         o << ", list1=" << apache::thrift::util::to_string(list1);
>         return o << "]";
>     }
>     // ...
> }
> {code}
> There will also probably be a util.h file to include that implements generic 
> template to_string for lists, maps, & sets.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to