You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@avro.apache.org by William McKenzie <ws...@cartewright.com> on 2015/09/28 20:43:37 UTC

Re: Weird problem with 'bool' on OS/X

Anyone have any ideas on this?

I can get around the problem by providing a custom codec_traits for
std::vector of bool:

#ifdef __APPLE__
namespace avro {
    static void encode(avro::Encoder& e, const std::vector<bool>& b) {
        e.arrayStart();
        if (! b.empty()) {
            e.setItemCount(b.size());
            for (bool val : b ) {
                e.startItem();
                avro::encode(e, val);
            }
        }
        e.arrayEnd();
    }
}
#endif

But why is it required only on OS/X? I've seen some posts that hint at it
being related to the fact that a vector of bools are special because they
can be packed various ways?

On Thu, Jun 18, 2015 at 12:32 PM, William McKenzie <wsmckenz@cartewright.com
> wrote:

> Hi guys,
>
> Funny problem with c++ encoding, only on OS/X. Works fine on any other OS.
> Everything encodes fine except 'bool'.
>
> #include "avro/Specific.hh"
> #include "avro/Encoder.hh"
> #include "avro/Decoder.hh"
>
> struct ArrayOfBoolean{
> std::vector<bool> m_values;
> };
>
> static void encode(avro::Encoder& e, const ArrayOfBoolean& v) {
> avro::encode(e, v.m_values);
> }
> static void decode(avro::Decoder& e, ArrayOfBoolean& v) {
> avro::decode(e, v.m_values);
> }
>
> int main(int argC, char ** argV)
> {
> return 0;
> }
>
>
> etp-cpp wsmckenz$ g++ test.cpp -I/usr/local/include -I/opt/local/include
>
> In file included from test.cpp:8:
>
> */usr/local/include/avro/Specific.hh:297:22: **error: **no member named
> 'encode' in*
>
> *
> 'avro::codec_traits<std::__1::__bit_const_reference<std::__1::vector<bool,*
>
> *      std::__1::allocator<bool> > > >'*
>
>     codec_traits<T>::encode(e, t);
>
> *    ~~~~~~~~~~~~~~~~~^*
>
> */usr/local/include/avro/Specific.hh:232:23: note: *in instantiation of
> function
>
>       template specialization
>
>       'avro::encode<std::__1::__bit_const_reference<std::__1::vector<bool,
>
>       std::__1::allocator<bool> > > >' requested here
>
>                 avro::encode(e, *it);
>
> *                      ^*
>
> */usr/local/include/avro/Specific.hh:297:22: note: *in instantiation of
> member
>
>       function 'avro::codec_traits<std::__1::vector<bool,
>
>       std::__1::allocator<bool> > >::encode' requested here
>
>     codec_traits<T>::encode(e, t);
>
> *                     ^*
>
> *test.cpp:17:8: note: *in instantiation of function template
> specialization
>
>       'avro::encode<std::__1::vector<bool, std::__1::allocator<bool> > >'
>
>       requested here
>
>         avro::encode(e, v.m_values);
>
> *              ^*
>
> 1 error generated.
>
> any ideas?
>
> cheers,
> ~Bill
>