This repository was archived by the owner on Dec 5, 2017. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 11#include < avro/Specific.hh>
22#include < avro/Encoder.hh>
33#include < avro/Decoder.hh>
4+ #include " utils.h"
45
56#pragma once
67
@@ -89,6 +90,44 @@ namespace csi
8990 return content_length1;
9091 }
9192
93+ // encodes fingerprint first in 16 bytes
94+ template <class T >
95+ void avro_binary_encode_with_schema (const T& src, avro::OutputStream& dst)
96+ {
97+ avro::EncoderPtr e = avro::binaryEncoder ();
98+ e->init (dst);
99+ avro::encode (*e, to_array (src.schema_hash ())); // you need to generate your classes with csi_avrogencpp - it adds this method
100+ avro::encode (*e, src);
101+ // push back unused characters to the output stream again... really strange...
102+ // otherwise content_length will be a multiple of 4096
103+ e->flush ();
104+ }
105+
106+ template <class T >
107+ bool avro_binary_decode_with_schema (std::auto_ptr<avro::InputStream> src, T& dst)
108+ {
109+ boost::array<uint8_t , 16 > schema_id;
110+
111+ avro::DecoderPtr e = avro::binaryDecoder ();
112+ e->init (*src);
113+ avro::decode (*e, schema_id);
114+ if (dst.schema_hash () != to_uuid (schema_id)) // you need to generate your classes with csi_avrogencpp - it adds this method
115+ {
116+ return false ;
117+ }
118+
119+ try
120+ {
121+ avro::decode (*e, dst);
122+ }
123+ catch (...)
124+ {
125+ return false ;
126+ }
127+ return true ;
128+ }
129+
130+
92131 template <class T >
93132 T& avro_binary_decode (const char * buffer, size_t size, T& dst)
94133 {
You can’t perform that action at this time.
0 commit comments