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

ASF GitHub Bot commented on AVRO-1941:
--------------------------------------

GitHub user moriarty opened a pull request:

    https://github.com/apache/avro/pull/147

    AVRO-1941: C++: adds __SCHEMA__ in generated code

    This adds an ```avro::ValidSchema __SCHEMA__``` to each generated struct.
    
    ```__SCHEMA__``` is initialized in constructor using 
```avro::compileJsonSchemaFromString```.
    
    This is a proposal for convenient way to access a schema similar to the 
generated Java classes, which have:
    ```
    public static final org.apache.avro.Schema SCHEMA$ = new 
org.apache.avro.Schema.Parser().parse(...);
    public static org.apache.avro.Schema getClassSchema() {return SCHEMA$; }
    ```
    
    This is a proposal and doesn't add ```__SCHEMA__``` to enums, which the 
Java generated classes do have. I couldn't think of a c++ way to do that, and 
am still waiting on feedback for 
[AVRO-1940](https://issues.apache.org/jira/browse/AVRO-1940) or GH 
apache/avro#146

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/moriarty/avro 
avro-1941/cpp-include-schema-in-generated-structs/dev

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/avro/pull/147.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #147
    
----
commit 945b60106b1f775afceb5006575c52e9af893f97
Author: Alexander Moriarty <[email protected]>
Date:   2016-10-25T11:50:49Z

    AVRO-1941: C++: adds __SCHEMA__ in generated code
    
    This adds an avro::ValidSchema __SCHEMA__ to each generated struct.
    
    __SCHEMA__ is initialized in constructor using 
avro::compileJsonSchemaFromString.
    
    This is a proposal for convenient way to access a schema similar to the 
generated Java classes, which have:
    ```
    public static final org.apache.avro.Schema SCHEMA$ = new 
org.apache.avro.Schema.Parser().parse(...);
    public static org.apache.avro.Schema getClassSchema() {return SCHEMA$; }
    ```
    
    This is a proposal and doesn't add __SCHEMA__ to enums, which the Java 
generated classes do have. I couldn't think of a c++ way to do that, and am 
still waiting on feedback for AVRO-1940 or GH apache/avro#146

----


> avrogencpp: unlike java, c++ generated code doesn't include own schema
> ----------------------------------------------------------------------
>
>                 Key: AVRO-1941
>                 URL: https://issues.apache.org/jira/browse/AVRO-1941
>             Project: Avro
>          Issue Type: Improvement
>          Components: c++
>    Affects Versions: 1.8.1
>            Reporter: Alexander Moriarty
>
> All the classes generated for java include a copy of their schema. The C++ 
> classes do not.
> Every generated java class has getClassSchema().
> Something similar for C++ would be convenient.
> During generation, the schema is available with n->printJson(..) which can 
> then be passed through boost::algorithm::erase_all() to remove whitespace and 
> new lines, and then boost::algorithm::replace_all() to add escape characters 
> back.
> and then given to avro::compileJsonSchemaFromString



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

Reply via email to