001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.codec;
019
020import java.io.InputStream;
021import java.io.OutputStream;
022
023import org.apache.hadoop.hbase.CellScanner;
024import org.apache.hadoop.hbase.HBaseInterfaceAudience;
025import org.apache.hadoop.hbase.io.CellOutputStream;
026import org.apache.hadoop.hbase.nio.ByteBuff;
027import org.apache.yetus.audience.InterfaceAudience;
028
029/**
030 * Encoder/Decoder for Cell.
031 *
032 * <p>Like {@link org.apache.hadoop.hbase.io.encoding.DataBlockEncoder} 
033 * only Cell-based rather than KeyValue version 1 based
034 * and without presuming an hfile context.  Intent is an Interface that will work for hfile and
035 * rpc.
036 */
037@InterfaceAudience.LimitedPrivate({HBaseInterfaceAudience.COPROC, HBaseInterfaceAudience.PHOENIX})
038public interface Codec {
039  // TODO: interfacing with {@link org.apache.hadoop.hbase.io.encoding.DataBlockEncoder}
040  /**
041   * Call flush when done.  Some encoders may not put anything on the stream until flush is called.
042   * On flush, let go of any resources used by the encoder.
043   */
044  interface Encoder extends CellOutputStream {}
045
046  /**
047   * Implementations should implicitly clean up any resources allocated when the
048   * Decoder/CellScanner runs off the end of the cell block. Do this rather than require the user
049   * call close explicitly.
050   */
051  interface Decoder extends CellScanner {}
052
053  Decoder getDecoder(InputStream is);
054  Decoder getDecoder(ByteBuff buf);
055  Encoder getEncoder(OutputStream os);
056}