@Override
  public int encode(PositionedByteRange dst, CellMessage.Cell val) {
    CodedOutputStream os = outputStreamFromByteRange(dst);
    try {
      int before = os.spaceLeft(), after, written;
      val.writeTo(os);
      after = os.spaceLeft();
      written = before - after;
      dst.setPosition(dst.getPosition() + written);
      return written;
    } catch (IOException e) {
      throw new RuntimeException("Error while encoding type.", e);
    }
  }
An example for using protobuf objects with {@link DataType} API.
hbase-examples/src/main/java/org/apache/hadoop/hbase/types/PBCell.java