Buffalo Protocal

Before buffalo 2.0, buffalo is using the burlap protocal from caucho. From 2.0 version, buffalo have a new protocal definition and implementation which is proper for web and faster. Buffalo is using this xml based lightweight protocal to serialize java object. The javascript client will deserialize the xml to javascript objects. When making a remote call, buffalo client will serialize the remote call to xml, and the java side will deserialize it. This document will cover the protocal specification.

Overview of the protocal

Buffalo protocal is utf-8 protocal. The xml encoding support utf-8 only, otherwise an ProtocalExcption will be thrown during parsing.

TagDescriptionMapped Java ClassMapped Javascript Class
booleanthe boolean value, 1 means true and 0 means falsejava.lang.Boolean , boolean.classboolean
datedate, ISO8609 format, for example 20061011T230201Z means Oct 11 2006, 23:02:01java.util.DateDate
intint valuejava.lang.Integer, java.lang.Short, java.lang.Byte and their primitive typesint
longlong valuejava.lang.Long and its primitive typeint
nullnull valuenullnull or undefined
stringstringjava.lang.String, java.lang.Character, char.classString
typeindicate the type of the list or mapN/AN/A
lengthindicate the length of the listN/AN/A
listlist or array data structurejava.util.Collection capatible or ArrayArray
mapmap or object data structurejava.util.Map assignable or java beanobject
doubledoublejava.lang.Double, java.lang.Float and their primitive typesfloat
refreference of an objectN/AN/A
faultexceptionwill NOT convert from client side as throw an exception from client side make no senseBuffalo.Fault
buffalo-callthe root element of client remote callN/AN/A
methodthe method client want to callN/AN/A
buffalo-replythe root element of the server replyN/AN/A

A sample request from client to server is:

<buffalo-call>
  <method>sum</method>
  <double>1</double>
  <double>2</double>
</buffalo-call>

and the response:

<buffalo-reply>
  <double>3.0</double>
</buffalo-call>

list

Array or java.util.Collection assignable value will be convert to list.

List list = new ArrayList();
list.add("String#1");
list.add("String#2");

will serialize to

<list>
  <type>java.util.ArrayList</type>
  <length>2</length>
  <string>String#1</string>
  <string>String#2</string>
</list>

For array:

String[] strings = new String[]{"String#1", "String#2"}

will serialize to

<list>
  <type>[java.lang.String</type>
  <length>2</length>
  <string>String#1</string>
  <string>String#2</string>
</list>

map

map indicate a map-liked data structure. the java.util.Map assignable value or POJO will use this tag.

Map map = new HashMap()
map.put("key1", "value1");
map.put(new Integer(1), new Double(2.0));

will serialize to

<map>
  <type>java.util.HashMap</type>
  <string>key1</string>
  <string>value1</string>
  <int>1</int>
  <double>2.0</double>
</map>

For POJO

package domain;
class User {
  String name;
  int age;
  boolean gendor;
  
  //getters & setters... 
}

User u = new User("John Smith", 30, true);

Will convert to

<map>
  <type>domain.user</type>
  <string>name</string>
  <string>John Smith</string>
  <string>age</string>
  <int>age</int>
  <string>gendor</string>
  <boolean>1</boolean>
</map>

TO BE CONTINUED...