[prev in list] [next in list] [prev in thread] [next in thread]
List: avro-dev
Subject: [jira] [Commented] (AVRO-523) records with the same name as a member generate bad c++ code
From: "peter liu (JIRA)" <jira () apache ! org>
Date: 2015-08-30 19:11:46
Message-ID: JIRA.12462801.1271959608000.205877.1440961906094 () Atlassian ! JIRA
[Download RAW message or body]
[ https://issues.apache.org/jira/browse/AVRO-523?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14721681#comment-14721681 \
]
peter liu commented on AVRO-523:
--------------------------------
LiuYanbos-MacBook:build liuyanbo$ cat test.hh
{code:cpp}
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TEST_HH_1533535760__H_
#define TEST_HH_1533535760__H_
#include <sstream>
#include "boost/any.hpp"
#include "avro/Specific.hh"
#include "avro/Encoder.hh"
#include "avro/Decoder.hh"
struct l {
int64_t l;
l() :
l(int64_t())
{ }
};
struct r {
int64_t r;
r() :
r(int64_t())
{ }
};
struct test_json_Union__0__ {
private:
size_t idx_;
boost::any value_;
public:
size_t idx() const { return idx_; }
l get_l() const;
void set_l(const l& v);
r get_r() const;
void set_r(const r& v);
test_json_Union__0__();
};
inline
l test_json_Union__0__::get_l() const {
if (idx_ != 0) {
throw avro::Exception("Invalid type for union");
}
return boost::any_cast<l >(value_);
}
inline
void test_json_Union__0__::set_l(const l& v) {
idx_ = 0;
value_ = v;
}
inline
r test_json_Union__0__::get_r() const {
if (idx_ != 1) {
throw avro::Exception("Invalid type for union");
}
return boost::any_cast<r >(value_);
}
inline
void test_json_Union__0__::set_r(const r& v) {
idx_ = 1;
value_ = v;
}
inline test_json_Union__0__::test_json_Union__0__() : idx_(0), value_(l()) { }
namespace avro {
template<> struct codec_traits<l> {
static void encode(Encoder& e, const l& v) {
avro::encode(e, v.l);
}
static void decode(Decoder& d, l& v) {
if (avro::ResolvingDecoder *rd =
dynamic_cast<avro::ResolvingDecoder *>(&d)) {
const std::vector<size_t> fo = rd->fieldOrder();
for (std::vector<size_t>::const_iterator it = fo.begin();
it != fo.end(); ++it) {
switch (*it) {
case 0:
avro::decode(d, v.l);
break;
default:
break;
}
}
} else {
avro::decode(d, v.l);
}
}
};
template<> struct codec_traits<r> {
static void encode(Encoder& e, const r& v) {
avro::encode(e, v.r);
}
static void decode(Decoder& d, r& v) {
if (avro::ResolvingDecoder *rd =
dynamic_cast<avro::ResolvingDecoder *>(&d)) {
const std::vector<size_t> fo = rd->fieldOrder();
for (std::vector<size_t>::const_iterator it = fo.begin();
it != fo.end(); ++it) {
switch (*it) {
case 0:
avro::decode(d, v.r);
break;
default:
break;
}
}
} else {
avro::decode(d, v.r);
}
}
};
template<> struct codec_traits<test_json_Union__0__> {
static void encode(Encoder& e, test_json_Union__0__ v) {
e.encodeUnionIndex(v.idx());
switch (v.idx()) {
case 0:
avro::encode(e, v.get_l());
break;
case 1:
avro::encode(e, v.get_r());
break;
}
}
static void decode(Decoder& d, test_json_Union__0__& v) {
size_t n = d.decodeUnionIndex();
if (n >= 2) { throw avro::Exception("Union index too big"); }
switch (n) {
case 0:
{
l vv;
avro::decode(d, vv);
v.set_l(vv);
}
break;
case 1:
{
r vv;
avro::decode(d, vv);
v.set_r(vv);
}
break;
}
}
};
}
#endif
{code}
> records with the same name as a member generate bad c++ code
> ------------------------------------------------------------
>
> Key: AVRO-523
> URL: https://issues.apache.org/jira/browse/AVRO-523
> Project: Avro
> Issue Type: Bug
> Components: c++
> Reporter: John Plevyak
>
> records with the same name as a member generate bad c++ code:
> {code}
> {
> "type" : "array",
> "name" : "optionals",
> "items" : [
> { "name" : "l", "type" : "record", "fields" : [ { "name" : "l", "type": "long"} ] \
> }, { "name" : "r", "type" : "record", "fields" : [ { "name" : "r", "type": "long"} \
> ] } ]
> }
> {code}
> produces c++ code such that when it is compiled it produces:
> union2.h:42: error: field 'int64_t avrouser::l::l' with same name as class
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic