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;
022import org.apache.hadoop.hbase.CellScanner;
023import org.apache.hadoop.hbase.HBaseInterfaceAudience;
024import org.apache.hadoop.hbase.io.CellOutputStream;
025import org.apache.hadoop.hbase.nio.ByteBuff;
026import org.apache.yetus.audience.InterfaceAudience;
027
028/**
029 * Encoder/Decoder for Cell.
030 * <p>
031 * Like {@link org.apache.hadoop.hbase.io.encoding.DataBlockEncoder} only Cell-based rather than
032 * KeyValue version 1 based and without presuming an hfile context. Intent is an Interface that will
033 * work for hfile and rpc.
034 */
035@InterfaceAudience.LimitedPrivate({ HBaseInterfaceAudience.COPROC, HBaseInterfaceAudience.PHOENIX })
036public interface Codec {
037  // TODO: interfacing with {@link org.apache.hadoop.hbase.io.encoding.DataBlockEncoder}
038  /**
039   * Call flush when done. Some encoders may not put anything on the stream until flush is called.
040   * On flush, let go of any resources used by the encoder.
041   */
042  interface Encoder extends CellOutputStream {
043  }
044
045  /**
046   * Implementations should implicitly clean up any resources allocated when the Decoder/CellScanner
047   * runs off the end of the cell block. Do this rather than require the user call close explicitly.
048   */
049  interface Decoder extends CellScanner {
050  }
051
052  Decoder getDecoder(InputStream is);
053
054  Decoder getDecoder(ByteBuff buf);
055
056  Encoder getEncoder(OutputStream os);
057}