You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by ma...@apache.org on 2009/10/15 20:00:26 UTC
svn commit: r825593 [1/3] - in /hadoop/avro/trunk/src/c: ./
avro_schema_tests/ avro_schema_tests/fail/ avro_schema_tests/pass/ json/
json/fail/ json/pass/ json_tests/ json_tests/fail/ json_tests/pass/
Author: massie
Date: Thu Oct 15 18:00:21 2009
New Revision: 825593
URL: http://svn.apache.org/viewvc?rev=825593&view=rev
Log:
Added a validating Avro schema parser in C
Added:
hadoop/avro/trunk/src/c/avro_boolean.c
hadoop/avro/trunk/src/c/avro_bytes.c
hadoop/avro/trunk/src/c/avro_endian.c
hadoop/avro/trunk/src/c/avro_enum.c
hadoop/avro/trunk/src/c/avro_file_container.c
hadoop/avro/trunk/src/c/avro_fixed.c
hadoop/avro/trunk/src/c/avro_float.c
hadoop/avro/trunk/src/c/avro_int.c
hadoop/avro/trunk/src/c/avro_io_file.c
hadoop/avro/trunk/src/c/avro_io_memory.c
hadoop/avro/trunk/src/c/avro_io_socket.c
hadoop/avro/trunk/src/c/avro_long.c
hadoop/avro/trunk/src/c/avro_map.c
hadoop/avro/trunk/src/c/avro_null.c
hadoop/avro/trunk/src/c/avro_primitives.c
hadoop/avro/trunk/src/c/avro_private.h
hadoop/avro/trunk/src/c/avro_record.c
hadoop/avro/trunk/src/c/avro_schema_tests/
hadoop/avro/trunk/src/c/avro_schema_tests/fail/
hadoop/avro/trunk/src/c/avro_schema_tests/fail/enum_nonarray_symbols
hadoop/avro/trunk/src/c/avro_schema_tests/fail/enum_nonstring_name
hadoop/avro/trunk/src/c/avro_schema_tests/fail/enum_without_name
hadoop/avro/trunk/src/c/avro_schema_tests/fail/fixed_without_name
hadoop/avro/trunk/src/c/avro_schema_tests/fail/fixed_without_size
hadoop/avro/trunk/src/c/avro_schema_tests/fail/illegal_type
hadoop/avro/trunk/src/c/avro_schema_tests/fail/record_with_field_missing_name
hadoop/avro/trunk/src/c/avro_schema_tests/fail/record_with_field_missing_type
hadoop/avro/trunk/src/c/avro_schema_tests/fail/record_with_nonarray_fields
hadoop/avro/trunk/src/c/avro_schema_tests/fail/record_with_nonstring_name
hadoop/avro/trunk/src/c/avro_schema_tests/pass/
hadoop/avro/trunk/src/c/avro_schema_tests/pass/array
hadoop/avro/trunk/src/c/avro_schema_tests/pass/boolean_full
hadoop/avro/trunk/src/c/avro_schema_tests/pass/bytes_full
hadoop/avro/trunk/src/c/avro_schema_tests/pass/double_full
hadoop/avro/trunk/src/c/avro_schema_tests/pass/enum
hadoop/avro/trunk/src/c/avro_schema_tests/pass/extra_attributes
hadoop/avro/trunk/src/c/avro_schema_tests/pass/fixed
hadoop/avro/trunk/src/c/avro_schema_tests/pass/float_full
hadoop/avro/trunk/src/c/avro_schema_tests/pass/int_full
hadoop/avro/trunk/src/c/avro_schema_tests/pass/long_full
hadoop/avro/trunk/src/c/avro_schema_tests/pass/map
hadoop/avro/trunk/src/c/avro_schema_tests/pass/null_full
hadoop/avro/trunk/src/c/avro_schema_tests/pass/record
hadoop/avro/trunk/src/c/avro_schema_tests/pass/record_fields_with_defaults
hadoop/avro/trunk/src/c/avro_schema_tests/pass/recursive_record
hadoop/avro/trunk/src/c/avro_schema_tests/pass/string_full
hadoop/avro/trunk/src/c/avro_schema_tests/pass/union
hadoop/avro/trunk/src/c/avro_type.gperf
hadoop/avro/trunk/src/c/avro_union.c
hadoop/avro/trunk/src/c/avro_value.c
hadoop/avro/trunk/src/c/container_of.h
hadoop/avro/trunk/src/c/json_parser.y
hadoop/avro/trunk/src/c/json_tests/
hadoop/avro/trunk/src/c/json_tests/README
hadoop/avro/trunk/src/c/json_tests/fail/
hadoop/avro/trunk/src/c/json_tests/fail/array_not_closed
hadoop/avro/trunk/src/c/json_tests/fail/array_not_opened
hadoop/avro/trunk/src/c/json_tests/fail/bad_value
hadoop/avro/trunk/src/c/json_tests/fail/colon_instead_of_comma
hadoop/avro/trunk/src/c/json_tests/fail/comma_after_close
hadoop/avro/trunk/src/c/json_tests/fail/comma_instead_of_colon
hadoop/avro/trunk/src/c/json_tests/fail/double_colon
hadoop/avro/trunk/src/c/json_tests/fail/extra_close
hadoop/avro/trunk/src/c/json_tests/fail/extra_data_after_object
hadoop/avro/trunk/src/c/json_tests/fail/illegal_expression
hadoop/avro/trunk/src/c/json_tests/fail/illegal_invocation
hadoop/avro/trunk/src/c/json_tests/fail/invalid_number
hadoop/avro/trunk/src/c/json_tests/fail/invalid_number2
hadoop/avro/trunk/src/c/json_tests/fail/invalid_number3
hadoop/avro/trunk/src/c/json_tests/fail/invalid_number4
hadoop/avro/trunk/src/c/json_tests/fail/json_text_not_array_or_object
hadoop/avro/trunk/src/c/json_tests/fail/line_break_in_string
hadoop/avro/trunk/src/c/json_tests/fail/line_break_in_string2
hadoop/avro/trunk/src/c/json_tests/fail/missing_colon
hadoop/avro/trunk/src/c/json_tests/fail/naked_array_value
hadoop/avro/trunk/src/c/json_tests/fail/object_array_mismatch
hadoop/avro/trunk/src/c/json_tests/fail/object_malformed
hadoop/avro/trunk/src/c/json_tests/fail/object_not_closed
hadoop/avro/trunk/src/c/json_tests/fail/object_not_opened
hadoop/avro/trunk/src/c/json_tests/fail/object_with_string
hadoop/avro/trunk/src/c/json_tests/fail/object_without_one_value
hadoop/avro/trunk/src/c/json_tests/fail/single_quote
hadoop/avro/trunk/src/c/json_tests/fail/string_bad_u1_value
hadoop/avro/trunk/src/c/json_tests/fail/string_bad_u2_value
hadoop/avro/trunk/src/c/json_tests/fail/string_bad_u3_value
hadoop/avro/trunk/src/c/json_tests/fail/string_bad_u4_value
hadoop/avro/trunk/src/c/json_tests/fail/string_illegal_escape
hadoop/avro/trunk/src/c/json_tests/fail/tab_char_in_string
hadoop/avro/trunk/src/c/json_tests/fail/tab_character_in_string
hadoop/avro/trunk/src/c/json_tests/fail/unquoted_object_key
hadoop/avro/trunk/src/c/json_tests/pass/
hadoop/avro/trunk/src/c/json_tests/pass/array_multidimensional
hadoop/avro/trunk/src/c/json_tests/pass/array_with_false
hadoop/avro/trunk/src/c/json_tests/pass/array_with_ints
hadoop/avro/trunk/src/c/json_tests/pass/array_with_null
hadoop/avro/trunk/src/c/json_tests/pass/array_with_objects
hadoop/avro/trunk/src/c/json_tests/pass/array_with_string
hadoop/avro/trunk/src/c/json_tests/pass/array_with_true
hadoop/avro/trunk/src/c/json_tests/pass/deep
hadoop/avro/trunk/src/c/json_tests/pass/empty_array
hadoop/avro/trunk/src/c/json_tests/pass/empty_object
hadoop/avro/trunk/src/c/json_tests/pass/json_org_example1
hadoop/avro/trunk/src/c/json_tests/pass/json_org_example2
hadoop/avro/trunk/src/c/json_tests/pass/json_org_example3
hadoop/avro/trunk/src/c/json_tests/pass/json_org_test1
hadoop/avro/trunk/src/c/json_tests/pass/object_with_duplicate_keys
hadoop/avro/trunk/src/c/json_tests/pass/object_with_false
hadoop/avro/trunk/src/c/json_tests/pass/object_with_multiple_members
hadoop/avro/trunk/src/c/json_tests/pass/object_with_null
hadoop/avro/trunk/src/c/json_tests/pass/object_with_object_member
hadoop/avro/trunk/src/c/json_tests/pass/object_with_one_member
hadoop/avro/trunk/src/c/json_tests/pass/object_with_true
hadoop/avro/trunk/src/c/json_tests/pass/rfc_example
hadoop/avro/trunk/src/c/json_tests/pass/rfc_example2
hadoop/avro/trunk/src/c/json_tests/pass/string_u_value
hadoop/avro/trunk/src/c/test_avro_interop.c
hadoop/avro/trunk/src/c/test_avro_schema.c
Removed:
hadoop/avro/trunk/src/c/avro_file.c
hadoop/avro/trunk/src/c/avro_memory.c
hadoop/avro/trunk/src/c/avro_raw.c
hadoop/avro/trunk/src/c/avro_socket.c
hadoop/avro/trunk/src/c/avro_zigzag.c
hadoop/avro/trunk/src/c/json/README
hadoop/avro/trunk/src/c/json/fail/array_not_closed
hadoop/avro/trunk/src/c/json/fail/array_not_opened
hadoop/avro/trunk/src/c/json/fail/bad_value
hadoop/avro/trunk/src/c/json/fail/colon_instead_of_comma
hadoop/avro/trunk/src/c/json/fail/comma_after_close
hadoop/avro/trunk/src/c/json/fail/comma_instead_of_colon
hadoop/avro/trunk/src/c/json/fail/double_colon
hadoop/avro/trunk/src/c/json/fail/extra_close
hadoop/avro/trunk/src/c/json/fail/extra_data_after_object
hadoop/avro/trunk/src/c/json/fail/illegal_expression
hadoop/avro/trunk/src/c/json/fail/illegal_invocation
hadoop/avro/trunk/src/c/json/fail/invalid_number
hadoop/avro/trunk/src/c/json/fail/invalid_number2
hadoop/avro/trunk/src/c/json/fail/invalid_number3
hadoop/avro/trunk/src/c/json/fail/invalid_number4
hadoop/avro/trunk/src/c/json/fail/json_text_not_array_or_object
hadoop/avro/trunk/src/c/json/fail/line_break_in_string
hadoop/avro/trunk/src/c/json/fail/line_break_in_string2
hadoop/avro/trunk/src/c/json/fail/missing_colon
hadoop/avro/trunk/src/c/json/fail/naked_array_value
hadoop/avro/trunk/src/c/json/fail/object_array_mismatch
hadoop/avro/trunk/src/c/json/fail/object_malformed
hadoop/avro/trunk/src/c/json/fail/object_not_closed
hadoop/avro/trunk/src/c/json/fail/object_not_opened
hadoop/avro/trunk/src/c/json/fail/object_with_string
hadoop/avro/trunk/src/c/json/fail/object_without_one_value
hadoop/avro/trunk/src/c/json/fail/single_quote
hadoop/avro/trunk/src/c/json/fail/string_bad_u1_value
hadoop/avro/trunk/src/c/json/fail/string_bad_u2_value
hadoop/avro/trunk/src/c/json/fail/string_bad_u3_value
hadoop/avro/trunk/src/c/json/fail/string_bad_u4_value
hadoop/avro/trunk/src/c/json/fail/string_illegal_escape
hadoop/avro/trunk/src/c/json/fail/tab_char_in_string
hadoop/avro/trunk/src/c/json/fail/tab_character_in_string
hadoop/avro/trunk/src/c/json/fail/unquoted_object_key
hadoop/avro/trunk/src/c/json/pass/array_multidimensional
hadoop/avro/trunk/src/c/json/pass/array_with_false
hadoop/avro/trunk/src/c/json/pass/array_with_ints
hadoop/avro/trunk/src/c/json/pass/array_with_null
hadoop/avro/trunk/src/c/json/pass/array_with_objects
hadoop/avro/trunk/src/c/json/pass/array_with_string
hadoop/avro/trunk/src/c/json/pass/array_with_true
hadoop/avro/trunk/src/c/json/pass/deep
hadoop/avro/trunk/src/c/json/pass/empty_array
hadoop/avro/trunk/src/c/json/pass/empty_object
hadoop/avro/trunk/src/c/json/pass/json_org_example1
hadoop/avro/trunk/src/c/json/pass/json_org_example2
hadoop/avro/trunk/src/c/json/pass/json_org_example3
hadoop/avro/trunk/src/c/json/pass/json_org_test1
hadoop/avro/trunk/src/c/json/pass/object_with_duplicate_keys
hadoop/avro/trunk/src/c/json/pass/object_with_false
hadoop/avro/trunk/src/c/json/pass/object_with_multiple_members
hadoop/avro/trunk/src/c/json/pass/object_with_null
hadoop/avro/trunk/src/c/json/pass/object_with_object_member
hadoop/avro/trunk/src/c/json/pass/object_with_one_member
hadoop/avro/trunk/src/c/json/pass/object_with_true
hadoop/avro/trunk/src/c/json/pass/rfc_example
hadoop/avro/trunk/src/c/json/pass/rfc_example2
hadoop/avro/trunk/src/c/json/pass/string_u_value
hadoop/avro/trunk/src/c/json_schema.y
hadoop/avro/trunk/src/c/test_avro_bytes.c
hadoop/avro/trunk/src/c/test_avro_float_double.c
hadoop/avro/trunk/src/c/test_avro_raw.c
hadoop/avro/trunk/src/c/test_avro_string.c
hadoop/avro/trunk/src/c/test_avro_zigzag.c
Modified:
hadoop/avro/trunk/src/c/.gitignore
hadoop/avro/trunk/src/c/INSTALL
hadoop/avro/trunk/src/c/Makefile.am
hadoop/avro/trunk/src/c/avro.c
hadoop/avro/trunk/src/c/avro.h
hadoop/avro/trunk/src/c/avro_array.c
hadoop/avro/trunk/src/c/avro_double.c
hadoop/avro/trunk/src/c/avro_string.c
hadoop/avro/trunk/src/c/json.c
hadoop/avro/trunk/src/c/json.h
hadoop/avro/trunk/src/c/json_tokenizer.h
hadoop/avro/trunk/src/c/test_json_parser.c
Modified: hadoop/avro/trunk/src/c/.gitignore
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/.gitignore?rev=825593&r1=825592&r2=825593&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/.gitignore (original)
+++ hadoop/avro/trunk/src/c/.gitignore Thu Oct 15 18:00:21 2009
@@ -4,3 +4,5 @@
config
config.h.in
configure
+*.lo
+*.o
Modified: hadoop/avro/trunk/src/c/INSTALL
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/INSTALL?rev=825593&r1=825592&r2=825593&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/INSTALL (original)
+++ hadoop/avro/trunk/src/c/INSTALL Thu Oct 15 18:00:21 2009
@@ -1,19 +1,16 @@
Installation Instructions
*************************
-Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005,
-2006, 2007, 2008 Free Software Foundation, Inc.
+Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005 Free
+Software Foundation, Inc.
- This file is free documentation; the Free Software Foundation gives
+This file is free documentation; the Free Software Foundation gives
unlimited permission to copy, distribute and modify it.
Basic Installation
==================
- Briefly, the shell commands `./configure; make; make install' should
-configure, build, and install this package. The following
-more-detailed instructions are generic; see the `README' file for
-instructions specific to this package.
+These are generic installation instructions.
The `configure' shell script attempts to guess correct values for
various system-dependent variables used during compilation. It uses
@@ -26,9 +23,9 @@
It can also use an optional file (typically called `config.cache'
and enabled with `--cache-file=config.cache' or simply `-C') that saves
-the results of its tests to speed up reconfiguring. Caching is
+the results of its tests to speed up reconfiguring. (Caching is
disabled by default to prevent problems with accidental use of stale
-cache files.
+cache files.)
If you need to do unusual things to compile the package, please try
to figure out how `configure' could check whether to do them, and mail
@@ -38,17 +35,20 @@
may remove or edit it.
The file `configure.ac' (or `configure.in') is used to create
-`configure' by a program called `autoconf'. You need `configure.ac' if
-you want to change it or regenerate `configure' using a newer version
-of `autoconf'.
+`configure' by a program called `autoconf'. You only need
+`configure.ac' if you want to change it or regenerate `configure' using
+a newer version of `autoconf'.
The simplest way to compile this package is:
1. `cd' to the directory containing the package's source code and type
- `./configure' to configure the package for your system.
+ `./configure' to configure the package for your system. If you're
+ using `csh' on an old version of System V, you might need to type
+ `sh ./configure' instead to prevent `csh' from trying to execute
+ `configure' itself.
- Running `configure' might take a while. While running, it prints
- some messages telling which features it is checking for.
+ Running `configure' takes awhile. While running, it prints some
+ messages telling which features it is checking for.
2. Type `make' to compile the package.
@@ -67,57 +67,42 @@
all sorts of other programs in order to regenerate files that came
with the distribution.
- 6. Often, you can also type `make uninstall' to remove the installed
- files again.
-
Compilers and Options
=====================
- Some systems require unusual options for compilation or linking that
-the `configure' script does not know about. Run `./configure --help'
-for details on some of the pertinent environment variables.
+Some systems require unusual options for compilation or linking that the
+`configure' script does not know about. Run `./configure --help' for
+details on some of the pertinent environment variables.
You can give `configure' initial values for configuration parameters
by setting variables in the command line or in the environment. Here
is an example:
- ./configure CC=c99 CFLAGS=-g LIBS=-lposix
+ ./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
*Note Defining Variables::, for more details.
Compiling For Multiple Architectures
====================================
- You can compile the package for more than one kind of computer at the
+You can compile the package for more than one kind of computer at the
same time, by placing the object files for each architecture in their
-own directory. To do this, you can use GNU `make'. `cd' to the
+own directory. To do this, you must use a version of `make' that
+supports the `VPATH' variable, such as GNU `make'. `cd' to the
directory where you want the object files and executables to go and run
the `configure' script. `configure' automatically checks for the
source code in the directory that `configure' is in and in `..'.
- With a non-GNU `make', it is safer to compile the package for one
-architecture at a time in the source code directory. After you have
-installed the package for one architecture, use `make distclean' before
-reconfiguring for another architecture.
-
- On MacOS X 10.5 and later systems, you can create libraries and
-executables that work on multiple system types--known as "fat" or
-"universal" binaries--by specifying multiple `-arch' options to the
-compiler but only a single `-arch' option to the preprocessor. Like
-this:
-
- ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
- CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
- CPP="gcc -E" CXXCPP="g++ -E"
-
- This is not guaranteed to produce working output in all cases, you
-may have to build one architecture at a time and combine the results
-using the `lipo' tool if you have problems.
+ If you have to use a `make' that does not support the `VPATH'
+variable, you have to compile the package for one architecture at a
+time in the source code directory. After you have installed the
+package for one architecture, use `make distclean' before reconfiguring
+for another architecture.
Installation Names
==================
- By default, `make install' installs the package's commands under
+By default, `make install' installs the package's commands under
`/usr/local/bin', include files under `/usr/local/include', etc. You
can specify an installation prefix other than `/usr/local' by giving
`configure' the option `--prefix=PREFIX'.
@@ -140,7 +125,7 @@
Optional Features
=================
- Some packages pay attention to `--enable-FEATURE' options to
+Some packages pay attention to `--enable-FEATURE' options to
`configure', where FEATURE indicates an optional part of the package.
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
is something like `gnu-as' or `x' (for the X Window System). The
@@ -152,36 +137,14 @@
you can use the `configure' options `--x-includes=DIR' and
`--x-libraries=DIR' to specify their locations.
-Particular systems
-==================
-
- On HP-UX, the default C compiler is not ANSI C compatible. If GNU
-CC is not installed, it is recommended to use the following options in
-order to use an ANSI C compiler:
-
- ./configure CC="cc -Ae"
-
-and if that doesn't work, install pre-built binaries of GCC for HP-UX.
-
- On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot
-parse its `<wchar.h>' header file. The option `-nodtk' can be used as
-a workaround. If GNU CC is not installed, it is therefore recommended
-to try
-
- ./configure CC="cc"
-
-and if that doesn't work, try
-
- ./configure CC="cc -nodtk"
-
Specifying the System Type
==========================
- There may be some features `configure' cannot figure out
-automatically, but needs to determine by the type of machine the package
-will run on. Usually, assuming the package is built to be run on the
-_same_ architectures, `configure' can figure that out, but if it prints
-a message saying it cannot guess the machine type, give it the
+There may be some features `configure' cannot figure out automatically,
+but needs to determine by the type of machine the package will run on.
+Usually, assuming the package is built to be run on the _same_
+architectures, `configure' can figure that out, but if it prints a
+message saying it cannot guess the machine type, give it the
`--build=TYPE' option. TYPE can either be a short name for the system
type, such as `sun4', or a canonical name which has the form:
@@ -207,9 +170,9 @@
Sharing Defaults
================
- If you want to set default values for `configure' scripts to share,
-you can create a site shell script called `config.site' that gives
-default values for variables like `CC', `cache_file', and `prefix'.
+If you want to set default values for `configure' scripts to share, you
+can create a site shell script called `config.site' that gives default
+values for variables like `CC', `cache_file', and `prefix'.
`configure' looks for `PREFIX/share/config.site' if it exists, then
`PREFIX/etc/config.site' if it exists. Or, you can set the
`CONFIG_SITE' environment variable to the location of the site script.
@@ -218,7 +181,7 @@
Defining Variables
==================
- Variables not defined in a site shell script can be set in the
+Variables not defined in a site shell script can be set in the
environment passed to `configure'. However, some packages may run
configure again during the build, and the customized values of these
variables may be lost. In order to avoid this problem, you should set
@@ -227,29 +190,21 @@
./configure CC=/usr/local2/bin/gcc
causes the specified `gcc' to be used as the C compiler (unless it is
-overridden in the site shell script).
+overridden in the site shell script). Here is a another example:
-Unfortunately, this technique does not work for `CONFIG_SHELL' due to
-an Autoconf bug. Until the bug is fixed you can use this workaround:
+ /bin/bash ./configure CONFIG_SHELL=/bin/bash
- CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash
+Here the `CONFIG_SHELL=/bin/bash' operand causes subsequent
+configuration-related scripts to be executed by `/bin/bash'.
`configure' Invocation
======================
- `configure' recognizes the following options to control how it
-operates.
+`configure' recognizes the following options to control how it operates.
`--help'
`-h'
- Print a summary of all of the options to `configure', and exit.
-
-`--help=short'
-`--help=recursive'
- Print a summary of the options unique to this package's
- `configure', and exit. The `short' variant lists options used
- only in the top level, while the `recursive' variant lists options
- also present in any nested packages.
+ Print a summary of the options to `configure', and exit.
`--version'
`-V'
@@ -276,16 +231,6 @@
Look for the package's source code in directory DIR. Usually
`configure' can determine that directory automatically.
-`--prefix=DIR'
- Use DIR as the installation prefix. *Note Installation Names::
- for more details, including other options available for fine-tuning
- the installation locations.
-
-`--no-create'
-`-n'
- Run the configure checks, but stop before creating any output
- files.
-
`configure' also accepts some other, not widely useful, options. Run
`configure --help' for more details.
Modified: hadoop/avro/trunk/src/c/Makefile.am
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/Makefile.am?rev=825593&r1=825592&r2=825593&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/Makefile.am (original)
+++ hadoop/avro/trunk/src/c/Makefile.am Thu Oct 15 18:00:21 2009
@@ -1,48 +1,44 @@
-AM_CFLAGS=$(APR_CFLAGS) $(APR_INCLUDES) $(APU_INCLUDES) -Wall -pedantic
+# -pedantic
+AM_CFLAGS=$(APR_CFLAGS) $(APR_INCLUDES) $(APU_INCLUDES) -Wall
C_DOCS_OUTPUT ?= "docs/dox"
-EXTRA_DIST=json_schema.y lemon.c lempar.c
+EXTRA_DIST=json_parser.y lemon.c lempar.c json_tests
include_HEADERS = avro.h
lib_LTLIBRARIES = libavro.la
-libavro_la_SOURCES = avro_memory.c avro_socket.c avro_file.c \
-dump.c dump.h avro.c avro_string.c avro_zigzag.c error.c error.h avro_raw.c \
-avro_double.c json_schema.c json_schema.h json_tokenizer.c json.c json.h \
-json_tokenizer.h
+libavro_la_SOURCES = avro.h avro_private.h avro.c \
+json_parser.c json_parser.h json_tokenizer.c json.c json.h json_tokenizer.h \
+dump.c dump.h error.c error.h avro_value.c \
+avro_array.c avro_boolean.c avro_bytes.c avro_double.c avro_enum.c avro_fixed.c \
+avro_float.c avro_int.c avro_long.c avro_map.c avro_null.c \
+avro_record.c avro_string.c avro_union.c container_of.h \
+avro_io_file.c avro_io_socket.c avro_io_memory.c \
+avro_file_container.c avro_endian.c avro_primitives.c
-check_PROGRAMS=test_avro_zigzag test_avro_string test_avro_bytes test_avro_raw \
-test_avro_float_double test_json_parser
+check_PROGRAMS=test_json_parser test_avro_schema
lemon: $(top_srcdir)/lemon.c $(top_srcdir)/lempar.c
$(CC) -o $@ $(top_srcdir)/lemon.c
-cp $(top_srcdir)/lempar.c .
-json_schema.c json_shema.h: $(top_srcdir)/json_schema.y lemon
- -cp $(top_srcdir)/json_schema.y .
- ./lemon json_schema.y
+json_parser.c json_shema.h: $(top_srcdir)/json_parser.y lemon
+ -cp $(top_srcdir)/json_parser.y .
+ ./lemon json_parser.y
-# Make sure to generate the json_schema in the source directory before distribution
-dist-hook: json_schema.h json_schema.c
- cp -r $(srcdir)/json $(distdir)
+# Make sure to generate the json_parser in the source directory before distribution
+dist-hook: json_parser.h json_parser.c
-test_avro_zigzag_SOURCE=test_avro_zigzag.c
-test_avro_zigzag_LDADD=$(APR_LIBS) $(APU_LIBS) $(top_builddir)/libavro.la
+test_LDADD=$(APR_LIBS) $(APU_LIBS) $(top_builddir)/libavro.la
-test_avro_string_SOURCE=test_avro_string.c
-test_avro_string_LDADD=$(APR_LIBS) $(APU_LIBS) $(top_builddir)/libavro.la
-
-test_avro_bytes_SOURCE=test_avro_bytes.c
-test_avro_bytes_LDADD=$(APR_LIBS) $(APU_LIBS) $(top_builddir)/libavro.la
-
-test_avro_raw_SOURCE=test_avro_raw.c
-test_avro_raw_LDADD=$(APR_LIBS) $(APU_LIBS) $(top_builddir)/libavro.la
+test_json_parser=test_json_parser.c
+test_json_parser_LDADD=$(test_LDADD)
-test_avro_float_double_SOURCE=test_avro_float_double.c
-test_avro_float_double_LDADD=$(APR_LIBS) $(APU_LIBS) $(top_builddir)/libavro.la
+test_avro_schema=test_avro_schema.c
+test_avro_schema_LDADD=$(test_LDADD)
-test_json_parser=test_json_parser.c
-test_json_parser_LDADD=$(APR_LIBS) $(APU_LIBS) $(top_builddir)/libavro.la
+#test_avro_interop=test_avro_interop.c
+#test_avro_interop_LDADD=$(test_LDADD)
TESTS=$(check_PROGRAMS)
@@ -67,4 +63,4 @@
.PHONY: docs
-CLEANFILES=$(top_srcdir)/*~ trace.txt json_schema.out lemon
+CLEANFILES=$(top_srcdir)/*~ trace.txt json_parser.out lemon
Modified: hadoop/avro/trunk/src/c/avro.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/avro.c?rev=825593&r1=825592&r2=825593&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/avro.c (original)
+++ hadoop/avro/trunk/src/c/avro.c Thu Oct 15 18:00:21 2009
@@ -17,43 +17,173 @@
under the License.
*/
+#include "avro_private.h"
#include <stdlib.h>
#include <locale.h>
-#include "avro.h"
+#include "apr_pools.h"
+#include "apr_file_io.h"
+#include "apr_file_info.h"
-avro_status_t
-avro_null (void)
+static struct avro_type_entry
{
- /* Do nothing */
- return AVRO_OK;
+ const avro_string_t name;
+ const avro_type_t type;
+} avro_type_lookup_table[] =
+{
+ {
+ L"string", AVRO_STRING},
+ {
+ L"bytes", AVRO_BYTES},
+ {
+ L"int", AVRO_INT},
+ {
+ L"long", AVRO_LONG},
+ {
+ L"float", AVRO_FLOAT},
+ {
+ L"double", AVRO_DOUBLE},
+ {
+ L"boolean", AVRO_BOOLEAN},
+ {
+ L"null", AVRO_NULL},
+ {
+ L"record", AVRO_RECORD},
+ {
+ L"enum", AVRO_ENUM},
+ {
+ L"fixed", AVRO_FIXED},
+ {
+ L"map", AVRO_MAP},
+ {
+ L"array", AVRO_ARRAY},
+ {
+ L"union", AVRO_UNION}
+};
+
+#define NUM_AVRO_NODE_TYPES (sizeof(avro_type_lookup_table)/sizeof(avro_type_lookup_table[0]))
+
+/* TODO: gperf this */
+const avro_type_t *
+avro_type_lookup (const avro_string_t name)
+{
+ int i;
+ if (name)
+ {
+ for (i = 0; i < NUM_AVRO_NODE_TYPES; i++)
+ {
+ const struct avro_type_entry *entry = avro_type_lookup_table + i;
+ if (wcscmp (entry->name, name) == 0)
+ {
+ return &entry->type;
+ }
+ }
+ }
+ return NULL;
}
-avro_status_t
-avro_bool (AVRO * avro, bool_t * bp)
+const avro_type_t *
+avro_type_from_json (const JSON_value * json)
{
- avro_status_t status;
- char b;
- if (!avro || !bp)
+ const avro_type_t *avro_type = NULL;
+ const static avro_type_t union_type = AVRO_UNION;
+ const JSON_value *type_attr;
+
+ if (!json)
{
- return AVRO_FAILURE;
+ return NULL;
}
- switch (avro->a_op)
+
+ if (json->type == JSON_STRING)
{
- case AVRO_ENCODE:
- {
- b = *bp ? 1 : 0;
- return AVRO_PUTBYTES (avro, &b, 1);
- }
- case AVRO_DECODE:
- {
- status = AVRO_GETBYTES (avro, &b, 1);
- CHECK_ERROR (status);
- *bp = b ? 1 : 0;
- }
- default:
- return AVRO_FAILURE;
+ avro_type = avro_type_lookup (json->json_string);
}
- return AVRO_OK;
+ else if (json->type == JSON_ARRAY)
+ {
+ avro_type = &union_type;
+ }
+ else if (json->type == JSON_OBJECT)
+ {
+ type_attr = json_attr_get_check_type (json, L"type", JSON_STRING);
+ if (!type_attr)
+ {
+ return NULL;
+ }
+ avro_type = avro_type_lookup (type_attr->json_string);
+ }
+
+ return avro_type;
+}
+
+char *
+avro_util_file_read_full (apr_pool_t * pool, const char *fname,
+ apr_size_t * len)
+{
+ apr_status_t status;
+ apr_finfo_t finfo;
+ apr_file_t *file;
+ char *rval;
+ apr_size_t bytes_read;
+
+ /* open the file */
+ status = apr_file_open (&file, fname, APR_READ, 0, pool);
+ if (status != APR_SUCCESS)
+ {
+ return NULL;
+ }
+
+ /* get the file length */
+ status = apr_file_info_get (&finfo, APR_FINFO_SIZE, file);
+ if (status != APR_SUCCESS)
+ {
+ return NULL;
+ }
+
+ /* alloc space for the data */
+ rval = apr_palloc (pool, finfo.size + 1);
+ if (!rval)
+ {
+ return NULL;
+ }
+
+ /* read in the data */
+ status = apr_file_read_full (file, rval, finfo.size, &bytes_read);
+ if (status != APR_SUCCESS)
+ {
+ return NULL;
+ }
+ rval[finfo.size] = '\0';
+
+ if (len)
+ {
+ *len = bytes_read;
+ }
+ return rval;
+}
+
+/* Helper utility for reading an attribute from a JSON object */
+const JSON_value *
+json_attr_get (const JSON_value * obj, const wchar_t * key)
+{
+ apr_ssize_t klen;
+ apr_hash_t *table;
+
+ if (!obj || !key || obj->type != JSON_OBJECT)
+ {
+ return NULL;
+ }
+
+ table = obj->json_object;
+ klen = wcslen (key) * sizeof (wchar_t);
+ return apr_hash_get (table, key, klen);
+}
+
+/* Helper utility for reading an attribute from JSON w/type checking */
+const JSON_value *
+json_attr_get_check_type (const JSON_value * obj, const wchar_t * key,
+ JSON_type type)
+{
+ const JSON_value *value = json_attr_get (obj, key);
+ return value && value->type == type ? value : NULL;
}
avro_status_t
@@ -70,3 +200,14 @@
return AVRO_OK;
}
+
+/* Helper to print indent before a value */
+void
+avro_value_indent (struct avro_value *value, FILE * fp)
+{
+ struct avro_value *cur;
+ for (cur = value->parent; cur; cur = cur->parent)
+ {
+ fprintf (fp, " ");
+ }
+}
Modified: hadoop/avro/trunk/src/c/avro.h
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/avro.h?rev=825593&r1=825592&r2=825593&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/avro.h (original)
+++ hadoop/avro/trunk/src/c/avro.h Thu Oct 15 18:00:21 2009
@@ -20,226 +20,78 @@
#ifndef AVRO_H
#define AVRO_H
-/**
-@file avro.h
-@brief AVRO API
-*/
-
-#include <stdarg.h>
-#include <stdint.h>
-#include <sys/types.h>
-#include <apr_pools.h>
-#include <apr_file_io.h>
-#include <apr_network_io.h>
-
#ifdef __cplusplus
extern "C" {
#endif
+#include <stdint.h>
+#include <wchar.h>
+
/**
-@defgroup AVRO Avro C API
-@{
+@mainpage
+
+The C implementation of the Avro Spec is currently <em>incomplete</em> without a public API. It
+is not ready for production use.
+
+
*/
+
/**
-* @defgroup Handle_Routines AVRO Handles
-* @ingroup AVRO
-* @{
+@file avro.h
+@brief AVRO API
*/
/**
-Avro operation enum.
-Enum for discriminating whether an Avro handle is for encoding or decoding data.
+@defgroup AVRO Avro C API
+@{
*/
-enum avro_op
-{
- AVRO_ENCODE = 0, /**< Marks a handle as encoding Avro data */
- AVRO_DECODE = 1 /**< Marks a handle as decoding Avro data */
-};
-typedef enum avro_op avro_op;
/**
Avro status enum.
Enum used by Avro functions to return state.
@todo expand the number of states
*/
-enum avro_status_t
+enum avro_status
{
AVRO_OK = 0, /**< Function success */
AVRO_FAILURE = 1 /**< Function failure */
};
-typedef enum avro_status_t avro_status_t;
-#define CHECK_ERROR(__status) if(__status != AVRO_OK){ return __status; }
-
-/**
-Avro handle.
-Opaque handle for encoding/decoding data to memory, file or network.
-@warning Never operate on an Avro handle directly. Use the AVRO Handle routines instead.
-*/
-struct AVRO
-{
- enum avro_op a_op; /**< Hold the type of operation the handle is performing */
- struct avro_ops
- {
- /**
- * Function for getting bytes from the underlying media
- */
- avro_status_t (*a_getbytes) (struct AVRO * avro, caddr_t addr,
- int64_t len);
- /**
- * Function for sending bytes to the backing store
- */
- avro_status_t (*a_putbytes) (struct AVRO * avro, const char *addr,
- const int64_t len);
- } *a_ops;
- apr_pool_t *pool; /**< Pool used for allocating memory for dynamic data structures */
- unsigned char *schema; /**< Current AVRO schema for processing data */
-
- apr_file_t *file; /**< Used by the file-backed handle */
- apr_socket_t *socket; /**< Used by the socket-backed handle */
- caddr_t addr; /**< Used by the memory-backed handle */
- int64_t len; /**< Used by the memory-backed handle */
- int64_t used; /**< Used by the memory-backed handle */
-};
-typedef struct AVRO AVRO;
-
-#define AVRO_GETBYTES(avro, addr, len) \
-(*(avro)->a_ops->a_getbytes)(avro, addr, len)
-
-#define AVRO_PUTBYTES(avro, addr, len) \
-(*(avro)->a_ops->a_putbytes)(avro, addr, len)
+typedef enum avro_status avro_status_t;
/** Initialize the AVRO library
@return The Avro status
*/
avro_status_t avro_initialize(void);
-/** Create a memory-backed Avro handle
-@param avro Pointer to handle that will be initialized
-@param pool Pool used for allocating dynamic data structures.
-@param addr Address of the memory location for manipulating data
-@param len Size of the memory to use
-@param op Expressing the operation the handle should perform (e.g. encode, decode)
-@return The Avro status
-*/
-avro_status_t avro_create_memory (AVRO * avro, apr_pool_t * pool,
- caddr_t addr, int64_t len, avro_op op);
-
-/** Create a file-backed Avro handle
-@param avro Pointer to the handle that will be initialized
-@param pool Pool used for allocating dynamic data structures
-@param file The file to read(decode) or write(encode) from
-@param op Expresses the operation the handle should perform (e.g. encode, decode)
-@return The Avro status
-*/
-avro_status_t avro_create_file (AVRO * avro, apr_pool_t * pool,
- apr_file_t * file, avro_op op);
-
-/** Create a socket-backed Avro handle
-@param avro Pointer to the handle that will be initialized
-@param pool Pool used for allocating dynamic data structures
-@param socket The socket to read(decode) or write(encode) from
-@param op Expresses the operation the handle should perform (e.g. encode, decode)
-@return The Avro status
-*/
-avro_status_t avro_create_socket (AVRO * avro, apr_pool_t * pool,
- apr_socket_t * socket, avro_op op);
-/** @} */
-
-typedef avro_status_t (*avroproc_t) (AVRO *, void *, ...);
-typedef int bool_t;
-
/**
-* @defgroup Primitives AVRO Primitive Type Serialization
+* @defgroup generic_routines AVRO Generic API
* @ingroup AVRO
* @{
*/
-/** avro_null() will not read or write any data
-*/
-avro_status_t avro_null (void);
-
-/** avro_int64() is called to read/write a 64-bit signed integer
-@param avro The Avro handle
-@param lp Pointer to the 64-bit integer
-@return The Avro status
-*/
-avro_status_t avro_int64 (AVRO * avro, int64_t * lp);
-
-/** avro_string() is called to read/write a string
-@param avro The Avro handle
-@param str Pointer to the string
-@param maxlen The maximum length of the string to read/write
-@return The Avro status
-*/
-avro_status_t avro_string (AVRO * avro, char **str, int64_t maxlen);
-
-/** avro_bytes() is called to read/write opaque bytes
-@param avro The Avro handle
-@param bytes The pointer to the bytes to read/write
-@param len Pointer to an integer which either (1) expresses the
-number of bytes you wish to encode or (2) is set on return to
-give the number of bytes decoded
-@param maxlen The maximum number of bytes to read/write
-@return The Avro status
-*/
-avro_status_t avro_bytes (AVRO * avro, char **bytes, int64_t * len,
- int64_t maxlen);
-
-/** avro_bool() is called to read/write a boolean value
-@param avro The Avro handle
-@param bp Pointer to the boolean pointer
-@return The Avro status
-*/
-avro_status_t avro_bool (AVRO * avro, bool_t * bp);
-
-/** avro_float() is called to read/write a float
-@param avro The Avro handle
-@param fp Pointer to the float
-@return The Avro status
-*/
-avro_status_t avro_float (AVRO * avro, float *fp);
-
-/** avro_double() is called to read/write a double
-@param avro The Avro handle
-@param dp Pointer to the double
-@return The Avro status
-*/
-avro_status_t avro_double (AVRO * avro, double *dp);
-
-/** @} */
-
/**
-* @defgroup Compound AVRO Compound Type Serialization
-* @ingroup AVRO
-* @{
+Avro types.
*/
-
-/** avro_array() encodes/decodes an array of avro elements
-@param avro The Avro handle
-@param addrp Pointer to the array
-@param sizep Pointer to the number of elements
-@param maxsize The maximum number of Avro elements
-@param elsize The size in bytes of each element
-@param elproc The Avro routine to handle each element
-@return The Avro status
-*/
-avro_status_t avro_array (AVRO * avro, caddr_t * addrp, uint32_t * sizep,
- uint32_t maxsize, uint32_t elsize,
- avroproc_t elproc);
-
-/** @} */
-
-
-/* Useful for debugging */
-void avro_dump_memory (AVRO * avro, FILE * fp);
-
-avro_status_t avro_getint32_raw (AVRO * avro, int32_t * value);
-avro_status_t avro_putint32_raw (AVRO * avro, const int32_t value);
-avro_status_t avro_getint64_raw (AVRO * avro, int64_t * value);
-avro_status_t avro_putint64_raw (AVRO * avro, const int64_t value);
-
-/** @} */
+enum avro_type
+{
+ AVRO_STRING, /**< string primitive */
+ AVRO_BYTES, /**< bytes primitive */
+ AVRO_INT, /**< int primitive */
+ AVRO_LONG, /**< long primitive */
+ AVRO_FLOAT, /**< float primitive */
+ AVRO_DOUBLE, /**< double primitive */
+ AVRO_BOOLEAN,/**< boolean primitive */
+ AVRO_NULL, /**< null primitive */
+ AVRO_RECORD, /**< complex record */
+ AVRO_FIELD, /**< complex record field */
+ AVRO_ENUM, /**< complex enum */
+ AVRO_FIXED, /**< complex fixed value */
+ AVRO_MAP, /**< complex map */
+ AVRO_ARRAY, /**< complex array */
+ AVRO_UNION /**< complex union */
+};
+typedef enum avro_type avro_type_t;
#ifdef __cplusplus
}
Modified: hadoop/avro/trunk/src/c/avro_array.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/avro_array.c?rev=825593&r1=825592&r2=825593&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/avro_array.c (original)
+++ hadoop/avro/trunk/src/c/avro_array.c Thu Oct 15 18:00:21 2009
@@ -16,13 +16,132 @@
specific language governing permissions and limitations
under the License.
*/
-#include "avro.h"
+#include "avro_private.h"
-avro_status_t
-avro_array (AVRO * avro, caddr_t * addrp, uint32_t * sizep,
- uint32_t maxsize, uint32_t elsize, avroproc_t elproc)
+struct avro_array_value
{
+ apr_array_header_t *values;
+ struct avro_value *items;
+ apr_pool_t *pool;
+
+ int value_set;
+
+ /* Need the ctx to dupe value */
+ struct avro_value_ctx *ctx;
+
+ struct avro_value base_value;
+};
+
+static void
+avro_array_print (struct avro_value *value, FILE * fp)
+{
+ struct avro_array_value *self =
+ container_of (value, struct avro_array_value, base_value);
+
+ avro_value_indent (value, fp);
+ fprintf (fp, "array value items\n");
+ self->items->print_info (self->items, fp);
+}
+
+static avro_status_t
+avro_array_read_skip (struct avro_value *value, struct avro_channel *channel,
+ int skip)
+{
+ avro_status_t status;
+ avro_long_t i, count;
+ struct avro_array_value *self =
+ container_of (value, struct avro_array_value, base_value);
+ struct avro_io *io;
+
+ apr_pool_clear (self->pool);
+
+ if (!channel)
+ {
+ return AVRO_FAILURE;
+ }
+ io = channel->io;
+ if (!io)
+ {
+ return AVRO_FAILURE;
+ }
+
+ status = avro_getlong (io, &count);
+ if (status != AVRO_OK)
+ {
+ return status;
+ }
+
+ if (count < 0)
+ {
+ /* TODO */
+ }
+
+ /* TODO */
+ return AVRO_OK;
+}
+
+static avro_status_t
+avro_array_read (struct avro_value *value, struct avro_channel *channel)
+{
+ return avro_array_read_skip (value, channel, 0);
+}
+
+static avro_status_t
+avro_array_skip (struct avro_value *value, struct avro_channel *channel)
+{
+ return avro_array_read_skip (value, channel, 1);
+}
+
+static avro_status_t
+avro_array_write (struct avro_value *value, struct avro_channel *channel)
+{
+/* TODO
+ struct avro_array_value *self =
+ container_of (value, struct avro_array_value, base_value);
+*/
return AVRO_OK;
}
+
+struct avro_value *
+avro_array_create (struct avro_value_ctx *ctx, struct avro_value *parent,
+ apr_pool_t * pool, const JSON_value * json)
+{
+ struct avro_array_value *self;
+ const JSON_value *items;
+
+ self = apr_palloc (pool, sizeof (struct avro_array_value));
+ if (!self)
+ {
+ return NULL;
+ }
+ self->base_value.type = AVRO_ARRAY;
+ self->base_value.pool = pool;
+ self->base_value.parent = parent;
+ self->base_value.schema = json;
+ self->base_value.read_data = avro_array_read;
+ self->base_value.skip_data = avro_array_skip;
+ self->base_value.write_data = avro_array_write;
+ self->base_value.print_info = avro_array_print;
+
+ /* collect and save required items */
+ items = json_attr_get (json, L"items");
+ if (!items)
+ {
+ return NULL;
+ }
+ self->items = avro_value_from_json (ctx, parent, items);
+ if (!self->items)
+ {
+ return NULL;
+ }
+ /* Create a pool for the value processing */
+ if (apr_pool_create (&self->pool, pool) != APR_SUCCESS)
+ {
+ return NULL;
+ }
+ self->value_set = 0;
+ self->ctx = ctx;
+ return &self->base_value;
+}
Added: hadoop/avro/trunk/src/c/avro_boolean.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/avro_boolean.c?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/avro_boolean.c (added)
+++ hadoop/avro/trunk/src/c/avro_boolean.c Thu Oct 15 18:00:21 2009
@@ -0,0 +1,133 @@
+/*
+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.
+*/
+#include "avro_private.h"
+
+struct avro_boolean_value
+{
+ int value;
+ int value_set;
+ struct avro_value base_value;
+};
+
+static void
+avro_boolean_print (struct avro_value *value, FILE * fp)
+{
+ struct avro_boolean_value *self =
+ container_of (value, struct avro_boolean_value, base_value);
+ avro_value_indent (value, fp);
+ fprintf (fp, "boolean");
+ if (self->value_set)
+ {
+ fprintf (fp, " value=%d", self->value);
+ }
+ fprintf (fp, "\n");
+}
+
+static avro_status_t
+avro_boolean_read_skip (struct avro_value *value,
+ struct avro_channel *channel, int skip)
+{
+ char b;
+ avro_status_t status;
+ struct avro_io *io;
+ struct avro_boolean_value *self =
+ container_of (value, struct avro_boolean_value, base_value);
+ if (!channel)
+ {
+ return AVRO_FAILURE;
+ }
+ io = channel->io;
+ if (!io)
+ {
+ return AVRO_FAILURE;
+ }
+ if (skip)
+ {
+ status = io->skip (io, 1);
+ }
+ else
+ {
+ status = io->read (io, &b, 1);
+ }
+ if (status != AVRO_OK)
+ {
+ return status;
+ }
+ self->value_set = 0;
+ if (!skip)
+ {
+ self->value = b;
+ self->value_set = 1;
+ }
+ return AVRO_OK;
+}
+
+static avro_status_t
+avro_boolean_read (struct avro_value *value, struct avro_channel *channel)
+{
+ return avro_boolean_read_skip (value, channel, 0);
+}
+
+static avro_status_t
+avro_boolean_skip (struct avro_value *value, struct avro_channel *channel)
+{
+ return avro_boolean_read_skip (value, channel, 1);
+}
+
+static avro_status_t
+avro_boolean_write (struct avro_value *value, struct avro_channel *channel)
+{
+ char b;
+ struct avro_boolean_value *self =
+ container_of (value, struct avro_boolean_value, base_value);
+ struct avro_io *io;
+ if (!channel)
+ {
+ return AVRO_FAILURE;
+ }
+ io = channel->io;
+ if (!io)
+ {
+ return AVRO_FAILURE;
+ }
+ b = self->value;
+ return io->write (io, &b, 1);
+}
+
+struct avro_value *
+avro_boolean_create (struct avro_value_ctx *ctx, struct avro_value *parent,
+ apr_pool_t * pool, const JSON_value * json)
+{
+ struct avro_boolean_value *self =
+ apr_palloc (pool, sizeof (struct avro_boolean_value));
+ if (!self)
+ {
+ return NULL;
+ }
+ self->base_value.type = AVRO_BOOLEAN;
+ self->base_value.pool = pool;
+ self->base_value.parent = parent;
+ self->base_value.schema = json;
+ self->base_value.read_data = avro_boolean_read;
+ self->base_value.skip_data = avro_boolean_skip;
+ self->base_value.write_data = avro_boolean_write;
+ self->base_value.print_info = avro_boolean_print;
+ self->value_set = 0;
+ return &self->base_value;
+}
Added: hadoop/avro/trunk/src/c/avro_bytes.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/avro_bytes.c?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/avro_bytes.c (added)
+++ hadoop/avro/trunk/src/c/avro_bytes.c Thu Oct 15 18:00:21 2009
@@ -0,0 +1,128 @@
+/*
+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.
+*/
+#include "avro_private.h"
+#include "dump.h"
+
+struct avro_bytes_value
+{
+ char *value;
+ int value_set;
+ avro_long_t size;
+ avro_value base_value;
+ apr_pool_t *pool;
+};
+
+static void
+avro_bytes_print (struct avro_value *value, FILE * fp)
+{
+ struct avro_bytes_value *self =
+ container_of (value, struct avro_bytes_value, base_value);
+
+ avro_value_indent (value, fp);
+ fprintf (fp, "bytes");
+ if (self->value_set)
+ {
+ fprintf (fp, " size=%ld ", self->size);
+ dump (fp, self->value, self->size);
+ }
+ fprintf (fp, "\n");
+}
+
+static avro_status_t
+avro_bytes_read (struct avro_value *value, struct avro_channel *channel)
+{
+ struct avro_io *io;
+ struct avro_bytes_value *self =
+ container_of (value, struct avro_bytes_value, base_value);
+ if (!channel)
+ {
+ return AVRO_FAILURE;
+ }
+ io = channel->io;
+ if (!io)
+ {
+ return AVRO_FAILURE;
+ }
+ /* Flush old data to make room for new */
+ self->value_set = 1;
+ apr_pool_clear (self->pool);
+ return avro_getbytes (io, self->pool, &self->value, &self->size);
+}
+
+static avro_status_t
+avro_bytes_skip (struct avro_value *value, struct avro_channel *channel)
+{
+ avro_status_t status;
+ struct avro_io *io;
+ avro_long_t len;
+ struct avro_bytes_value *self =
+ container_of (value, struct avro_bytes_value, base_value);
+
+ self->value_set = 0;
+ if (!channel)
+ {
+ return AVRO_FAILURE;
+ }
+ io = channel->io;
+ if (!io)
+ {
+ return AVRO_FAILURE;
+ }
+ status = avro_getlong (io, &len);
+ if (status != AVRO_OK)
+ {
+ return AVRO_FAILURE;
+ }
+ return io->skip (io, len);
+}
+
+static avro_status_t
+avro_bytes_write (struct avro_value *value, struct avro_channel *channel)
+{
+ struct avro_bytes_value *self =
+ container_of (value, struct avro_bytes_value, base_value);
+ return AVRO_OK;
+}
+
+struct avro_value *
+avro_bytes_create (struct avro_value_ctx *ctx, struct avro_value *parent,
+ apr_pool_t * pool, const JSON_value * json)
+{
+ struct avro_bytes_value *self =
+ apr_palloc (pool, sizeof (struct avro_bytes_value));
+ DEBUG (fprintf (stderr, "Creating bytes\n"));
+ if (!self)
+ {
+ return NULL;
+ }
+ self->base_value.type = AVRO_BYTES;
+ self->base_value.pool = pool;
+ self->base_value.parent = parent;
+ self->base_value.schema = json;
+ self->base_value.read_data = avro_bytes_read;
+ self->base_value.skip_data = avro_bytes_skip;
+ self->base_value.write_data = avro_bytes_write;
+ self->base_value.print_info = avro_bytes_print;
+ self->value_set = 0;
+ if (apr_pool_create (&self->pool, pool) != APR_SUCCESS)
+ {
+ return NULL;
+ }
+ return &self->base_value;
+}
Modified: hadoop/avro/trunk/src/c/avro_double.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/avro_double.c?rev=825593&r1=825592&r2=825593&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c/avro_double.c (original)
+++ hadoop/avro/trunk/src/c/avro_double.c Thu Oct 15 18:00:21 2009
@@ -16,43 +16,90 @@
specific language governing permissions and limitations
under the License.
*/
+#include "avro_private.h"
-#include "avro.h"
+struct avro_double_value
+{
+ double value;
+ int value_set;
+ struct avro_value base_value;
+};
-avro_status_t
-avro_float (AVRO * avro, float *fp)
+static void
+avro_double_print (struct avro_value *value, FILE * fp)
{
- if (!avro || !fp)
+ struct avro_double_value *self =
+ container_of (value, struct avro_double_value, base_value);
+ avro_value_indent (value, fp);
+ fprintf (fp, "double");
+ if (self->value_set)
{
- return AVRO_FAILURE;
+ fprintf (fp, " value=%f", self->value);
}
- switch (avro->a_op)
+ fprintf (fp, "\n");
+}
+
+static avro_status_t
+avro_double_read (struct avro_value *value, struct avro_channel *channel)
+{
+ double *dp;
+ struct avro_double_value *self =
+ container_of (value, struct avro_double_value, base_value);
+ if (!channel)
{
- case AVRO_ENCODE:
- return avro_putint32_raw (avro, *(int32_t *) fp);
- case AVRO_DECODE:
- return avro_getint32_raw (avro, (int32_t *) fp);
- default:
return AVRO_FAILURE;
}
- return AVRO_OK;
+ self->value_set = 1;
+ dp = &self->value;
+ return avro_getint64_le (channel->io, (int64_t *) dp);
}
-avro_status_t
-avro_double (AVRO * avro, double *dp)
+static avro_status_t
+avro_double_skip (struct avro_value *value, struct avro_channel *channel)
{
- if (!avro || !dp)
+ double d;
+ double *dp = &d;
+ struct avro_double_value *self =
+ container_of (value, struct avro_double_value, base_value);
+ if (!channel)
{
return AVRO_FAILURE;
}
- switch (avro->a_op)
+ self->value_set = 0;
+ return avro_getint64_le (channel->io, (int64_t *) dp);
+}
+
+static avro_status_t
+avro_double_write (struct avro_value *value, struct avro_channel *channel)
+{
+ struct avro_double_value *self =
+ container_of (value, struct avro_double_value, base_value);
+ if (!channel)
{
- case AVRO_ENCODE:
- return avro_putint64_raw (avro, *(int64_t *) dp);
- case AVRO_DECODE:
- return avro_getint64_raw (avro, (int64_t *) dp);
- default:
return AVRO_FAILURE;
}
- return AVRO_OK;
+ return avro_putint64_le (channel->io, (int64_t) self->value);;
+}
+
+struct avro_value *
+avro_double_create (struct avro_value_ctx *ctx, struct avro_value *parent,
+ apr_pool_t * pool, const JSON_value * json)
+{
+ struct avro_double_value *self =
+ apr_palloc (pool, sizeof (struct avro_double_value));
+ DEBUG (fprintf (stderr, "Creating double\n"));
+ if (!self)
+ {
+ return NULL;
+ }
+ self->base_value.type = AVRO_DOUBLE;
+ self->base_value.pool = pool;
+ self->base_value.parent = parent;
+ self->base_value.schema = json;
+ self->base_value.read_data = avro_double_read;
+ self->base_value.skip_data = avro_double_skip;
+ self->base_value.write_data = avro_double_write;
+ self->base_value.print_info = avro_double_print;
+ self->value_set = 0;
+ return &self->base_value;
}
Added: hadoop/avro/trunk/src/c/avro_endian.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/avro_endian.c?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/avro_endian.c (added)
+++ hadoop/avro/trunk/src/c/avro_endian.c Thu Oct 15 18:00:21 2009
@@ -0,0 +1,176 @@
+/*
+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.
+*/
+#include "avro_private.h"
+
+avro_status_t
+avro_getint32_le (struct avro_io *io, int32_t * value)
+{
+ avro_status_t status;
+ uint8_t buf[4];
+ if (!io || !value)
+ {
+ return AVRO_FAILURE;
+ }
+ status = io->read (io, (char *) buf, sizeof (buf));
+ if (status != AVRO_OK)
+ {
+ return status;
+ }
+ *value = ((int32_t) buf[0] << 0)
+ | ((int32_t) buf[1] << 8)
+ | ((int32_t) buf[2] << 16) | ((int32_t) buf[3] << 24);
+ return AVRO_OK;
+}
+
+avro_status_t
+avro_putint32_le (struct avro_io * io, const int32_t value)
+{
+ uint8_t buf[4];
+ buf[0] = (uint8_t) (value >> 0);
+ buf[1] = (uint8_t) (value >> 8);
+ buf[2] = (uint8_t) (value >> 16);
+ buf[3] = (uint8_t) (value >> 24);
+ if (!io)
+ {
+ return AVRO_FAILURE;
+ }
+ return io->write (io, (char *) buf, sizeof (buf));
+}
+
+avro_status_t
+avro_getint32_be (struct avro_io *io, int32_t * value)
+{
+ avro_status_t status;
+ uint8_t buf[4];
+ if (!io || !value)
+ {
+ return AVRO_FAILURE;
+ }
+ status = io->read (io, (char *) buf, sizeof (buf));
+ if (status != AVRO_OK)
+ {
+ return status;
+ }
+ *value = ((int32_t) buf[0] << 24)
+ | ((int32_t) buf[1] << 16)
+ | ((int32_t) buf[2] << 8) | ((int32_t) buf[3] << 0);
+ return AVRO_OK;
+}
+
+avro_status_t
+avro_putint32_be (struct avro_io * io, const int32_t value)
+{
+ uint8_t buf[4];
+ buf[0] = (uint8_t) (value >> 24);
+ buf[1] = (uint8_t) (value >> 16);
+ buf[2] = (uint8_t) (value >> 8);
+ buf[3] = (uint8_t) (value >> 0);
+ if (!io)
+ {
+ return AVRO_FAILURE;
+ }
+ return io->write (io, (char *) buf, sizeof (buf));
+}
+
+
+avro_status_t
+avro_getint64_le (struct avro_io *io, int64_t * value)
+{
+ avro_status_t status;
+ uint8_t buf[8];
+ if (!io || !value)
+ {
+ return AVRO_FAILURE;
+ }
+ status = io->read (io, (char *) buf, sizeof (buf));
+ if (status != AVRO_OK)
+ {
+ return status;
+ }
+ *value = ((int64_t) buf[0] << 0)
+ | ((int64_t) buf[1] << 8)
+ | ((int64_t) buf[2] << 16)
+ | ((int64_t) buf[3] << 24)
+ | ((int64_t) buf[4] << 32)
+ | ((int64_t) buf[5] << 40)
+ | ((int64_t) buf[6] << 48) | ((int64_t) buf[7] << 56);
+ return AVRO_OK;
+}
+
+avro_status_t
+avro_putint64_le (struct avro_io * io, const int64_t value)
+{
+ uint8_t buf[8];
+ buf[0] = (uint8_t) (value >> 0);
+ buf[1] = (uint8_t) (value >> 8);
+ buf[2] = (uint8_t) (value >> 16);
+ buf[3] = (uint8_t) (value >> 24);
+ buf[4] = (uint8_t) (value >> 32);
+ buf[5] = (uint8_t) (value >> 40);
+ buf[6] = (uint8_t) (value >> 48);
+ buf[7] = (uint8_t) (value >> 56);
+ if (!io)
+ {
+ return AVRO_FAILURE;
+ }
+ return io->write (io, (char *) buf, sizeof (buf));
+}
+
+avro_status_t
+avro_getint64_be (struct avro_io *io, int64_t * value)
+{
+ avro_status_t status;
+ uint8_t buf[8];
+ if (!io || !value)
+ {
+ return AVRO_FAILURE;
+ }
+ status = io->read (io, (char *) buf, sizeof (buf));
+ if (status != AVRO_OK)
+ {
+ return status;
+ }
+ *value = ((int64_t) buf[0] << 56)
+ | ((int64_t) buf[1] << 48)
+ | ((int64_t) buf[2] << 40)
+ | ((int64_t) buf[3] << 32)
+ | ((int64_t) buf[4] << 24)
+ | ((int64_t) buf[5] << 16)
+ | ((int64_t) buf[6] << 8) | ((int64_t) buf[7] << 0);
+ return AVRO_OK;
+}
+
+avro_status_t
+avro_putint64_be (struct avro_io * io, const int64_t value)
+{
+ uint8_t buf[8];
+ buf[0] = (uint8_t) (value >> 56);
+ buf[1] = (uint8_t) (value >> 48);
+ buf[2] = (uint8_t) (value >> 40);
+ buf[3] = (uint8_t) (value >> 32);
+ buf[4] = (uint8_t) (value >> 24);
+ buf[5] = (uint8_t) (value >> 16);
+ buf[6] = (uint8_t) (value >> 8);
+ buf[7] = (uint8_t) (value >> 0);
+ if (!io)
+ {
+ return AVRO_FAILURE;
+ }
+ return io->write (io, (char *) buf, sizeof (buf));
+}
Added: hadoop/avro/trunk/src/c/avro_enum.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/avro_enum.c?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/avro_enum.c (added)
+++ hadoop/avro/trunk/src/c/avro_enum.c Thu Oct 15 18:00:21 2009
@@ -0,0 +1,155 @@
+/*
+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.
+*/
+#include "avro_private.h"
+
+struct avro_avro_enum
+{
+ avro_string_t name;
+ avro_long_t offset;
+ apr_array_header_t *symbols;
+ int value_set;
+ struct avro_value base_value;
+};
+
+static void
+avro_enum_print (struct avro_value *value, FILE * fp)
+{
+ struct avro_avro_enum *self =
+ container_of (value, struct avro_avro_enum, base_value);
+ avro_value_indent (value, fp);
+ fprintf (fp, "enum name=%ls", self->name);
+ if (self->value_set)
+ {
+ fprintf (fp, " value=%ls",
+ ((avro_string_t *) self->symbols->elts)[self->offset]);
+ }
+ fprintf (fp, "\n");
+}
+
+static avro_status_t
+avro_enum_read_skip (struct avro_value *value, struct avro_channel *channel,
+ int skip)
+{
+ avro_status_t status;
+ struct avro_io *io;
+ struct avro_avro_enum *self =
+ container_of (value, struct avro_avro_enum, base_value);
+
+ if (!channel)
+ {
+ return AVRO_FAILURE;
+ }
+ io = channel->io;
+ if (!io)
+ {
+ return AVRO_FAILURE;
+ }
+ /* Read the offset */
+ status = avro_getlong (io, &self->offset);
+ if (status != AVRO_OK)
+ {
+ return status;
+ }
+ if (self->offset > self->symbols->nelts)
+ {
+ /* Offset outside of our symbol table */
+ return AVRO_FAILURE;
+ }
+ self->value_set = !skip;
+ return AVRO_OK;
+}
+
+static avro_status_t
+avro_enum_read (struct avro_value *value, struct avro_channel *channel)
+{
+ return avro_enum_read_skip (value, channel, 0);
+}
+
+static avro_status_t
+avro_enum_skip (struct avro_value *value, struct avro_channel *channel)
+{
+ return avro_enum_read_skip (value, channel, 1);
+}
+
+static avro_status_t
+avro_enum_write (struct avro_value *value, struct avro_channel *channel)
+{
+/* TODO
+ struct avro_avro_enum *self =
+ container_of (value, struct avro_avro_enum, base_value);
+*/
+ return AVRO_OK;
+}
+
+struct avro_value *
+avro_enum_create (struct avro_value_ctx *ctx, struct avro_value *parent,
+ apr_pool_t * pool, const JSON_value * json)
+{
+ struct avro_avro_enum *self;
+ const JSON_value *name;
+ const JSON_value *symbols;
+ int i;
+
+ DEBUG (fprintf (stderr, "Creating enum\n"));
+ self = apr_palloc (pool, sizeof (struct avro_avro_enum));
+ if (!self)
+ {
+ return NULL;
+ }
+ self->base_value.type = AVRO_ENUM;
+ self->base_value.pool = pool;
+ self->base_value.parent = parent;
+ self->base_value.schema = json;
+ self->base_value.read_data = avro_enum_read;
+ self->base_value.skip_data = avro_enum_skip;
+ self->base_value.write_data = avro_enum_write;
+ self->base_value.print_info = avro_enum_print;
+
+ /* collect and save required name */
+ name = json_attr_get_check_type (json, L"name", JSON_STRING);
+ if (!name)
+ {
+ return NULL;
+ }
+ self->name = name->json_string;
+
+ /* register self with named objects */
+ apr_hash_set (ctx->named_objects, self->name,
+ wcslen (self->name) * sizeof (wchar_t), &self->base_value);
+
+ /* collect and save required symbols */
+ symbols = json_attr_get_check_type (json, L"symbols", JSON_ARRAY);
+ if (!symbols || symbols->json_array->nelts == 0)
+ {
+ return NULL;
+ }
+ self->symbols = apr_array_make (pool, 8, sizeof (avro_string_t));
+ for (i = 0; i < symbols->json_array->nelts; i++)
+ {
+ const JSON_value *symbol =
+ ((JSON_value **) symbols->json_array->elts)[i];
+ if (symbol->type != JSON_STRING)
+ {
+ return NULL;
+ }
+ *(avro_string_t *) apr_array_push (self->symbols) = symbol->json_string;
+ }
+ self->value_set = 0;
+ return &self->base_value;
+}
Added: hadoop/avro/trunk/src/c/avro_file_container.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/avro_file_container.c?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/avro_file_container.c (added)
+++ hadoop/avro/trunk/src/c/avro_file_container.c Thu Oct 15 18:00:21 2009
@@ -0,0 +1,198 @@
+#include "avro_private.h"
+#include <apr_file_io.h>
+#include "dump.h"
+#include "json.h"
+
+struct avro_metadata
+{
+ avro_string_t key;
+ char *value;
+ avro_long_t len;
+};
+
+struct avro_file_container
+{
+ char uuid[16];
+ apr_hash_t *meta;
+ JSON_value *schema;
+ avro_long_t size;
+ struct avro_channel channel;
+};
+
+struct avro_channel *
+avro_file_container_create_from_file (apr_file_t * file)
+{
+ apr_status_t apr_status;
+ avro_status_t status;
+ struct avro_file_container *container;
+ struct apr_pool_t *pool;
+ struct avro_io *io;
+ char buf[4];
+ int i;
+ int64_t type;
+ apr_off_t offset, len;
+ int32_t footersize;
+ avro_long_t metalength;
+ struct avro_metadata *metadata;
+
+ if (!file)
+ {
+ return NULL;
+ }
+
+ pool = apr_file_pool_get (file);
+ if (!pool)
+ {
+ return NULL;
+ }
+
+ container = apr_pcalloc (pool, sizeof (struct avro_file_container));
+ container->channel.format = AVRO_BINARY_FORMAT;
+ container->channel.io = io = avro_io_file_create (file);
+ if (!io)
+ {
+ return NULL;
+ }
+
+ status = io->read (io, buf, 4);
+ if (status != AVRO_OK)
+ {
+ return NULL;
+ }
+
+ /* Assuming version zero here */
+ if (buf[0] != 'O' || buf[1] != 'b' || buf[2] != 'j' || buf[3] != 0)
+ {
+ /* Not an Avro file */
+ return NULL;
+ }
+
+ /* Grab the UUID */
+ io->read (io, container->uuid, 16);
+ DEBUG (dump (stderr, container->uuid, 16));
+
+ /* Jump to the end of the file */
+ offset = 0;
+ apr_status = apr_file_seek (file, APR_END, &offset);
+ if (apr_status != APR_SUCCESS)
+ {
+ return NULL;
+ }
+ len = offset;
+
+ /* Move back four bytes to get the footersize */
+ offset = -4;
+ apr_status = apr_file_seek (file, APR_CUR, &offset);
+ if (apr_status != APR_SUCCESS)
+ {
+ return NULL;
+ }
+ /* Read in the footersize */
+ status = avro_getint32_be (io, &footersize);
+ if (status != AVRO_OK)
+ {
+ return NULL;
+ }
+
+ /* Seek in the file to metadata */
+ offset = -footersize;
+ apr_status = apr_file_seek (file, APR_END, &offset);
+ if (apr_status != APR_SUCCESS)
+ {
+ return NULL;
+ }
+
+ /* Read the metadata length */
+ status = avro_getlong (io, &metalength);
+ if (status != AVRO_OK)
+ {
+ return NULL;
+ }
+
+ if (metalength < 0)
+ {
+ avro_long_t ignore;
+ avro_getlong (io, &ignore);
+ }
+
+ /* Create a hash table for the meta data */
+ container->meta = apr_hash_make (pool);
+ for (i = 0; i < metalength; i++)
+ {
+ avro_string_t key;
+
+ metadata = apr_pcalloc (pool, sizeof (struct avro_metadata));
+ if (!metadata)
+ {
+ return NULL;
+ }
+ avro_getstring (io, pool, &key);
+ avro_getbytes (io, pool, &metadata->value, &metadata->len);
+ apr_hash_set (container->meta, key, wcslen (key) * sizeof (wchar_t),
+ metadata);
+ DEBUG (fprintf (stderr, "%ls = ", key));
+ DEBUG (dump (stderr, metadata->value, metadata->len));
+ }
+
+ /* Save the schema */
+ metadata = apr_hash_get (container->meta, L"schema", sizeof (wchar_t) * 6);
+ if (!metadata)
+ {
+ return NULL;
+ }
+ /* Validate the schema */
+ container->schema = JSON_parse (pool, metadata->value, metadata->len);
+ if (!container->schema)
+ {
+ /* Invalid schema */
+ return NULL;
+ }
+ DEBUG (JSON_print (stderr, container->schema));
+ metadata = apr_hash_get (container->meta, L"sync", sizeof (wchar_t) * 4);
+ if (!metadata)
+ {
+ return NULL;
+ }
+ if (memcmp (container->uuid, metadata->value, 16) != 0)
+ {
+ /* TODO: find the correct schema.. */
+ return NULL;
+ }
+
+ /* Seek back to the start of the file */
+ offset = 20; /* Obj0 + UUID */
+ apr_status = apr_file_seek (file, APR_SET, &offset);
+ if (apr_status != APR_SUCCESS)
+ {
+ return NULL;
+ }
+
+ /* Read the size of the block */
+ status = avro_getlong (io, &container->size);
+ if (status != AVRO_OK)
+ {
+ return NULL;
+ }
+ return &container->channel;
+}
+
+struct avro_channel *
+avro_file_container_create (apr_pool_t * pool, const char *fname,
+ apr_int32_t flag, apr_fileperms_t perm)
+{
+ apr_status_t status;
+ apr_file_t *file;
+
+ if (!pool || !fname)
+ {
+ return NULL;
+ }
+
+ status = apr_file_open (&file, fname, flag, perm, pool);
+ if (status != APR_SUCCESS)
+ {
+ return NULL;
+ }
+
+ return avro_file_container_create_from_file (file);
+}
Added: hadoop/avro/trunk/src/c/avro_fixed.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/avro_fixed.c?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/avro_fixed.c (added)
+++ hadoop/avro/trunk/src/c/avro_fixed.c Thu Oct 15 18:00:21 2009
@@ -0,0 +1,113 @@
+/*
+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.
+*/
+#include "avro_private.h"
+
+struct avro_fixed_value
+{
+ avro_string_t name;
+ avro_long_t size;
+ void *value;
+
+ avro_value base_value;
+};
+
+static void
+fixed_print (struct avro_value *value, FILE * fp)
+{
+ struct avro_fixed_value *self =
+ container_of (value, struct avro_fixed_value, base_value);
+ avro_value_indent (value, fp);
+ fprintf (fp, "fixed name=%ls size=%ld\n", self->name, self->size);
+}
+
+static avro_status_t
+fixed_read (struct avro_value *value, struct avro_channel *channel)
+{
+ struct avro_fixed_value *self =
+ container_of (value, struct avro_fixed_value, base_value);
+ return AVRO_OK;
+}
+
+static avro_status_t
+fixed_skip (struct avro_value *value, struct avro_channel *channel)
+{
+ struct avro_fixed_value *self =
+ container_of (value, struct avro_fixed_value, base_value);
+ return AVRO_OK;
+}
+
+static avro_status_t
+fixed_write (struct avro_value *value, struct avro_channel *channel)
+{
+ struct avro_fixed_value *self =
+ container_of (value, struct avro_fixed_value, base_value);
+ return AVRO_OK;
+}
+
+struct avro_value *
+avro_fixed_create (struct avro_value_ctx *ctx, struct avro_value *parent,
+ apr_pool_t * pool, const JSON_value * json)
+{
+ struct avro_fixed_value *self;
+ const JSON_value *size;
+ const JSON_value *name;
+
+ DEBUG (fprintf (stderr, "Creating fixed\n"));
+ self = apr_palloc (pool, sizeof (struct avro_fixed_value));
+ if (!self)
+ {
+ return NULL;
+ }
+ self->base_value.type = AVRO_FIXED;
+ self->base_value.pool = pool;
+ self->base_value.parent = parent;
+ self->base_value.schema = json;
+ self->base_value.read_data = fixed_read;
+ self->base_value.skip_data = fixed_skip;
+ self->base_value.write_data = fixed_write;
+ self->base_value.print_info = fixed_print;
+
+ /* collect and save required size */
+ size = json_attr_get_check_type (json, L"size", JSON_NUMBER);
+ if (!size)
+ {
+ return NULL;
+ }
+ self->size = size->json_number;
+
+
+ /* collect and save the require name */
+ name = json_attr_get_check_type (json, L"name", JSON_STRING);
+ if (!name)
+ {
+ return NULL;
+ }
+ self->name = name->json_string;
+ /* register self with named objects */
+ apr_hash_set (ctx->named_objects, self->name,
+ wcslen (self->name) * sizeof (wchar_t), &self->base_value);
+
+ self->value = apr_palloc (pool, self->size);
+ if (!self->value)
+ {
+ return NULL;
+ }
+
+ return &self->base_value;
+}
Added: hadoop/avro/trunk/src/c/avro_float.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/avro_float.c?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/avro_float.c (added)
+++ hadoop/avro/trunk/src/c/avro_float.c Thu Oct 15 18:00:21 2009
@@ -0,0 +1,105 @@
+/*
+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.
+*/
+#include "avro_private.h"
+
+struct avro_float_value
+{
+ float value;
+ int value_set;
+ struct avro_value base_value;
+};
+
+static void
+avro_float_print (struct avro_value *value, FILE * fp)
+{
+ struct avro_float_value *self =
+ container_of (value, struct avro_float_value, base_value);
+ avro_value_indent (value, fp);
+ fprintf (fp, "float");
+ if (self->value_set)
+ {
+ fprintf (fp, " value=%f", self->value);
+ }
+ fprintf (fp, "\n");
+}
+
+static avro_status_t
+avro_float_read (struct avro_value *value, struct avro_channel *channel)
+{
+ float *fp;
+ struct avro_float_value *self =
+ container_of (value, struct avro_float_value, base_value);
+ if (!channel)
+ {
+ return AVRO_FAILURE;
+ }
+ fp = &self->value;
+ self->value_set = 1;
+ return avro_getint32_le (channel->io, (int32_t *) fp);
+}
+
+static avro_status_t
+avro_float_skip (struct avro_value *value, struct avro_channel *channel)
+{
+ float f;
+ float *fp = &f;
+ struct avro_float_value *self =
+ container_of (value, struct avro_float_value, base_value);
+ if (!channel)
+ {
+ return AVRO_FAILURE;
+ }
+ self->value_set = 0;
+ return avro_getint32_le (channel->io, (int32_t *) fp);
+}
+
+static avro_status_t
+avro_float_write (struct avro_value *value, struct avro_channel *channel)
+{
+ struct avro_float_value *self =
+ container_of (value, struct avro_float_value, base_value);
+ if (!channel)
+ {
+ return AVRO_FAILURE;
+ }
+ return avro_putint32_le (channel->io, (int32_t) self->value);
+}
+
+struct avro_value *
+avro_float_create (struct avro_value_ctx *ctx, struct avro_value *parent,
+ apr_pool_t * pool, const JSON_value * json)
+{
+ struct avro_float_value *self =
+ apr_palloc (pool, sizeof (struct avro_float_value));
+ DEBUG (fprintf (stderr, "Creating float\n"));
+ if (!self)
+ {
+ return NULL;
+ }
+ self->base_value.type = AVRO_FLOAT;
+ self->base_value.pool = pool;
+ self->base_value.parent = parent;
+ self->base_value.schema = json;
+ self->base_value.read_data = avro_float_read;
+ self->base_value.skip_data = avro_float_skip;
+ self->base_value.write_data = avro_float_write;
+ self->base_value.print_info = avro_float_print;
+ self->value_set = 0;
+ return &self->base_value;
+}
Added: hadoop/avro/trunk/src/c/avro_int.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/avro_int.c?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/avro_int.c (added)
+++ hadoop/avro/trunk/src/c/avro_int.c Thu Oct 15 18:00:21 2009
@@ -0,0 +1,113 @@
+/*
+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.
+*/
+#include "avro_private.h"
+
+struct avro_int_value
+{
+ avro_int_t value;
+ int value_set;
+ struct avro_value base_value;
+};
+
+static void
+avro_int_print (struct avro_value *value, FILE * fp)
+{
+ struct avro_int_value *self =
+ container_of (value, struct avro_int_value, base_value);
+ avro_value_indent (value, fp);
+ fprintf (fp, "int");
+ if (self->value_set)
+ {
+ fprintf (fp, " value=%d", self->value);
+ }
+ fprintf (fp, "\n");
+}
+
+static avro_status_t
+avro_int_read_skip (struct avro_value *value, struct avro_channel *channel,
+ int skip)
+{
+ struct avro_int_value *self =
+ container_of (value, struct avro_int_value, base_value);
+ struct avro_io *io;
+ if (!channel)
+ {
+ return AVRO_FAILURE;
+ }
+ io = channel->io;
+ if (!io)
+ {
+ return AVRO_FAILURE;
+ }
+ self->value_set = !skip;
+ return avro_getint (io, &self->value);
+}
+
+static avro_status_t
+avro_int_read (struct avro_value *value, struct avro_channel *channel)
+{
+ return avro_int_read_skip (value, channel, 0);
+}
+
+static avro_status_t
+avro_int_skip (struct avro_value *value, struct avro_channel *channel)
+{
+ return avro_int_read_skip (value, channel, 1);
+}
+
+static avro_status_t
+avro_int_write (struct avro_value *value, struct avro_channel *channel)
+{
+ struct avro_int_value *self =
+ container_of (value, struct avro_int_value, base_value);
+ struct avro_io *io;
+ if (!value || !channel)
+ {
+ return AVRO_FAILURE;
+ }
+ io = channel->io;
+ if (!io)
+ {
+ return AVRO_FAILURE;
+ }
+ return avro_putint (io, &self->value);
+}
+
+struct avro_value *
+avro_int_create (struct avro_value_ctx *ctx, struct avro_value *parent,
+ apr_pool_t * pool, const JSON_value * json)
+{
+ struct avro_int_value *self =
+ apr_palloc (pool, sizeof (struct avro_int_value));
+ DEBUG (fprintf (stderr, "Creating int\n"));
+ if (!self)
+ {
+ return NULL;
+ }
+ self->base_value.type = AVRO_INT;
+ self->base_value.pool = pool;
+ self->base_value.parent = parent;
+ self->base_value.schema = json;
+ self->base_value.read_data = avro_int_read;
+ self->base_value.skip_data = avro_int_skip;
+ self->base_value.write_data = avro_int_write;
+ self->base_value.print_info = avro_int_print;
+ self->value_set = 0;
+ return &self->base_value;
+}
Added: hadoop/avro/trunk/src/c/avro_io_file.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/avro_io_file.c?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/avro_io_file.c (added)
+++ hadoop/avro/trunk/src/c/avro_io_file.c Thu Oct 15 18:00:21 2009
@@ -0,0 +1,79 @@
+/*
+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.
+*/
+
+#include "avro_private.h"
+#include "apr_file_io.h"
+
+struct avro_io_file
+{
+ apr_file_t *file;
+ struct avro_io io;
+};
+
+static avro_status_t
+avro_io_file_read (struct avro_io *io, char *addr, uint64_t len)
+{
+ struct avro_io_file *self = container_of (io, struct avro_io_file, io);
+ apr_status_t status =
+ apr_file_read_full (self->file, addr, (apr_size_t) len, NULL);
+ return status == APR_SUCCESS ? AVRO_OK : AVRO_FAILURE;
+}
+
+static avro_status_t
+avro_io_file_skip (struct avro_io *io, uint64_t len)
+{
+ /* TODO: file seek */
+ return AVRO_OK;
+}
+
+static avro_status_t
+avro_io_file_write (struct avro_io *io, char *addr, uint64_t len)
+{
+ struct avro_io_file *self = container_of (io, struct avro_io_file, io);
+ apr_status_t status =
+ apr_file_write_full (self->file, addr, (apr_size_t) len, NULL);
+ return status == APR_SUCCESS ? AVRO_OK : AVRO_FAILURE;
+}
+
+struct avro_io *
+avro_io_file_create (apr_file_t * file)
+{
+ struct avro_io_file *file_io;
+ apr_pool_t *pool;
+
+ if (!file)
+ {
+ return NULL;
+ }
+ pool = apr_file_pool_get (file);
+ if (!pool)
+ {
+ return NULL;
+ }
+ file_io = apr_pcalloc (pool, sizeof (struct avro_io_file));
+ if (!file_io)
+ {
+ return NULL;
+ }
+ file_io->io.read = avro_io_file_read;
+ file_io->io.skip = avro_io_file_skip;
+ file_io->io.write = avro_io_file_write;
+ file_io->file = file;
+ return &file_io->io;
+}
Added: hadoop/avro/trunk/src/c/avro_io_memory.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/avro_io_memory.c?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/avro_io_memory.c (added)
+++ hadoop/avro/trunk/src/c/avro_io_memory.c Thu Oct 15 18:00:21 2009
@@ -0,0 +1,93 @@
+/*
+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.
+*/
+
+#include "avro_private.h"
+
+struct avro_io_memory
+{
+ char *addr;
+ uint64_t used;
+ uint64_t len;
+ struct avro_io io;
+};
+
+static avro_status_t
+avro_io_memory_read (struct avro_io *io, char *addr, uint64_t len)
+{
+ struct avro_io_memory *self = container_of (io, struct avro_io_memory, io);
+ if ((self->len - self->used) < len)
+ {
+ return AVRO_FAILURE;
+ }
+ memcpy (addr, self->addr + self->used, len);
+ self->used += len;
+ return AVRO_OK;
+}
+
+static avro_status_t
+avro_io_memory_skip (struct avro_io *io, uint64_t len)
+{
+ struct avro_io_memory *self = container_of (io, struct avro_io_memory, io);
+ if ((self->len - self->used) < len)
+ {
+ return AVRO_FAILURE;
+ }
+ self->used += len;
+ return AVRO_OK;
+}
+
+static avro_status_t
+avro_io_memory_write (struct avro_io *io, char *addr, uint64_t len)
+{
+ struct avro_io_memory *self = container_of (io, struct avro_io_memory, io);
+ if ((self->len - self->used) < len)
+ {
+ return AVRO_FAILURE;
+ }
+ memcpy (self->addr + self->used, addr, len);
+ self->used += len;
+ return AVRO_OK;
+}
+
+struct avro_io *
+avro_io_memory_create (apr_pool_t * pool, char *addr, int64_t len)
+{
+ struct avro_io_memory *io_memory;
+
+ if (!pool || !addr)
+ {
+ return NULL;
+ }
+
+ io_memory = apr_pcalloc (pool, sizeof (struct avro_io));
+ if (!io_memory)
+ {
+ return NULL;
+ }
+
+ io_memory->addr = addr;
+ io_memory->used = 0;
+ io_memory->len = len;
+
+ io_memory->io.read = avro_io_memory_read;
+ io_memory->io.skip = avro_io_memory_skip;
+ io_memory->io.write = avro_io_memory_write;
+
+ return &io_memory->io;
+}
Added: hadoop/avro/trunk/src/c/avro_io_socket.c
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c/avro_io_socket.c?rev=825593&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c/avro_io_socket.c (added)
+++ hadoop/avro/trunk/src/c/avro_io_socket.c Thu Oct 15 18:00:21 2009
@@ -0,0 +1,104 @@
+/*
+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.
+*/
+
+#include "avro_private.h"
+#include <apr_network_io.h>
+
+struct avro_io_socket
+{
+ apr_socket_t *socket;
+ struct avro_io io;
+};
+
+static avro_status_t
+avro_io_socket_read (struct avro_io *io, char *addr, uint64_t len)
+{
+ apr_status_t status;
+ apr_size_t bytes_wanted = len;
+ apr_size_t bytes_recvd = 0;
+ struct avro_io_socket *self = container_of (io, struct avro_io_socket, io);
+ while (bytes_recvd < bytes_wanted)
+ {
+ apr_size_t bytes_requested = bytes_wanted - bytes_recvd;
+ status = apr_socket_recv (self->socket, addr, &bytes_requested);
+ if (status != APR_SUCCESS)
+ {
+ return AVRO_FAILURE;
+ }
+ bytes_recvd += bytes_requested;
+ }
+ return AVRO_OK;
+}
+
+static avro_status_t
+avro_io_socket_skip (struct avro_io *io, uint64_t len)
+{
+ /* TODO */
+ return AVRO_OK;
+}
+
+static avro_status_t
+avro_io_socket_write (struct avro_io *io, char *addr, uint64_t len)
+{
+ apr_status_t status;
+ struct avro_io_socket *self = container_of (io, struct avro_io_socket, io);
+ apr_size_t bytes_wanted = len;
+ apr_size_t bytes_sent = 0;
+ while (bytes_sent < bytes_wanted)
+ {
+ apr_size_t bytes_requested = bytes_wanted - bytes_sent;
+ status = apr_socket_send (self->socket, addr, &bytes_requested);
+ if (status != APR_SUCCESS)
+ {
+ return AVRO_FAILURE;
+ }
+ bytes_sent += bytes_requested;
+ }
+ return AVRO_OK;
+}
+
+struct avro_io *
+avro_io_socket_create (apr_socket_t * socket)
+{
+ struct avro_io_socket *socket_io;
+ apr_pool_t *pool;
+
+ if (!socket)
+ {
+ return NULL;
+ }
+
+ pool = apr_socket_pool_get (socket);
+ if (!pool)
+ {
+ return NULL;
+ }
+
+ socket_io = apr_pcalloc (pool, sizeof (struct avro_io_socket));
+ if (!socket_io)
+ {
+ return NULL;
+ }
+
+ socket_io->socket = socket;
+ socket_io->io.read = avro_io_socket_read;
+ socket_io->io.skip = avro_io_socket_skip;
+ socket_io->io.write = avro_io_socket_write;
+ return &socket_io->io;
+}