2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to you under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14
* implied. See the License for the specific language governing
15
* permissions and limitations under the License.
24
#include "avro_private.h"
27
/*-- PROCESSING A FILE --*/
30
process_file(const char *filename)
32
avro_file_reader_t reader;
36
if (filename == NULL) {
41
fp = fopen(filename, "rb");
45
fprintf(stderr, "Error opening %s:\n %s\n",
46
filename, strerror(errno));
51
if (avro_file_reader_fp(fp, filename, 0, &reader)) {
52
fprintf(stderr, "Error opening %s:\n %s\n",
53
filename, avro_strerror());
60
avro_schema_t wschema;
61
avro_value_iface_t *iface;
64
wschema = avro_file_reader_get_writer_schema(reader);
65
iface = avro_generic_class_from_schema(wschema);
66
avro_generic_value_new(iface, &value);
70
while ((rval = avro_file_reader_read_value(reader, &value)) == 0) {
73
if (avro_value_to_json(&value, 1, &json)) {
74
fprintf(stderr, "Error converting value to JSON: %s\n",
81
avro_value_reset(&value);
84
// If it was not an EOF that caused it to fail,
87
fprintf(stderr, "Error: %s\n", avro_strerror());
90
avro_file_reader_close(reader);
91
avro_value_decref(&value);
92
avro_value_iface_decref(iface);
93
avro_schema_decref(wschema);
101
/*-- MAIN PROGRAM --*/
103
static void usage(void)
106
"Usage: avrocat <avro data file>\n");
110
int main(int argc, char **argv)
115
data_filename = argv[1];
116
} else if (argc == 1) {
117
data_filename = NULL;
119
fprintf(stderr, "Can't read from multiple input files.\n");
124
/* Process the data file */
125
process_file(data_filename);