You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by el...@apache.org on 2009/01/07 22:12:47 UTC

svn commit: r732497 [1/2] - in /mina/sandbox/protocol-buffers: ./ example/ example/src/main/java/org/apache/mina/example/filebrowser/ example/src/test/proto/ filter-codec-protobuf/ filter-codec-protobuf/src/ filter-codec-protobuf/src/main/ filter-codec...

Author: elecharny
Date: Wed Jan  7 13:12:46 2009
New Revision: 732497

URL: http://svn.apache.org/viewvc?rev=732497&view=rev
Log:
Injected Thoms code about the google protocol buffer

Added:
    mina/sandbox/protocol-buffers/LICENSE.protobuf.txt
    mina/sandbox/protocol-buffers/example/src/main/java/org/apache/mina/example/filebrowser/
    mina/sandbox/protocol-buffers/example/src/main/java/org/apache/mina/example/filebrowser/CommandLine.java
    mina/sandbox/protocol-buffers/example/src/main/java/org/apache/mina/example/filebrowser/FileBrowser.java
    mina/sandbox/protocol-buffers/example/src/main/java/org/apache/mina/example/filebrowser/FileBrowserProto.java
    mina/sandbox/protocol-buffers/example/src/main/java/org/apache/mina/example/filebrowser/FileBrowserServer.java
    mina/sandbox/protocol-buffers/example/src/test/proto/
    mina/sandbox/protocol-buffers/example/src/test/proto/fileBrowser.proto
    mina/sandbox/protocol-buffers/filter-codec-protobuf/
    mina/sandbox/protocol-buffers/filter-codec-protobuf/LICENCE.protobuf.txt
    mina/sandbox/protocol-buffers/filter-codec-protobuf/pom.xml
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/filter/
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/filter/codec/
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/filter/codec/protobuf/
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/filter/codec/protobuf/ProtobufCodecFactory.java
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/filter/codec/protobuf/ProtobufDecoder.java
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/filter/codec/protobuf/ProtobufEncoder.java
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/filter/codec/protobuf/SizeContext.java
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/test/
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/test/java/
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/test/java/org/
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/test/java/org/apache/
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/test/java/org/apache/mina/
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/test/java/org/apache/mina/filter/
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/test/java/org/apache/mina/filter/codec/
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/test/java/org/apache/mina/filter/codec/protobuf/
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/test/java/org/apache/mina/filter/codec/protobuf/FoobarProto.java
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/test/java/org/apache/mina/filter/codec/protobuf/ProtobufCodecFactoryTest.java
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/test/java/org/apache/mina/filter/codec/protobuf/ProtobufDecoderTest.java
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/test/java/org/apache/mina/filter/codec/protobuf/ProtobufEncoderTest.java
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/test/proto/
    mina/sandbox/protocol-buffers/filter-codec-protobuf/src/test/proto/foobar.proto
Modified:
    mina/sandbox/protocol-buffers/example/pom.xml
    mina/sandbox/protocol-buffers/pom.xml

Added: mina/sandbox/protocol-buffers/LICENSE.protobuf.txt
URL: http://svn.apache.org/viewvc/mina/sandbox/protocol-buffers/LICENSE.protobuf.txt?rev=732497&view=auto
==============================================================================
--- mina/sandbox/protocol-buffers/LICENSE.protobuf.txt (added)
+++ mina/sandbox/protocol-buffers/LICENSE.protobuf.txt Wed Jan  7 13:12:46 2009
@@ -0,0 +1,33 @@
+Copyright 2008, Google Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+    * Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above
+copyright notice, this list of conditions and the following disclaimer
+in the documentation and/or other materials provided with the
+distribution.
+    * Neither the name of Google Inc. nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+Code generated by the Protocol Buffer compiler is owned by the owner
+of the input file used when generating it.  This code is not
+standalone and requires a support library to be linked with it.  This
+support library is itself covered by the above license.

Modified: mina/sandbox/protocol-buffers/example/pom.xml
URL: http://svn.apache.org/viewvc/mina/sandbox/protocol-buffers/example/pom.xml?rev=732497&r1=732496&r2=732497&view=diff
==============================================================================
--- mina/sandbox/protocol-buffers/example/pom.xml (original)
+++ mina/sandbox/protocol-buffers/example/pom.xml Wed Jan  7 13:12:46 2009
@@ -37,6 +37,14 @@
     </dependency>
     <dependency>
       <groupId>${groupId}</groupId>
+      <artifactId>mina-filter-codec-protobuf</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>${groupId}</groupId>
+      <artifactId>mina-filter-codec-protobuf</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>${groupId}</groupId>
       <artifactId>mina-statemachine</artifactId>
     </dependency>
     <dependency>

Added: mina/sandbox/protocol-buffers/example/src/main/java/org/apache/mina/example/filebrowser/CommandLine.java
URL: http://svn.apache.org/viewvc/mina/sandbox/protocol-buffers/example/src/main/java/org/apache/mina/example/filebrowser/CommandLine.java?rev=732497&view=auto
==============================================================================
--- mina/sandbox/protocol-buffers/example/src/main/java/org/apache/mina/example/filebrowser/CommandLine.java (added)
+++ mina/sandbox/protocol-buffers/example/src/main/java/org/apache/mina/example/filebrowser/CommandLine.java Wed Jan  7 13:12:46 2009
@@ -0,0 +1,53 @@
+package org.apache.mina.example.filebrowser;
+
+/*
+ *  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.
+ *
+ */
+import java.io.File;
+
+/**
+ * Very simple implementation of command line arguments container.
+ * 
+ * @author Tomasz Blachowicz
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
+ */
+class CommandLine {
+
+	private final String[] args;
+	private int i = -1;
+	
+	CommandLine(String[] args) {
+		this.args = args;
+	}
+	
+	String popString(String def) {
+		i++;
+		return args == null || args.length < i + 1 || args[i] == null ? def : args[i];
+	}
+	
+	int popInt(int def) {	
+		return Integer.valueOf(popString(String.valueOf(def)));
+	}
+	
+	File popFile(File def) {
+		return new File(popString(def.toString()));
+	}
+	
+}

Added: mina/sandbox/protocol-buffers/example/src/main/java/org/apache/mina/example/filebrowser/FileBrowser.java
URL: http://svn.apache.org/viewvc/mina/sandbox/protocol-buffers/example/src/main/java/org/apache/mina/example/filebrowser/FileBrowser.java?rev=732497&view=auto
==============================================================================
--- mina/sandbox/protocol-buffers/example/src/main/java/org/apache/mina/example/filebrowser/FileBrowser.java (added)
+++ mina/sandbox/protocol-buffers/example/src/main/java/org/apache/mina/example/filebrowser/FileBrowser.java Wed Jan  7 13:12:46 2009
@@ -0,0 +1,125 @@
+/*
+ *  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.example.filebrowser;
+
+import java.net.InetSocketAddress;
+import java.util.Date;
+
+import org.apache.mina.core.service.IoHandlerAdapter;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.mina.filter.codec.protobuf.ProtobufCodecFactory;
+import org.apache.mina.filter.logging.LoggingFilter;
+import org.apache.mina.transport.socket.nio.NioSocketConnector;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.protobuf.ExtensionRegistry;
+
+/**
+ * Browser (client) that displays the server-side file system.
+ * Uses the Google Protocol Buffers as wire format to exchange
+ * data about files.
+ * 
+ * @author Tomasz Blachowicz
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class FileBrowser extends IoHandlerAdapter {
+	
+	private static Logger logger = LoggerFactory.getLogger(FileBrowser.class);
+	
+	/**
+	 * Three optional arguments can be provided (defaults in brackets):
+	 * path, host (localhost) and port (6667). 
+	 * 
+	 * @param args The command line args.
+	 */
+	public static void main(String[] args) {
+		CommandLine cmd = new CommandLine(args);
+		String path = cmd.popString("");
+		String host = cmd.popString("localhost");
+		int port = cmd.popInt(6667);
+		FileBrowser browser = new FileBrowser();
+		browser.connect(host, port);
+		browser.send(FileBrowserProto.Name.newBuilder().setValue(path).build());
+	}
+	
+	private final NioSocketConnector connector;
+	
+	private IoSession session;
+	
+	private FileBrowser() {
+		connector = new NioSocketConnector();
+		//connector.getFilterChain().addLast("logger", new LoggingFilter());
+		ExtensionRegistry extensionRegistry = ExtensionRegistry.newInstance();
+		extensionRegistry.add(FileBrowserProto.FileEntry.lenght);
+		extensionRegistry.add(FileBrowserProto.DirectoryEntry.entries);
+		connector.getFilterChain().addLast("codec",
+			new ProtocolCodecFilter(
+				ProtobufCodecFactory.newInstance(
+					FileBrowserProto.Entry.getDefaultInstance(),
+					extensionRegistry)));
+		connector.setHandler(this);
+	}
+	
+	public void connect(String host, int port) {
+		session = connector
+			.connect(new InetSocketAddress(host, port))
+			.awaitUninterruptibly()
+			.getSession();	
+	}
+	
+	public void send(FileBrowserProto.Name name) {
+		session.write(name);
+	}
+	
+	@Override
+	public void messageReceived(IoSession session, Object message) throws Exception {
+		FileBrowserProto.Entry entry = (FileBrowserProto.Entry) message;
+		if(entry.hasExtension(FileBrowserProto.FileEntry.lenght)) {
+			System.out.println(String.format("File: %s %s [%d bytes]",
+				entry.getName().getValue(),
+				new Date(entry.getLastModifed()),
+				entry.getExtension(FileBrowserProto.FileEntry.lenght)));	
+		} else {
+			System.out.println(String.format("Dir: %s %s",
+				entry.getName().getValue(),
+				new Date(entry.getLastModifed())));
+			for(FileBrowserProto.Name name : entry.getExtension(FileBrowserProto.DirectoryEntry.entries)) {
+				System.out.println(String.format(" + %s", name.getValue()));
+			}
+			for(FileBrowserProto.Name name : entry.getExtension(FileBrowserProto.DirectoryEntry.entries)) {
+				send(FileBrowserProto.Name
+					.newBuilder()
+					.setValue(
+						String.format("%s/%s",
+							entry.getName().getValue(),
+							name.getValue())).build());
+			}
+		}
+	}
+	
+	@Override
+	public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
+		logger.error("Ooops! Something went wrong :|", cause);
+	}
+	
+}

Added: mina/sandbox/protocol-buffers/example/src/main/java/org/apache/mina/example/filebrowser/FileBrowserProto.java
URL: http://svn.apache.org/viewvc/mina/sandbox/protocol-buffers/example/src/main/java/org/apache/mina/example/filebrowser/FileBrowserProto.java?rev=732497&view=auto
==============================================================================
--- mina/sandbox/protocol-buffers/example/src/main/java/org/apache/mina/example/filebrowser/FileBrowserProto.java (added)
+++ mina/sandbox/protocol-buffers/example/src/main/java/org/apache/mina/example/filebrowser/FileBrowserProto.java Wed Jan  7 13:12:46 2009
@@ -0,0 +1,788 @@
+/*
+ *  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.
+ *
+ */
+
+// Generated by the protocol buffer compiler.  DO NOT EDIT!
+package org.apache.mina.example.filebrowser;
+
+/**
+ * @author Tomasz Blachowicz
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
+ */
+public final class FileBrowserProto {
+  private FileBrowserProto() {}
+  public static void registerAllExtensions(
+      com.google.protobuf.ExtensionRegistry registry) {
+    registry.add(org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry.lenght);
+    registry.add(org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry.entries);
+  }
+  public static final class Name extends
+      com.google.protobuf.GeneratedMessage {
+    // Use Name.newBuilder() to construct.
+    private Name() {}
+    
+    private static final Name defaultInstance = new Name();
+    public static Name getDefaultInstance() {
+      return defaultInstance;
+    }
+    
+    public Name getDefaultInstanceForType() {
+      return defaultInstance;
+    }
+    
+    public static final com.google.protobuf.Descriptors.Descriptor
+        getDescriptor() {
+      return org.apache.mina.example.filebrowser.FileBrowserProto.internal_static_Name_descriptor;
+    }
+    
+    @Override
+    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+        internalGetFieldAccessorTable() {
+      return org.apache.mina.example.filebrowser.FileBrowserProto.internal_static_Name_fieldAccessorTable;
+    }
+    
+    // required string value = 1;
+    private boolean hasValue;
+    private java.lang.String value_ = "";
+    public boolean hasValue() { return hasValue; }
+    public java.lang.String getValue() { return value_; }
+    
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.Name parseFrom(
+        com.google.protobuf.ByteString data)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data).buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.Name parseFrom(
+        com.google.protobuf.ByteString data,
+        com.google.protobuf.ExtensionRegistry extensionRegistry)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data, extensionRegistry)
+               .buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.Name parseFrom(byte[] data)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data).buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.Name parseFrom(
+        byte[] data,
+        com.google.protobuf.ExtensionRegistry extensionRegistry)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data, extensionRegistry)
+               .buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.Name parseFrom(java.io.InputStream input)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input).buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.Name parseFrom(
+        java.io.InputStream input,
+        com.google.protobuf.ExtensionRegistry extensionRegistry)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input, extensionRegistry)
+               .buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.Name parseFrom(
+        com.google.protobuf.CodedInputStream input)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input).buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.Name parseFrom(
+        com.google.protobuf.CodedInputStream input,
+        com.google.protobuf.ExtensionRegistry extensionRegistry)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input, extensionRegistry)
+               .buildParsed();
+    }
+    
+    public static Builder newBuilder() { return new Builder(); }
+    public Builder newBuilderForType() { return new Builder(); }
+    public static Builder newBuilder(org.apache.mina.example.filebrowser.FileBrowserProto.Name prototype) {
+      return new Builder().mergeFrom(prototype);
+    }
+    
+    public static final class Builder extends
+        com.google.protobuf.GeneratedMessage.Builder<Builder> {
+      // Construct using org.apache.mina.example.filebrowser.FileBrowserProto.Name.newBuilder()
+      private Builder() {}
+      
+      org.apache.mina.example.filebrowser.FileBrowserProto.Name result = new org.apache.mina.example.filebrowser.FileBrowserProto.Name();
+      
+      @Override
+      protected org.apache.mina.example.filebrowser.FileBrowserProto.Name internalGetResult() {
+        return result;
+      }
+      
+      @Override
+      public Builder clear() {
+        result = new org.apache.mina.example.filebrowser.FileBrowserProto.Name();
+        return this;
+      }
+      
+      @Override
+      public Builder clone() {
+        return new Builder().mergeFrom(result);
+      }
+      
+      @Override
+      public com.google.protobuf.Descriptors.Descriptor
+          getDescriptorForType() {
+        return org.apache.mina.example.filebrowser.FileBrowserProto.Name.getDescriptor();
+      }
+      
+      public org.apache.mina.example.filebrowser.FileBrowserProto.Name getDefaultInstanceForType() {
+        return org.apache.mina.example.filebrowser.FileBrowserProto.Name.getDefaultInstance();
+      }
+      
+      public org.apache.mina.example.filebrowser.FileBrowserProto.Name build() {
+        if (!isInitialized()) {
+          throw new com.google.protobuf.UninitializedMessageException(
+            result);
+        }
+        return buildPartial();
+      }
+      
+      private org.apache.mina.example.filebrowser.FileBrowserProto.Name buildParsed()
+          throws com.google.protobuf.InvalidProtocolBufferException {
+        if (!isInitialized()) {
+          throw new com.google.protobuf.UninitializedMessageException(
+            result).asInvalidProtocolBufferException();
+        }
+        return buildPartial();
+      }
+      
+      public org.apache.mina.example.filebrowser.FileBrowserProto.Name buildPartial() {
+        org.apache.mina.example.filebrowser.FileBrowserProto.Name returnMe = result;
+        result = null;
+        return returnMe;
+      }
+      
+      
+      // required string value = 1;
+      public boolean hasValue() {
+        return result.hasValue();
+      }
+      public java.lang.String getValue() {
+        return result.getValue();
+      }
+      public Builder setValue(java.lang.String value) {
+        result.hasValue = true;
+        result.value_ = value;
+        return this;
+      }
+      public Builder clearValue() {
+        result.hasValue = false;
+        result.value_ = "";
+        return this;
+      }
+    }
+    
+    static {
+      org.apache.mina.example.filebrowser.FileBrowserProto.getDescriptor();
+    }
+  }
+  
+  public static final class Entry extends
+      com.google.protobuf.GeneratedMessage.ExtendableMessage<
+        Entry> {
+    // Use Entry.newBuilder() to construct.
+    private Entry() {}
+    
+    private static final Entry defaultInstance = new Entry();
+    public static Entry getDefaultInstance() {
+      return defaultInstance;
+    }
+    
+    public Entry getDefaultInstanceForType() {
+      return defaultInstance;
+    }
+    
+    public static final com.google.protobuf.Descriptors.Descriptor
+        getDescriptor() {
+      return org.apache.mina.example.filebrowser.FileBrowserProto.internal_static_Entry_descriptor;
+    }
+    
+    @Override
+    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+        internalGetFieldAccessorTable() {
+      return org.apache.mina.example.filebrowser.FileBrowserProto.internal_static_Entry_fieldAccessorTable;
+    }
+    
+    // required .Name name = 1;
+    private boolean hasName;
+    private org.apache.mina.example.filebrowser.FileBrowserProto.Name name_ = org.apache.mina.example.filebrowser.FileBrowserProto.Name.getDefaultInstance();
+    public boolean hasName() { return hasName; }
+    public org.apache.mina.example.filebrowser.FileBrowserProto.Name getName() { return name_; }
+    
+    // required int64 last_modifed = 2;
+    private boolean hasLastModifed;
+    private long lastModifed_ = 0L;
+    public boolean hasLastModifed() { return hasLastModifed; }
+    public long getLastModifed() { return lastModifed_; }
+    
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.Entry parseFrom(
+        com.google.protobuf.ByteString data)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data).buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.Entry parseFrom(
+        com.google.protobuf.ByteString data,
+        com.google.protobuf.ExtensionRegistry extensionRegistry)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data, extensionRegistry)
+               .buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.Entry parseFrom(byte[] data)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data).buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.Entry parseFrom(
+        byte[] data,
+        com.google.protobuf.ExtensionRegistry extensionRegistry)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data, extensionRegistry)
+               .buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.Entry parseFrom(java.io.InputStream input)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input).buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.Entry parseFrom(
+        java.io.InputStream input,
+        com.google.protobuf.ExtensionRegistry extensionRegistry)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input, extensionRegistry)
+               .buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.Entry parseFrom(
+        com.google.protobuf.CodedInputStream input)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input).buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.Entry parseFrom(
+        com.google.protobuf.CodedInputStream input,
+        com.google.protobuf.ExtensionRegistry extensionRegistry)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input, extensionRegistry)
+               .buildParsed();
+    }
+    
+    public static Builder newBuilder() { return new Builder(); }
+    public Builder newBuilderForType() { return new Builder(); }
+    public static Builder newBuilder(org.apache.mina.example.filebrowser.FileBrowserProto.Entry prototype) {
+      return new Builder().mergeFrom(prototype);
+    }
+    
+    public static final class Builder extends
+        com.google.protobuf.GeneratedMessage.ExtendableBuilder<
+          org.apache.mina.example.filebrowser.FileBrowserProto.Entry, Builder> {
+      // Construct using org.apache.mina.example.filebrowser.FileBrowserProto.Entry.newBuilder()
+      private Builder() {}
+      
+      org.apache.mina.example.filebrowser.FileBrowserProto.Entry result = new org.apache.mina.example.filebrowser.FileBrowserProto.Entry();
+      
+      @Override
+      protected org.apache.mina.example.filebrowser.FileBrowserProto.Entry internalGetResult() {
+        return result;
+      }
+      
+      @Override
+      public Builder clear() {
+        result = new org.apache.mina.example.filebrowser.FileBrowserProto.Entry();
+        return this;
+      }
+      
+      @Override
+      public Builder clone() {
+        return new Builder().mergeFrom(result);
+      }
+      
+      @Override
+      public com.google.protobuf.Descriptors.Descriptor
+          getDescriptorForType() {
+        return org.apache.mina.example.filebrowser.FileBrowserProto.Entry.getDescriptor();
+      }
+      
+      public org.apache.mina.example.filebrowser.FileBrowserProto.Entry getDefaultInstanceForType() {
+        return org.apache.mina.example.filebrowser.FileBrowserProto.Entry.getDefaultInstance();
+      }
+      
+      public org.apache.mina.example.filebrowser.FileBrowserProto.Entry build() {
+        if (!isInitialized()) {
+          throw new com.google.protobuf.UninitializedMessageException(
+            result);
+        }
+        return buildPartial();
+      }
+      
+      private org.apache.mina.example.filebrowser.FileBrowserProto.Entry buildParsed()
+          throws com.google.protobuf.InvalidProtocolBufferException {
+        if (!isInitialized()) {
+          throw new com.google.protobuf.UninitializedMessageException(
+            result).asInvalidProtocolBufferException();
+        }
+        return buildPartial();
+      }
+      
+      public org.apache.mina.example.filebrowser.FileBrowserProto.Entry buildPartial() {
+        org.apache.mina.example.filebrowser.FileBrowserProto.Entry returnMe = result;
+        result = null;
+        return returnMe;
+      }
+      
+      
+      // required .Name name = 1;
+      public boolean hasName() {
+        return result.hasName();
+      }
+      public org.apache.mina.example.filebrowser.FileBrowserProto.Name getName() {
+        return result.getName();
+      }
+      public Builder setName(org.apache.mina.example.filebrowser.FileBrowserProto.Name value) {
+        result.hasName = true;
+        result.name_ = value;
+        return this;
+      }
+      public Builder setName(org.apache.mina.example.filebrowser.FileBrowserProto.Name.Builder builderForValue) {
+        result.hasName = true;
+        result.name_ = builderForValue.build();
+        return this;
+      }
+      public Builder mergeName(org.apache.mina.example.filebrowser.FileBrowserProto.Name value) {
+        if (result.hasName() &&
+            result.name_ != org.apache.mina.example.filebrowser.FileBrowserProto.Name.getDefaultInstance()) {
+          result.name_ =
+            org.apache.mina.example.filebrowser.FileBrowserProto.Name.newBuilder(result.name_).mergeFrom(value).buildPartial();
+        } else {
+          result.name_ = value;
+        }
+        result.hasName = true;
+        return this;
+      }
+      public Builder clearName() {
+        result.hasName = false;
+        result.name_ = org.apache.mina.example.filebrowser.FileBrowserProto.Name.getDefaultInstance();
+        return this;
+      }
+      
+      // required int64 last_modifed = 2;
+      public boolean hasLastModifed() {
+        return result.hasLastModifed();
+      }
+      public long getLastModifed() {
+        return result.getLastModifed();
+      }
+      public Builder setLastModifed(long value) {
+        result.hasLastModifed = true;
+        result.lastModifed_ = value;
+        return this;
+      }
+      public Builder clearLastModifed() {
+        result.hasLastModifed = false;
+        result.lastModifed_ = 0L;
+        return this;
+      }
+    }
+    
+    static {
+      org.apache.mina.example.filebrowser.FileBrowserProto.getDescriptor();
+    }
+  }
+  
+  public static final class FileEntry extends
+      com.google.protobuf.GeneratedMessage {
+    // Use FileEntry.newBuilder() to construct.
+    private FileEntry() {}
+    
+    private static final FileEntry defaultInstance = new FileEntry();
+    public static FileEntry getDefaultInstance() {
+      return defaultInstance;
+    }
+    
+    public FileEntry getDefaultInstanceForType() {
+      return defaultInstance;
+    }
+    
+    public static final com.google.protobuf.Descriptors.Descriptor
+        getDescriptor() {
+      return org.apache.mina.example.filebrowser.FileBrowserProto.internal_static_FileEntry_descriptor;
+    }
+    
+    @Override
+    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+        internalGetFieldAccessorTable() {
+      return org.apache.mina.example.filebrowser.FileBrowserProto.internal_static_FileEntry_fieldAccessorTable;
+    }
+    
+    public static
+      com.google.protobuf.GeneratedMessage.GeneratedExtension<
+        org.apache.mina.example.filebrowser.FileBrowserProto.Entry,
+        java.lang.Long> lenght;
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry parseFrom(
+        com.google.protobuf.ByteString data)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data).buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry parseFrom(
+        com.google.protobuf.ByteString data,
+        com.google.protobuf.ExtensionRegistry extensionRegistry)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data, extensionRegistry)
+               .buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry parseFrom(byte[] data)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data).buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry parseFrom(
+        byte[] data,
+        com.google.protobuf.ExtensionRegistry extensionRegistry)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data, extensionRegistry)
+               .buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry parseFrom(java.io.InputStream input)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input).buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry parseFrom(
+        java.io.InputStream input,
+        com.google.protobuf.ExtensionRegistry extensionRegistry)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input, extensionRegistry)
+               .buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry parseFrom(
+        com.google.protobuf.CodedInputStream input)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input).buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry parseFrom(
+        com.google.protobuf.CodedInputStream input,
+        com.google.protobuf.ExtensionRegistry extensionRegistry)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input, extensionRegistry)
+               .buildParsed();
+    }
+    
+    public static Builder newBuilder() { return new Builder(); }
+    public Builder newBuilderForType() { return new Builder(); }
+    public static Builder newBuilder(org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry prototype) {
+      return new Builder().mergeFrom(prototype);
+    }
+    
+    public static final class Builder extends
+        com.google.protobuf.GeneratedMessage.Builder<Builder> {
+      // Construct using org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry.newBuilder()
+      private Builder() {}
+      
+      org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry result = new org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry();
+      
+      @Override
+      protected org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry internalGetResult() {
+        return result;
+      }
+      
+      @Override
+      public Builder clear() {
+        result = new org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry();
+        return this;
+      }
+      
+      @Override
+      public Builder clone() {
+        return new Builder().mergeFrom(result);
+      }
+      
+      @Override
+      public com.google.protobuf.Descriptors.Descriptor
+          getDescriptorForType() {
+        return org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry.getDescriptor();
+      }
+      
+      public org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry getDefaultInstanceForType() {
+        return org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry.getDefaultInstance();
+      }
+      
+      public org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry build() {
+        if (!isInitialized()) {
+          throw new com.google.protobuf.UninitializedMessageException(
+            result);
+        }
+        return buildPartial();
+      }
+      
+      private org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry buildParsed()
+          throws com.google.protobuf.InvalidProtocolBufferException {
+        if (!isInitialized()) {
+          throw new com.google.protobuf.UninitializedMessageException(
+            result).asInvalidProtocolBufferException();
+        }
+        return buildPartial();
+      }
+      
+      public org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry buildPartial() {
+        org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry returnMe = result;
+        result = null;
+        return returnMe;
+      }
+      
+    }
+    
+    static {
+      org.apache.mina.example.filebrowser.FileBrowserProto.getDescriptor();
+    }
+  }
+  
+  public static final class DirectoryEntry extends
+      com.google.protobuf.GeneratedMessage {
+    // Use DirectoryEntry.newBuilder() to construct.
+    private DirectoryEntry() {}
+    
+    private static final DirectoryEntry defaultInstance = new DirectoryEntry();
+    public static DirectoryEntry getDefaultInstance() {
+      return defaultInstance;
+    }
+    
+    public DirectoryEntry getDefaultInstanceForType() {
+      return defaultInstance;
+    }
+    
+    public static final com.google.protobuf.Descriptors.Descriptor
+        getDescriptor() {
+      return org.apache.mina.example.filebrowser.FileBrowserProto.internal_static_DirectoryEntry_descriptor;
+    }
+    
+    @Override
+    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+        internalGetFieldAccessorTable() {
+      return org.apache.mina.example.filebrowser.FileBrowserProto.internal_static_DirectoryEntry_fieldAccessorTable;
+    }
+    
+    public static
+      com.google.protobuf.GeneratedMessage.GeneratedExtension<
+        org.apache.mina.example.filebrowser.FileBrowserProto.Entry,
+        java.util.List<org.apache.mina.example.filebrowser.FileBrowserProto.Name>> entries;
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry parseFrom(
+        com.google.protobuf.ByteString data)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data).buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry parseFrom(
+        com.google.protobuf.ByteString data,
+        com.google.protobuf.ExtensionRegistry extensionRegistry)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data, extensionRegistry)
+               .buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry parseFrom(byte[] data)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data).buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry parseFrom(
+        byte[] data,
+        com.google.protobuf.ExtensionRegistry extensionRegistry)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data, extensionRegistry)
+               .buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry parseFrom(java.io.InputStream input)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input).buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry parseFrom(
+        java.io.InputStream input,
+        com.google.protobuf.ExtensionRegistry extensionRegistry)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input, extensionRegistry)
+               .buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry parseFrom(
+        com.google.protobuf.CodedInputStream input)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input).buildParsed();
+    }
+    public static org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry parseFrom(
+        com.google.protobuf.CodedInputStream input,
+        com.google.protobuf.ExtensionRegistry extensionRegistry)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input, extensionRegistry)
+               .buildParsed();
+    }
+    
+    public static Builder newBuilder() { return new Builder(); }
+    public Builder newBuilderForType() { return new Builder(); }
+    public static Builder newBuilder(org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry prototype) {
+      return new Builder().mergeFrom(prototype);
+    }
+    
+    public static final class Builder extends
+        com.google.protobuf.GeneratedMessage.Builder<Builder> {
+      // Construct using org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry.newBuilder()
+      private Builder() {}
+      
+      org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry result = new org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry();
+      
+      @Override
+      protected org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry internalGetResult() {
+        return result;
+      }
+      
+      @Override
+      public Builder clear() {
+        result = new org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry();
+        return this;
+      }
+      
+      @Override
+      public Builder clone() {
+        return new Builder().mergeFrom(result);
+      }
+      
+      @Override
+      public com.google.protobuf.Descriptors.Descriptor
+          getDescriptorForType() {
+        return org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry.getDescriptor();
+      }
+      
+      public org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry getDefaultInstanceForType() {
+        return org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry.getDefaultInstance();
+      }
+      
+      public org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry build() {
+        if (!isInitialized()) {
+          throw new com.google.protobuf.UninitializedMessageException(
+            result);
+        }
+        return buildPartial();
+      }
+      
+      private org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry buildParsed()
+          throws com.google.protobuf.InvalidProtocolBufferException {
+        if (!isInitialized()) {
+          throw new com.google.protobuf.UninitializedMessageException(
+            result).asInvalidProtocolBufferException();
+        }
+        return buildPartial();
+      }
+      
+      public org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry buildPartial() {
+        org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry returnMe = result;
+        result = null;
+        return returnMe;
+      }
+      
+    }
+    
+    static {
+      org.apache.mina.example.filebrowser.FileBrowserProto.getDescriptor();
+    }
+  }
+  
+  private static com.google.protobuf.Descriptors.Descriptor
+    internal_static_Name_descriptor;
+  private static
+    com.google.protobuf.GeneratedMessage.FieldAccessorTable
+      internal_static_Name_fieldAccessorTable;
+  private static com.google.protobuf.Descriptors.Descriptor
+    internal_static_Entry_descriptor;
+  private static
+    com.google.protobuf.GeneratedMessage.FieldAccessorTable
+      internal_static_Entry_fieldAccessorTable;
+  private static com.google.protobuf.Descriptors.Descriptor
+    internal_static_FileEntry_descriptor;
+  private static
+    com.google.protobuf.GeneratedMessage.FieldAccessorTable
+      internal_static_FileEntry_fieldAccessorTable;
+  private static com.google.protobuf.Descriptors.Descriptor
+    internal_static_DirectoryEntry_descriptor;
+  private static
+    com.google.protobuf.GeneratedMessage.FieldAccessorTable
+      internal_static_DirectoryEntry_fieldAccessorTable;
+  
+  public static com.google.protobuf.Descriptors.FileDescriptor
+      getDescriptor() {
+    return descriptor;
+  }
+  private static com.google.protobuf.Descriptors.FileDescriptor
+      descriptor;
+  static {
+    java.lang.String descriptorData =
+      "\n\021fileBrowser.proto\"\025\n\004Name\022\r\n\005value\030\001 \002" +
+      "(\t\"8\n\005Entry\022\023\n\004name\030\001 \002(\0132\005.Name\022\024\n\014last" +
+      "_modifed\030\002 \002(\003*\004\010\n\020\025\"#\n\tFileEntry2\026\n\006len" +
+      "ght\022\006.Entry\030\n \002(\003\"0\n\016DirectoryEntry2\036\n\007e" +
+      "ntries\022\006.Entry\030\013 \003(\0132\005.NameB7\n#org.apach" +
+      "e.mina.example.filebrowserB\020FileBrowserP" +
+      "roto";
+    com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
+      new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
+        public com.google.protobuf.ExtensionRegistry assignDescriptors(
+            com.google.protobuf.Descriptors.FileDescriptor root) {
+          descriptor = root;
+          internal_static_Name_descriptor =
+            getDescriptor().getMessageTypes().get(0);
+          internal_static_Name_fieldAccessorTable = new
+            com.google.protobuf.GeneratedMessage.FieldAccessorTable(
+              internal_static_Name_descriptor,
+              new java.lang.String[] { "Value", },
+              org.apache.mina.example.filebrowser.FileBrowserProto.Name.class,
+              org.apache.mina.example.filebrowser.FileBrowserProto.Name.Builder.class);
+          internal_static_Entry_descriptor =
+            getDescriptor().getMessageTypes().get(1);
+          internal_static_Entry_fieldAccessorTable = new
+            com.google.protobuf.GeneratedMessage.FieldAccessorTable(
+              internal_static_Entry_descriptor,
+              new java.lang.String[] { "Name", "LastModifed", },
+              org.apache.mina.example.filebrowser.FileBrowserProto.Entry.class,
+              org.apache.mina.example.filebrowser.FileBrowserProto.Entry.Builder.class);
+          internal_static_FileEntry_descriptor =
+            getDescriptor().getMessageTypes().get(2);
+          internal_static_FileEntry_fieldAccessorTable = new
+            com.google.protobuf.GeneratedMessage.FieldAccessorTable(
+              internal_static_FileEntry_descriptor,
+              new java.lang.String[] { },
+              org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry.class,
+              org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry.Builder.class);
+          org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry.lenght =
+            com.google.protobuf.GeneratedMessage.newGeneratedExtension(
+              org.apache.mina.example.filebrowser.FileBrowserProto.FileEntry.getDescriptor().getExtensions().get(0),
+              java.lang.Long.class);
+          internal_static_DirectoryEntry_descriptor =
+            getDescriptor().getMessageTypes().get(3);
+          internal_static_DirectoryEntry_fieldAccessorTable = new
+            com.google.protobuf.GeneratedMessage.FieldAccessorTable(
+              internal_static_DirectoryEntry_descriptor,
+              new java.lang.String[] { },
+              org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry.class,
+              org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry.Builder.class);
+          org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry.entries =
+            com.google.protobuf.GeneratedMessage
+              .newRepeatedGeneratedExtension(
+                org.apache.mina.example.filebrowser.FileBrowserProto.DirectoryEntry.getDescriptor().getExtensions().get(0),
+                org.apache.mina.example.filebrowser.FileBrowserProto.Name.class);
+          return null;
+        }
+      };
+    com.google.protobuf.Descriptors.FileDescriptor
+      .internalBuildGeneratedFileFrom(descriptorData,
+        new com.google.protobuf.Descriptors.FileDescriptor[] {
+        }, assigner);
+  }
+}

Added: mina/sandbox/protocol-buffers/example/src/main/java/org/apache/mina/example/filebrowser/FileBrowserServer.java
URL: http://svn.apache.org/viewvc/mina/sandbox/protocol-buffers/example/src/main/java/org/apache/mina/example/filebrowser/FileBrowserServer.java?rev=732497&view=auto
==============================================================================
--- mina/sandbox/protocol-buffers/example/src/main/java/org/apache/mina/example/filebrowser/FileBrowserServer.java (added)
+++ mina/sandbox/protocol-buffers/example/src/main/java/org/apache/mina/example/filebrowser/FileBrowserServer.java Wed Jan  7 13:12:46 2009
@@ -0,0 +1,115 @@
+/*
+ *  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.example.filebrowser;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.mina.core.service.IoHandlerAdapter;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.mina.filter.codec.protobuf.ProtobufCodecFactory;
+import org.apache.mina.filter.logging.LoggingFilter;
+import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The server that returns the details about the files and directories
+ * on client's request. Uses Google Protocol Buffer as wire format.
+ * 
+ * @author Tomasz Blachowicz
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class FileBrowserServer extends IoHandlerAdapter {
+
+	private static Logger logger = LoggerFactory.getLogger(FileBrowserServer.class);
+	
+	/**
+	 * Two optional arguments can be provided (defaults in brackets):
+	 * basedir (.) and port (6667). 
+	 * 
+	 * @param args The command line args.
+	 */
+	public static void main(String[] args) throws Exception {
+		CommandLine cmd = new CommandLine(args);
+		File baseDir = cmd.popFile(new File("."));
+		int port = cmd.popInt(6667);
+		FileBrowserServer server = new FileBrowserServer(baseDir);
+		server.listen(port);
+	}
+	
+	private final File baseDir; 
+	private final NioSocketAcceptor acceptor;
+	
+	private FileBrowserServer(File baseDir) {
+		this.baseDir = baseDir;
+		acceptor = new NioSocketAcceptor();
+	    //acceptor.getFilterChain().addLast("logger", new LoggingFilter());
+		acceptor.getFilterChain().addLast("codec",
+			new ProtocolCodecFilter(
+				ProtobufCodecFactory.newInstance(
+					FileBrowserProto.Name.getDefaultInstance())));
+	    acceptor.setHandler(this);		
+	}
+	
+	public void listen(int port) throws IOException {
+		acceptor.bind(new InetSocketAddress(port));
+	}
+	
+	@Override
+	public void messageReceived(IoSession session, Object message) throws Exception {
+		FileBrowserProto.Name name = (FileBrowserProto.Name) message;
+		File file = new File(baseDir, name.getValue());
+		if(file.exists()) {
+			logger.info("Entry '{}' exists", file);
+			FileBrowserProto.Entry.Builder entry = FileBrowserProto.Entry.newBuilder();
+			entry.setName(name);
+			entry.setLastModifed(file.lastModified());
+			if(file.isFile()) {
+				logger.info("Entry '{}' is a file", file);
+				entry.setExtension(FileBrowserProto.FileEntry.lenght, file.length());
+			}
+			if(file.isDirectory()) {
+				logger.info("Entry '{}' is a directory", file);
+				for(String fileName  : file.list()) {
+					entry.addExtension(
+						FileBrowserProto.DirectoryEntry.entries,
+						FileBrowserProto.Name.newBuilder().setValue(fileName).build());
+				}
+				
+			}
+			session.write(entry.build());
+		} else {
+			throw new FileNotFoundException(file.getPath());
+		}
+	}
+	
+	@Override
+	public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
+		logger.error("Ooops! Something went wrong :|", cause);
+	}
+	
+}

Added: mina/sandbox/protocol-buffers/example/src/test/proto/fileBrowser.proto
URL: http://svn.apache.org/viewvc/mina/sandbox/protocol-buffers/example/src/test/proto/fileBrowser.proto?rev=732497&view=auto
==============================================================================
--- mina/sandbox/protocol-buffers/example/src/test/proto/fileBrowser.proto (added)
+++ mina/sandbox/protocol-buffers/example/src/test/proto/fileBrowser.proto Wed Jan  7 13:12:46 2009
@@ -0,0 +1,24 @@
+option java_package = "org.apache.mina.example.filebrowser";
+option java_outer_classname = "FileBrowserProto";
+
+message Name {
+	required string value = 1;  
+}
+
+message Entry {
+	required Name name = 1;
+	required int64 last_modifed = 2; 
+	extensions 10 to 20;
+}
+
+message FileEntry {
+	extend Entry {
+		required int64 lenght = 10; 
+	}
+}
+
+message DirectoryEntry {
+	extend Entry {
+		repeated Name entries = 11;
+	}
+}
\ No newline at end of file

Added: mina/sandbox/protocol-buffers/filter-codec-protobuf/LICENCE.protobuf.txt
URL: http://svn.apache.org/viewvc/mina/sandbox/protocol-buffers/filter-codec-protobuf/LICENCE.protobuf.txt?rev=732497&view=auto
==============================================================================
--- mina/sandbox/protocol-buffers/filter-codec-protobuf/LICENCE.protobuf.txt (added)
+++ mina/sandbox/protocol-buffers/filter-codec-protobuf/LICENCE.protobuf.txt Wed Jan  7 13:12:46 2009
@@ -0,0 +1,33 @@
+Copyright 2008, Google Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+    * Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above
+copyright notice, this list of conditions and the following disclaimer
+in the documentation and/or other materials provided with the
+distribution.
+    * Neither the name of Google Inc. nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+Code generated by the Protocol Buffer compiler is owned by the owner
+of the input file used when generating it.  This code is not
+standalone and requires a support library to be linked with it.  This
+support library is itself covered by the above license.

Added: mina/sandbox/protocol-buffers/filter-codec-protobuf/pom.xml
URL: http://svn.apache.org/viewvc/mina/sandbox/protocol-buffers/filter-codec-protobuf/pom.xml?rev=732497&view=auto
==============================================================================
--- mina/sandbox/protocol-buffers/filter-codec-protobuf/pom.xml (added)
+++ mina/sandbox/protocol-buffers/filter-codec-protobuf/pom.xml Wed Jan  7 13:12:46 2009
@@ -0,0 +1,46 @@
+<?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>build</artifactId>
+    <version>2.0.0-RC1-SNAPSHOT</version>
+  </parent>
+  <artifactId>mina-filter-codec-protobuf</artifactId>
+  <name>Apache MINA Protobuf Codec</name>
+  <packaging>bundle</packaging>  
+  <properties>
+    <exportedPackage>${groupId}.filter.codec.protobuf</exportedPackage>
+  </properties>
+  <dependencies>
+    <dependency>
+      <groupId>${groupId}</groupId>
+      <artifactId>mina-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.google.protobuf</groupId>
+      <artifactId>protobuf-java</artifactId>
+    </dependency>
+  </dependencies>
+</project>
+

Added: mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/filter/codec/protobuf/ProtobufCodecFactory.java
URL: http://svn.apache.org/viewvc/mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/filter/codec/protobuf/ProtobufCodecFactory.java?rev=732497&view=auto
==============================================================================
--- mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/filter/codec/protobuf/ProtobufCodecFactory.java (added)
+++ mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/filter/codec/protobuf/ProtobufCodecFactory.java Wed Jan  7 13:12:46 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.
+ *
+ */
+package org.apache.mina.filter.codec.protobuf;
+
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.codec.ProtocolCodecFactory;
+import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolEncoder;
+
+import com.google.protobuf.ExtensionRegistry;
+import com.google.protobuf.Message;
+import com.google.protobuf.Message.Builder;
+
+/**
+ * Factory that is being used by MINA for creating protobuf-specific
+ * decoders and encoders. Instance of {@link ProtobufEncoder} is generic
+ * and common for different types of protobuf messages encoded to wire
+ * format. Every instance of the factory returns the same instance
+ * of {@link ProtobufDecoder} on every call of getDecoder method, but every decoder
+ * is specific for single given type of message passed as prototype while creating
+ * the instance of factory.   
+ * 
+ * @author Tomasz Blachowicz
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class ProtobufCodecFactory implements ProtocolCodecFactory  {
+
+	/**
+	 * Instance of {@link ProtobufEncoder} (singleton).
+	 */
+	private static final ProtobufEncoder ENCODER_INSTANCE = new ProtobufEncoder(); 
+	
+	/**
+	 * Factory method that creates instance of {@link ProtocolCodecFactory}
+	 * for handling Protobuf wire format.
+	 * 
+	 * @param messagePrototype Protobuf message prototype used to acquire {@link Builder}.
+	 * @return Instance of {@link ProtobufCodecFactory}.
+	 */
+	public static ProtobufCodecFactory newInstance(Message messagePrototype) {
+		return new ProtobufCodecFactory(new ProtobufDecoder(messagePrototype));
+	}
+
+	/**
+	 * Factory method that creates instance of {@link ProtocolCodecFactory}
+	 * for handling Protobuf wire format.
+	 * 
+	 * @param messagePrototype Protobuf message prototype used to acquire {@link Builder}.
+	 * @param extensionRegistry 
+	 * @return 
+	 */
+	public static ProtobufCodecFactory newInstance(
+		Message messagePrototype, ExtensionRegistry extensionRegistry) {
+		return new ProtobufCodecFactory(new ProtobufDecoder(messagePrototype, extensionRegistry));
+	}
+	
+	/**
+	 * Instance of {@link ProtocolDecoder} that can deal with the Prtobuf wire format.
+	 */
+	private final ProtobufDecoder decoder;
+	
+	/**
+	 * Private constructor used by factory methods.
+	 * 
+	 * @param decoder Instance of {@link ProtobufDecoder}.
+	 */
+	private ProtobufCodecFactory(ProtobufDecoder decoder) {
+		this.decoder = decoder;
+	}
+	
+	/**
+	 * @param session Not in use
+	 * @return Instance of {@link ProtobufDecoder}
+	 */
+	public ProtocolDecoder getDecoder(IoSession session) throws Exception {
+		return decoder;
+	}
+
+	/**
+	 * @param session Not in use
+	 * @return Instance of {@link ProtobufEncoder}
+	 */
+	public ProtocolEncoder getEncoder(IoSession session) throws Exception {
+		return ENCODER_INSTANCE;
+	}	
+	
+}

Added: mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/filter/codec/protobuf/ProtobufDecoder.java
URL: http://svn.apache.org/viewvc/mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/filter/codec/protobuf/ProtobufDecoder.java?rev=732497&view=auto
==============================================================================
--- mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/filter/codec/protobuf/ProtobufDecoder.java (added)
+++ mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/filter/codec/protobuf/ProtobufDecoder.java Wed Jan  7 13:12:46 2009
@@ -0,0 +1,112 @@
+/*
+ *  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.filter.codec.protobuf;
+
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+import com.google.protobuf.ExtensionRegistry;
+import com.google.protobuf.Message;
+
+/**
+ * Protocol decoder used to decode protobuf messages from the wire.
+ * It is based on {@link CumulativeProtocolDecoder} to deal with
+ * fragmented messages handled by the framework in asynchronous fashion.
+ * 
+ * This decoder handles single type of messages provided as prototype.
+ * However the registry of extensions {@link ExtensionRegistry} can also
+ * be provided. 
+ * 
+ * The instance of the decoder should be created by the {@link ProtobufCodecFactory},
+ * however the protected constructors has been provided for convenience.
+ * 
+ * @author Tomasz Blachowicz
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class ProtobufDecoder extends CumulativeProtocolDecoder  {
+	
+	/**
+	 * The prototype message used to decode messages.
+	 */
+	private final Message prototype;
+	
+	/**
+	 * The registry of extensions used during decoding messages with extensions.
+	 */
+	private final ExtensionRegistry extentions;
+	
+	/**
+	 * Creates instance of decoder specific for given message type.
+	 * 
+	 * @param prototype The prototype message used to decode messages.
+	 */
+	protected ProtobufDecoder(Message prototype) {
+		this(prototype, ExtensionRegistry.getEmptyRegistry());
+	}
+	
+	/**
+	 * Creates instance of decoder specific for given message type.
+	 * 
+	 * @param prototype The prototype message used to decode messages.
+	 * @param extensionRegistry The registry of extensions used during decoding
+	 * messages with extensions.
+	 */
+	protected ProtobufDecoder(Message prototype, ExtensionRegistry extensionRegistry) {
+		this.prototype = prototype;
+		this.extentions = extensionRegistry;
+	}
+	
+	/**
+	 * Decodes protobuf messages of given type from buffer. If not enough data
+	 * has been presented delegates to the {@link CumulativeProtocolDecoder} base
+	 * class to read more data from the wire.
+	 * 
+	 * It uses instance of internal {@link SizeContext} class to calculate
+	 * size of buffer expected by the given type of message. The size of every
+	 * message that arrives on the wire is specified by the prepending varint
+	 * value.
+	 * 
+	 * @param session The session used to store internal {@link SizeContext}.
+	 * @param in The buffer used to read messages if contains enough data.
+	 * @param out The output for messages decoded from data provided.
+	 * 
+	 * @see ProtobufEncoder
+	 * @see SizeContext
+	 */
+	@Override
+	protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
+		SizeContext ctx = SizeContext.get(session, in);
+		if(ctx.hasEnoughData(in)) {
+			try	{
+				Message.Builder builder = prototype.newBuilderForType();
+				ctx.getInputStream(in).readMessage(builder, extentions);
+				out.write(builder.build());
+				return true;
+			} finally {
+				ctx.shiftPositionAndReset(session, in);
+			}
+		}
+		return false;
+	}
+
+}

Added: mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/filter/codec/protobuf/ProtobufEncoder.java
URL: http://svn.apache.org/viewvc/mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/filter/codec/protobuf/ProtobufEncoder.java?rev=732497&view=auto
==============================================================================
--- mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/filter/codec/protobuf/ProtobufEncoder.java (added)
+++ mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/filter/codec/protobuf/ProtobufEncoder.java Wed Jan  7 13:12:46 2009
@@ -0,0 +1,74 @@
+/*
+ *  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.filter.codec.protobuf;
+
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+
+import com.google.protobuf.CodedOutputStream;
+import com.google.protobuf.Message;
+
+/**
+ * The protocol encoded used to encode protobuf {@link Message} into the wire format.
+ * The encoder is able to encode any protobuf message and is stateles, so the same
+ * instance can be used by many threads. In fact the {@link ProtobufCodecFactory}
+ * creates single instance of the encoder i.e. singleton.
+ * 
+ * The protobuf messages are designed to be as lightweight as possible, so there
+ * are very limited metadata included in serialized form of the message. The size
+ * of the message have to be explicitly prepended before every message. The encoded
+ * does so and encodes the size as protobuf varint (int32) value.
+ * 
+ * The instance of the encoder should be created by the {@link ProtobufCodecFactory},
+ * however the protected constructor has been provided for convenience.
+ * 
+ * @author Tomasz Blachowicz
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class ProtobufEncoder extends ProtocolEncoderAdapter {
+
+	/**
+	 * Creates the instance of the encoder.
+	 */
+	protected ProtobufEncoder() { }
+	
+	/**
+	 * Encodes the protobuf {@link Message} provided into the wire format.
+	 * 
+	 * @param session The session (not used).
+	 * @param message The protobuf {@link Message}.
+	 * @param out The encoder output used to write buffer into.
+	 */
+	public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
+		Message msg = (Message) message;
+		int size = msg.getSerializedSize();
+		IoBuffer buffer = IoBuffer.allocate(SizeContext.computeTotal(size));
+		CodedOutputStream cos = CodedOutputStream.newInstance(buffer.asOutputStream());
+		cos.writeRawVarint32(size);
+		msg.writeTo(cos);
+		cos.flush();
+		buffer.flip();
+		out.write(buffer);
+	}
+
+}
\ No newline at end of file

Added: mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/filter/codec/protobuf/SizeContext.java
URL: http://svn.apache.org/viewvc/mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/filter/codec/protobuf/SizeContext.java?rev=732497&view=auto
==============================================================================
--- mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/filter/codec/protobuf/SizeContext.java (added)
+++ mina/sandbox/protocol-buffers/filter-codec-protobuf/src/main/java/org/apache/mina/filter/codec/protobuf/SizeContext.java Wed Jan  7 13:12:46 2009
@@ -0,0 +1,138 @@
+/*
+ *  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.filter.codec.protobuf;
+
+import java.io.IOException;
+
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;
+
+import com.google.protobuf.CodedInputStream;
+import com.google.protobuf.CodedOutputStream;
+
+/**
+ * Internal class used to control expected size of data buffer.
+ * The instance is being stored in {@link IoSession} between
+ * ProtobufEncoder.doDecode calls.
+ * 
+ * @author Tomasz Blachowicz
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
+ */
+class SizeContext {
+	
+	/**
+	 * The key of attribute in {@link IoSession}.
+	 */
+	static String KEY = String.format("%s#KEY", SizeContext.class.getCanonicalName());
+	
+	/**
+	 * Expected size of the data needed to decode message.
+	 */
+	private final int size;
+
+	/**
+	 * Retrieves instance of the context form given {@link IoSession}. If there is no
+	 * attribute holding the instance of context the new one is created. In that
+	 * case the size of the message is being read from {@link IoBuffer} provided.
+	 * The size is encoded as protobuf varint (int32).   
+	 * 
+	 * @param session the session that holds instance of context as attribute 
+	 * @param in
+	 * @return
+	 * @throws IOException
+	 */
+	static SizeContext get(IoSession session, IoBuffer in) throws IOException {
+		SizeContext ctx = (SizeContext) session.getAttribute(KEY);
+		if(ctx == null) {
+			int size = CodedInputStream.newInstance(in.array(), in.position(), 5).readRawVarint32();
+			ctx = new SizeContext(SizeContext.computeTotal(size));
+			session.setAttribute(KEY, ctx);
+		}
+		return ctx;
+	}
+	
+	/**
+	 * Computes total size of the message that includes the size
+	 * itself encoded as protobuf varint (int32). In contrast to
+	 * the fixed int32 encoding varint may span from 1 up to 5 bytes.
+	 * 
+	 * The method is being used by the {@link ProtobufEncoder} to
+	 * allocate {@link IoBuffer}.
+	 * 
+	 * @param size Size of the message.
+	 * @return The total size (message size and size itself).
+	 */
+	static int computeTotal(int size) {
+		return size + CodedOutputStream.computeRawVarint32Size(size);
+	}
+	
+	/**
+	 * Creates instance of context.
+	 * 
+	 * @param size The size of the message.
+	 */
+	private SizeContext(int size) {
+		this.size = size;
+	}
+	
+	/**
+	 * Determines weather the buffer contains enough data
+	 * to decode message. Uses method IoBuffer.remaining.
+	 * 
+	 * @param in The buffer
+	 * @return <code>true</code> if buffer contains enough data,
+	 * otherwise <code>false</code>.
+	 */
+	boolean hasEnoughData(IoBuffer in) {
+		return in.remaining() >= size;
+	}
+	
+	/**
+	 * Creates the protobuf {@link CodedInputStream} from {@link IoBuffer}.
+	 * To avoid consumption of the whole buffer uses internal array and size
+	 * to extract only the slice of the buffer as source for the stream.
+	 * 
+	 * @param in The buffer
+	 * @return The protobuf stream used to read messages.
+	 */
+	CodedInputStream getInputStream(IoBuffer in) {
+		return CodedInputStream.newInstance(
+			in.array(),
+			in.position(),
+			size);
+	}
+	
+	/**
+	 * Shifts position of the {@link IoBuffer} and removes
+	 * the context from {@link IoSession}. This method is
+	 * being called once the message has been successfully
+	 * decoded and the framework can proceed with the next
+	 * message in sequence.
+	 * 
+	 * @param session The session
+	 * @param in The buffer
+	 */
+	void shiftPositionAndReset(IoSession session, IoBuffer in) {
+		in.position(in.position() + size);
+		session.removeAttribute(KEY);
+	}
+	
+}
\ No newline at end of file