/**
 * Copyright 2012 Twitter, Inc.
 *
 * Licensed 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 redelm.io;

abstract public class RecordConsumer {

  abstract public void startMessage();
  abstract public void endMessage();

  abstract public void startField(String field, int index);
  abstract public void endField(String field, int index);

  abstract public void startGroup();
  abstract public void endGroup();

  abstract public void addInt(int value);
  abstract public void addLong(long value);
  abstract public void addString(String value);
  abstract public void addBoolean(boolean value);
  abstract public void addBinary(byte[] value);
  abstract public void addFloat(float value);
  abstract public void addDouble(double value);

}

/**
 * Copyright 2012 Twitter, Inc.
 *
 * Licensed 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 redelm.io;

/**
 *
 * Abstraction for writing or consuming records
 * It decouples the striping/assembly algorithm from the actual record model
 * example:
 * <pre>
 * startMessage()
 *  startField("A", 0)
 *   addValue(1)
 *   addValue(2)
 *  endField("A", 0)
 *  startField("B", 1)
 *   startGroup()
 *    startField("C", 0)
 *     addValue(3)
 *    endField("C", 0)
 *   endGroup()
 *  endField("B", 1)
 * endMessage()
 * </pre>
 *
 * would produce the following message:
 * <pre>
 * {
 *   A: [1, 2]
 *   B: {
 *     C: 3
 *   }
 * }
 * </pre>
 * @author Julien Le Dem
 *
 */
abstract public class RecordConsumer {

  /**
   * start a new record
   */
  abstract public void startMessage();

  /**
   * end of a record
   */
  abstract public void endMessage();

  /**
   * start of a field in a group or message
   * if the field is repeated the field is started only once and all values added in between start and end
   * @param field name of the field
   * @param index of the field in the group or message
   */
  abstract public void startField(String field, int index);

  /**
   * end of a field in a group or message
   * @param field name of the field
   * @param index of the field in the group or message
   */
  abstract public void endField(String field, int index);

  /**
   * start of a group in a field
   */
  abstract public void startGroup();

  /**
   * end of a group in a field
   */
  abstract public void endGroup();

  /**
   * add an int value in the current field
   * @param value
   */
  abstract public void addInt(int value);

  /**
   * add a long value in the current field
   * @param value
   */
  abstract public void addLong(long value);

  /**
   * add a string value in the current field
   * @param value
   */
  abstract public void addString(String value);

  /**
   * add a boolean value in the current field
   * @param value
   */
  abstract public void addBoolean(boolean value);

  /**
   * add a binary value in the current field
   * @param value
   */
  abstract public void addBinary(byte[] value);

  /**
   * add a float value in the current field
   * @param value
   */
  abstract public void addFloat(float value);

  /**
   * add a double value in the current field
   * @param value
   */
  abstract public void addDouble(double value);

}

add javadoc