FileDocCategorySizeDatePackage
ProtoBufType.javaAPI DocAndroid 1.5 API5143Wed May 06 22:41:34 BST 2009com.google.common.io.protocol

ProtoBufType

public class ProtoBufType extends Object
This class can be used to create a memory model of a .proto file. Currently, it is assumed that tags ids are not large. This could be improved by storing a start offset, relaxing the assumption to a dense number space.

Fields Summary
public static final int
TYPE_UNDEFINED
public static final int
TYPE_DOUBLE
public static final int
TYPE_FLOAT
public static final int
TYPE_INT64
public static final int
TYPE_UINT64
public static final int
TYPE_INT32
public static final int
TYPE_FIXED64
public static final int
TYPE_FIXED32
public static final int
TYPE_BOOL
public static final int
TYPE_DATA
public static final int
TYPE_GROUP
public static final int
TYPE_MESSAGE
public static final int
TYPE_TEXT
public static final int
TYPE_UINT32
public static final int
TYPE_ENUM
public static final int
TYPE_SFIXED32
public static final int
TYPE_SFIXED64
public static final int
TYPE_SINT32
public static final int
TYPE_SINT64
public static final int
TYPE_BYTES
public static final int
TYPE_STRING
public static final int
MASK_TYPE
public static final int
MASK_MODIFIER
public static final int
REQUIRED
public static final int
OPTIONAL
public static final int
REPEATED
private final StringBuffer
types
private final Vector
data
private final String
typeName
Constructors Summary
public ProtoBufType()
Empty constructor.

  
       
    
    typeName = null;
  
public ProtoBufType(String typeName)
Constructor including a type name for debugging purposes.

    this.typeName = typeName;
  
Methods Summary
public com.google.common.io.protocol.ProtoBufTypeaddElement(int optionsAndType, int tag, java.lang.Object data)
Adds a tag description. The data parameter contains the group definition for group elements and the default value for regular elements.

param
optionsAndType any legal combination (bitwise or) of REQUIRED or OPTIONAL and REPEATED and one of the TYPE_ constants
param
tag the tag id
param
data the type for group elements (or the default value for regular elements in future versions)
return
this is returned to permit cascading

    while (types.length() <= tag) {
      types.append((char) TYPE_UNDEFINED);
      this.data.addElement(null);
    }
    types.setCharAt(tag, (char) optionsAndType);
    this.data.setElementAt(data, tag);

    return this;
  
public booleanequals(java.lang.Object object)
{@inheritDoc}

Two ProtoBufTypes are equals if the fields types are the same.

    if (null == object) {
      // trivial check
      return false;
    } else if (this == object) {
      // trivial check
      return true;
    } else if (this.getClass() != object.getClass()) {
      // different class
      return false;
    }
    ProtoBufType other = (ProtoBufType) object;

    return stringEquals(types, other.types);
  
public java.lang.ObjectgetData(int tag)
Returns the data associated to a given tag (either the default value for regular elements or a ProtoBufType for groups and messages). For undefined tags, null is returned.

    return (tag < 0 || tag >= data.size()) ? null : data.elementAt(tag);
  
public intgetModifiers(int tag)
Returns a bit combination of the modifiers for the given tag id (OPTIONAL, REPEATED, REQUIRED). For undefined tags, OPTIONAL|REPEATED is returned.

    return (tag < 0 || tag >= types.length()) 
        ? (OPTIONAL | REPEATED)
        : (types.charAt(tag) & MASK_MODIFIER);
  
public intgetType(int tag)
Returns the type for the given tag id (without modifiers such as OPTIONAL, REPEATED). For undefined tags, TYPE_UNDEFINED is returned.

    return (tag < 0 || tag >= types.length()) 
        ? TYPE_UNDEFINED
        : (types.charAt(tag) & MASK_TYPE);
  
public inthashCode()
{@inheritDoc}

    if (types != null) {
      return types.hashCode();
    } else {
      return super.hashCode();
    }
  
public static booleanstringEquals(java.lang.CharSequence a, java.lang.CharSequence b)

    if (a == b) return true;
    int length;
    if (a != null && b != null && (length = a.length()) == b.length()) {
      if (a instanceof String && b instanceof String) {
        return a.equals(b);
      } else {
        for (int i = 0; i < length; i++) {
          if (a.charAt(i) != b.charAt(i)) return false;
        }
        return true;
      }
    }
    return false;
  
public java.lang.StringtoString()
Returns the type name set in the constructor for debugging purposes.

    return typeName;