mina-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apali...@apache.org
Subject git commit: Initial draft for Avro codec
Date Sat, 27 Jul 2013 16:08:15 GMT
Updated Branches:
  refs/heads/trunk 5d4e972b3 -> f226cd1b0


Initial draft for Avro codec


Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/f226cd1b
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/f226cd1b
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/f226cd1b

Branch: refs/heads/trunk
Commit: f226cd1b0f9cb9fe7a0c6353487698c8b5fe75d3
Parents: 5d4e972
Author: paliwalashish <paliwalashish@gmail.com>
Authored: Sat Jul 27 21:38:03 2013 +0530
Committer: paliwalashish <paliwalashish@gmail.com>
Committed: Sat Jul 27 21:38:03 2013 +0530

----------------------------------------------------------------------
 avro/pom.xml                                    |  89 +++++++
 .../org/apache/mina/avro/codec/AvroDecoder.java |  40 ++++
 .../org/apache/mina/avro/codec/AvroEncoder.java |  35 +++
 .../codec/serialization/AvroMessageDecoder.java |  60 +++++
 .../codec/serialization/AvroMessageEncoder.java |  62 +++++
 .../mina/avro/codec/serialization/AvroTest.java |  84 +++++++
 .../org/apache/mina/avro/generated/User.java    | 236 +++++++++++++++++++
 avro/src/test/resources/user.avsc               |  10 +
 pom.xml                                         |   1 +
 9 files changed, 617 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina/blob/f226cd1b/avro/pom.xml
----------------------------------------------------------------------
diff --git a/avro/pom.xml b/avro/pom.xml
new file mode 100644
index 0000000..4c7775f
--- /dev/null
+++ b/avro/pom.xml
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.mina</groupId>
+    <artifactId>mina-parent</artifactId>
+    <version>3.0.0-M3-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>mina-avro</artifactId>
+  <name>Apache MINA Serialization::Avro ${project.version}</name>
+  <packaging>jar</packaging>
+
+  <properties>
+    <symbolicName>${project.groupId}.avro</symbolicName>
+    <exportedPackage>${project.groupId}</exportedPackage>
+    <avro.version>1.7.4</avro.version>
+  </properties>
+
+  <dependencies>
+
+      <dependency>
+          <groupId>org.apache.avro</groupId>
+          <artifactId>avro</artifactId>
+          <version>${avro.version}</version>
+      </dependency>
+
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>mina-codec</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>mina-codec</artifactId>
+      <scope>test</scope>
+      <type>test-jar</type>
+    </dependency>
+  </dependencies>
+    <!--<build>-->
+        <!--<plugins>-->
+            <!--<plugin>-->
+                <!--<groupId>org.apache.avro</groupId>-->
+                <!--<artifactId>avro-maven-plugin</artifactId>-->
+                <!--<version>1.7.4</version>-->
+                <!--<executions>-->
+                    <!--<execution>-->
+                        <!--<phase>generate-sources</phase>-->
+                        <!--<goals>-->
+                            <!--<goal>schema</goal>-->
+                        <!--</goals>-->
+                        <!--<configuration>-->
+                            <!--<sourceDirectory>${project.basedir}/src/test/resources/</sourceDirectory>-->
+                            <!--<outputDirectory>${project.basedir}/src/test/java/</outputDirectory>-->
+                        <!--</configuration>-->
+                    <!--</execution>-->
+                <!--</executions>-->
+            <!--</plugin>-->
+            <!--<plugin>-->
+                <!--<groupId>org.apache.maven.plugins</groupId>-->
+                <!--<artifactId>maven-compiler-plugin</artifactId>-->
+                <!--<configuration>-->
+                    <!--<source>1.7</source>-->
+                    <!--<target>1.7</target>-->
+                <!--</configuration>-->
+            <!--</plugin>-->
+        <!--</plugins>-->
+    <!--</build>-->
+</project>
+

http://git-wip-us.apache.org/repos/asf/mina/blob/f226cd1b/avro/src/main/java/org/apache/mina/avro/codec/AvroDecoder.java
----------------------------------------------------------------------
diff --git a/avro/src/main/java/org/apache/mina/avro/codec/AvroDecoder.java b/avro/src/main/java/org/apache/mina/avro/codec/AvroDecoder.java
new file mode 100644
index 0000000..997d73a
--- /dev/null
+++ b/avro/src/main/java/org/apache/mina/avro/codec/AvroDecoder.java
@@ -0,0 +1,40 @@
+/*
+ *  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.
+ *
+ */
+
+package org.apache.mina.avro.codec;
+
+import org.apache.avro.Schema;
+import org.apache.mina.avro.codec.serialization.AvroMessageDecoder;
+import org.apache.mina.codec.delimited.IoBufferDecoder;
+import org.apache.mina.codec.delimited.SizePrefixedDecoder;
+import org.apache.mina.codec.delimited.ints.VarInt;
+
+/**
+ *
+ */
+public class AvroDecoder<GenericRecord> extends SizePrefixedDecoder<GenericRecord>
{
+
+    private Schema schema;
+
+    public AvroDecoder(IoBufferDecoder<Integer> sizeDecoder, IoBufferDecoder<GenericRecord>
payloadDecoder, Schema schema) {
+        super(new VarInt().getDecoder(), new AvroMessageDecoder<GenericRecord>(schema));
+        this.schema = schema;
+    }
+}

http://git-wip-us.apache.org/repos/asf/mina/blob/f226cd1b/avro/src/main/java/org/apache/mina/avro/codec/AvroEncoder.java
----------------------------------------------------------------------
diff --git a/avro/src/main/java/org/apache/mina/avro/codec/AvroEncoder.java b/avro/src/main/java/org/apache/mina/avro/codec/AvroEncoder.java
new file mode 100644
index 0000000..51d3b75
--- /dev/null
+++ b/avro/src/main/java/org/apache/mina/avro/codec/AvroEncoder.java
@@ -0,0 +1,35 @@
+/*
+ *  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.
+ *
+ */
+package org.apache.mina.avro.codec;
+
+import org.apache.avro.generic.GenericRecord;
+import org.apache.mina.avro.codec.serialization.AvroMessageEncoder;
+import org.apache.mina.codec.delimited.ByteBufferEncoder;
+import org.apache.mina.codec.delimited.SizePrefixedEncoder;
+import org.apache.mina.codec.delimited.ints.VarInt;
+
+/**
+ *
+ */
+public class AvroEncoder<IN extends GenericRecord> extends SizePrefixedEncoder<GenericRecord>
{
+    public AvroEncoder(ByteBufferEncoder<Integer> sizeEncoder, ByteBufferEncoder<GenericRecord>
payloadEncoder) {
+        super(new VarInt().getEncoder(), new AvroMessageEncoder<GenericRecord>());
+    }
+}

http://git-wip-us.apache.org/repos/asf/mina/blob/f226cd1b/avro/src/main/java/org/apache/mina/avro/codec/serialization/AvroMessageDecoder.java
----------------------------------------------------------------------
diff --git a/avro/src/main/java/org/apache/mina/avro/codec/serialization/AvroMessageDecoder.java
b/avro/src/main/java/org/apache/mina/avro/codec/serialization/AvroMessageDecoder.java
new file mode 100644
index 0000000..2df618e
--- /dev/null
+++ b/avro/src/main/java/org/apache/mina/avro/codec/serialization/AvroMessageDecoder.java
@@ -0,0 +1,60 @@
+/*
+ *  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.
+ *
+ */
+
+package org.apache.mina.avro.codec.serialization;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericData;
+import org.apache.avro.generic.GenericDatumReader;
+import org.apache.avro.io.BinaryDecoder;
+import org.apache.avro.io.DecoderFactory;
+import org.apache.mina.codec.IoBuffer;
+import org.apache.mina.codec.delimited.IoBufferDecoder;
+
+import java.io.IOException;
+
+/**
+ *
+ */
+public class AvroMessageDecoder<GenericRecord> extends IoBufferDecoder<GenericRecord>
{
+
+    private Schema schema;
+
+    /**
+     * Default Constructor
+     * @param schema
+     */
+    public AvroMessageDecoder(Schema schema) {
+        this.schema = schema;
+    }
+
+    @Override
+    public GenericRecord decode(IoBuffer input) {
+        BinaryDecoder binaryDecoder = DecoderFactory.get().binaryDecoder(input.array(), null);
+        GenericDatumReader<GenericRecord> recordGenericDatumReader = new GenericDatumReader<GenericRecord>(schema);
+        GenericRecord result = null;
+        try {
+            result = recordGenericDatumReader.read(null, binaryDecoder);
+        }catch (IOException ioEx) {
+            ioEx.printStackTrace();
+        }
+        return result;
+    }
+}

http://git-wip-us.apache.org/repos/asf/mina/blob/f226cd1b/avro/src/main/java/org/apache/mina/avro/codec/serialization/AvroMessageEncoder.java
----------------------------------------------------------------------
diff --git a/avro/src/main/java/org/apache/mina/avro/codec/serialization/AvroMessageEncoder.java
b/avro/src/main/java/org/apache/mina/avro/codec/serialization/AvroMessageEncoder.java
new file mode 100644
index 0000000..ecddad2
--- /dev/null
+++ b/avro/src/main/java/org/apache/mina/avro/codec/serialization/AvroMessageEncoder.java
@@ -0,0 +1,62 @@
+/*
+ *  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.
+ *
+ */
+
+package org.apache.mina.avro.codec.serialization;
+
+import org.apache.avro.generic.GenericDatumWriter;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.avro.io.DatumWriter;
+import org.apache.avro.io.Encoder;
+import org.apache.avro.io.EncoderFactory;
+import org.apache.mina.codec.delimited.ByteBufferEncoder;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+/**
+ *
+ */
+public class AvroMessageEncoder<OUT extends GenericRecord> extends ByteBufferEncoder<GenericRecord>
{
+
+    private ByteBuffer encodedMessage;
+
+    @Override
+    public int getEncodedSize(GenericRecord message) {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        DatumWriter<GenericRecord> writer = new GenericDatumWriter<GenericRecord>(message.getSchema());
+        Encoder encoder = EncoderFactory.get().binaryEncoder(out, null);
+        try {
+            writer.write(message, encoder);
+            encoder.flush();
+            byte[] encoded = out.toByteArray();
+            encodedMessage = ByteBuffer.wrap(encoded);
+            out.close();
+        } catch (IOException ioEx) {
+            // :(
+        }
+        return encodedMessage != null ? encodedMessage.capacity() : -1;
+    }
+
+    @Override
+    public void writeTo(GenericRecord message, ByteBuffer buffer) {
+        buffer.put(encodedMessage);
+    }
+}

http://git-wip-us.apache.org/repos/asf/mina/blob/f226cd1b/avro/src/test/java/org/apache/mina/avro/codec/serialization/AvroTest.java
----------------------------------------------------------------------
diff --git a/avro/src/test/java/org/apache/mina/avro/codec/serialization/AvroTest.java b/avro/src/test/java/org/apache/mina/avro/codec/serialization/AvroTest.java
new file mode 100644
index 0000000..5a754fc
--- /dev/null
+++ b/avro/src/test/java/org/apache/mina/avro/codec/serialization/AvroTest.java
@@ -0,0 +1,84 @@
+/*
+ *  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.
+ *
+ */
+
+package org.apache.mina.avro.codec.serialization;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericData;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.mina.codec.IoBuffer;
+import org.apache.mina.codec.delimited.ByteBufferEncoder;
+import org.apache.mina.codec.delimited.IoBufferDecoder;
+import org.apache.mina.codec.delimited.serialization.GenericSerializerTest;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ */
+public class AvroTest extends GenericSerializerTest {
+
+    private static Schema SCHEMA;
+
+    static {
+        try {
+            SCHEMA = new Schema.Parser().parse(AvroTest.class.getClassLoader().getResourceAsStream("user.avsc"));
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Override
+    public IoBufferDecoder getDecoder() throws Exception {
+        return new AvroMessageDecoder<GenericRecord>(SCHEMA);
+    }
+
+    @Override
+    public ByteBufferEncoder getEncoder() throws Exception {
+        return new AvroMessageEncoder<GenericRecord>();
+    }
+
+    @Override
+    public List<GenericRecord> getObjects() {
+        List<GenericRecord> genericRecordList = new ArrayList<GenericRecord>(1);
+        GenericRecord record1 = new GenericData.Record(SCHEMA);
+        record1.put("name", "Black Jack");
+        record1.put("favorite_number", 11);
+        record1.put("favorite_color", "Black");
+        genericRecordList.add(record1);
+
+        return genericRecordList;
+    }
+
+    @Test
+    public void testMessage() throws Exception {
+        ByteBufferEncoder<GenericRecord> encoder = getEncoder();
+        AvroMessageDecoder<GenericRecord> decoder = new AvroMessageDecoder<GenericRecord>(SCHEMA);
+
+        for (GenericRecord object : getObjects()) {
+            GenericRecord message = decoder.decode(IoBuffer
+                    .wrap(encoder.encode(object)));
+            System.out.println(message);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/mina/blob/f226cd1b/avro/src/test/java/org/apache/mina/avro/generated/User.java
----------------------------------------------------------------------
diff --git a/avro/src/test/java/org/apache/mina/avro/generated/User.java b/avro/src/test/java/org/apache/mina/avro/generated/User.java
new file mode 100644
index 0000000..e0d91c3
--- /dev/null
+++ b/avro/src/test/java/org/apache/mina/avro/generated/User.java
@@ -0,0 +1,236 @@
+/**
+ * Autogenerated by Avro
+ * 
+ * DO NOT EDIT DIRECTLY
+ */
+package org.apache.mina.avro.generated;  
+@SuppressWarnings("all")
+@org.apache.avro.specific.AvroGenerated
+public class User extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord
{
+  public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"User\",\"namespace\":\"org.apache.mina.avro.generated\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"favorite_number\",\"type\":[\"int\",\"null\"]},{\"name\":\"favorite_color\",\"type\":[\"string\",\"null\"]}]}");
+  public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; }
+  @Deprecated public java.lang.CharSequence name;
+  @Deprecated public java.lang.Integer favorite_number;
+  @Deprecated public java.lang.CharSequence favorite_color;
+
+  /**
+   * Default constructor.
+   */
+  public User() {}
+
+  /**
+   * All-args constructor.
+   */
+  public User(java.lang.CharSequence name, java.lang.Integer favorite_number, java.lang.CharSequence
favorite_color) {
+    this.name = name;
+    this.favorite_number = favorite_number;
+    this.favorite_color = favorite_color;
+  }
+
+  public org.apache.avro.Schema getSchema() { return SCHEMA$; }
+  // Used by DatumWriter.  Applications should not call. 
+  public java.lang.Object get(int field$) {
+    switch (field$) {
+    case 0: return name;
+    case 1: return favorite_number;
+    case 2: return favorite_color;
+    default: throw new org.apache.avro.AvroRuntimeException("Bad index");
+    }
+  }
+  // Used by DatumReader.  Applications should not call. 
+  @SuppressWarnings(value="unchecked")
+  public void put(int field$, java.lang.Object value$) {
+    switch (field$) {
+    case 0: name = (java.lang.CharSequence)value$; break;
+    case 1: favorite_number = (java.lang.Integer)value$; break;
+    case 2: favorite_color = (java.lang.CharSequence)value$; break;
+    default: throw new org.apache.avro.AvroRuntimeException("Bad index");
+    }
+  }
+
+  /**
+   * Gets the value of the 'name' field.
+   */
+  public java.lang.CharSequence getName() {
+    return name;
+  }
+
+  /**
+   * Sets the value of the 'name' field.
+   * @param value the value to set.
+   */
+  public void setName(java.lang.CharSequence value) {
+    this.name = value;
+  }
+
+  /**
+   * Gets the value of the 'favorite_number' field.
+   */
+  public java.lang.Integer getFavoriteNumber() {
+    return favorite_number;
+  }
+
+  /**
+   * Sets the value of the 'favorite_number' field.
+   * @param value the value to set.
+   */
+  public void setFavoriteNumber(java.lang.Integer value) {
+    this.favorite_number = value;
+  }
+
+  /**
+   * Gets the value of the 'favorite_color' field.
+   */
+  public java.lang.CharSequence getFavoriteColor() {
+    return favorite_color;
+  }
+
+  /**
+   * Sets the value of the 'favorite_color' field.
+   * @param value the value to set.
+   */
+  public void setFavoriteColor(java.lang.CharSequence value) {
+    this.favorite_color = value;
+  }
+
+  /** Creates a new User RecordBuilder */
+  public static org.apache.mina.avro.generated.User.Builder newBuilder() {
+    return new org.apache.mina.avro.generated.User.Builder();
+  }
+  
+  /** Creates a new User RecordBuilder by copying an existing Builder */
+  public static org.apache.mina.avro.generated.User.Builder newBuilder(org.apache.mina.avro.generated.User.Builder
other) {
+    return new org.apache.mina.avro.generated.User.Builder(other);
+  }
+  
+  /** Creates a new User RecordBuilder by copying an existing User instance */
+  public static org.apache.mina.avro.generated.User.Builder newBuilder(org.apache.mina.avro.generated.User
other) {
+    return new org.apache.mina.avro.generated.User.Builder(other);
+  }
+  
+  /**
+   * RecordBuilder for User instances.
+   */
+  public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase<User>
+    implements org.apache.avro.data.RecordBuilder<User> {
+
+    private java.lang.CharSequence name;
+    private java.lang.Integer favorite_number;
+    private java.lang.CharSequence favorite_color;
+
+    /** Creates a new Builder */
+    private Builder() {
+      super(org.apache.mina.avro.generated.User.SCHEMA$);
+    }
+    
+    /** Creates a Builder by copying an existing Builder */
+    private Builder(org.apache.mina.avro.generated.User.Builder other) {
+      super(other);
+    }
+    
+    /** Creates a Builder by copying an existing User instance */
+    private Builder(org.apache.mina.avro.generated.User other) {
+            super(org.apache.mina.avro.generated.User.SCHEMA$);
+      if (isValidValue(fields()[0], other.name)) {
+        this.name = data().deepCopy(fields()[0].schema(), other.name);
+        fieldSetFlags()[0] = true;
+      }
+      if (isValidValue(fields()[1], other.favorite_number)) {
+        this.favorite_number = data().deepCopy(fields()[1].schema(), other.favorite_number);
+        fieldSetFlags()[1] = true;
+      }
+      if (isValidValue(fields()[2], other.favorite_color)) {
+        this.favorite_color = data().deepCopy(fields()[2].schema(), other.favorite_color);
+        fieldSetFlags()[2] = true;
+      }
+    }
+
+    /** Gets the value of the 'name' field */
+    public java.lang.CharSequence getName() {
+      return name;
+    }
+    
+    /** Sets the value of the 'name' field */
+    public org.apache.mina.avro.generated.User.Builder setName(java.lang.CharSequence value)
{
+      validate(fields()[0], value);
+      this.name = value;
+      fieldSetFlags()[0] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'name' field has been set */
+    public boolean hasName() {
+      return fieldSetFlags()[0];
+    }
+    
+    /** Clears the value of the 'name' field */
+    public org.apache.mina.avro.generated.User.Builder clearName() {
+      name = null;
+      fieldSetFlags()[0] = false;
+      return this;
+    }
+
+    /** Gets the value of the 'favorite_number' field */
+    public java.lang.Integer getFavoriteNumber() {
+      return favorite_number;
+    }
+    
+    /** Sets the value of the 'favorite_number' field */
+    public org.apache.mina.avro.generated.User.Builder setFavoriteNumber(java.lang.Integer
value) {
+      validate(fields()[1], value);
+      this.favorite_number = value;
+      fieldSetFlags()[1] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'favorite_number' field has been set */
+    public boolean hasFavoriteNumber() {
+      return fieldSetFlags()[1];
+    }
+    
+    /** Clears the value of the 'favorite_number' field */
+    public org.apache.mina.avro.generated.User.Builder clearFavoriteNumber() {
+      favorite_number = null;
+      fieldSetFlags()[1] = false;
+      return this;
+    }
+
+    /** Gets the value of the 'favorite_color' field */
+    public java.lang.CharSequence getFavoriteColor() {
+      return favorite_color;
+    }
+    
+    /** Sets the value of the 'favorite_color' field */
+    public org.apache.mina.avro.generated.User.Builder setFavoriteColor(java.lang.CharSequence
value) {
+      validate(fields()[2], value);
+      this.favorite_color = value;
+      fieldSetFlags()[2] = true;
+      return this; 
+    }
+    
+    /** Checks whether the 'favorite_color' field has been set */
+    public boolean hasFavoriteColor() {
+      return fieldSetFlags()[2];
+    }
+    
+    /** Clears the value of the 'favorite_color' field */
+    public org.apache.mina.avro.generated.User.Builder clearFavoriteColor() {
+      favorite_color = null;
+      fieldSetFlags()[2] = false;
+      return this;
+    }
+
+    @Override
+    public User build() {
+      try {
+        User record = new User();
+        record.name = fieldSetFlags()[0] ? this.name : (java.lang.CharSequence) defaultValue(fields()[0]);
+        record.favorite_number = fieldSetFlags()[1] ? this.favorite_number : (java.lang.Integer)
defaultValue(fields()[1]);
+        record.favorite_color = fieldSetFlags()[2] ? this.favorite_color : (java.lang.CharSequence)
defaultValue(fields()[2]);
+        return record;
+      } catch (Exception e) {
+        throw new org.apache.avro.AvroRuntimeException(e);
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/mina/blob/f226cd1b/avro/src/test/resources/user.avsc
----------------------------------------------------------------------
diff --git a/avro/src/test/resources/user.avsc b/avro/src/test/resources/user.avsc
new file mode 100644
index 0000000..ddf304c
--- /dev/null
+++ b/avro/src/test/resources/user.avsc
@@ -0,0 +1,10 @@
+{
+    "namespace": "org.apache.mina.avro.generated",
+    "type": "record",
+    "name": "User",
+    "fields": [
+                {"name": "name", "type": "string"},
+                {"name": "favorite_number",  "type": ["int", "null"]},
+                {"name": "favorite_color", "type": ["string", "null"]}
+              ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/mina/blob/f226cd1b/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index ee95d87..d9c0db0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -117,6 +117,7 @@
     <module>protobuf</module>
     <module>benchmarks</module>
     <module>benchmarks2</module>
+    <module>avro</module>
   </modules>
 
   <dependencyManagement>


Mime
View raw message