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.types;
019
020import org.apache.hadoop.hbase.util.Order;
021import org.apache.hadoop.hbase.util.PositionedByteRange;
022import org.apache.yetus.audience.InterfaceAudience;
023
024/**
025 * An {@code DataType} that encodes fixed-length values encoded using
026 * {@link org.apache.hadoop.hbase.util.Bytes#putBytes( byte[], int, byte[], int, int)}. Intended to
027 * make it easier to transition away from direct use of {@link org.apache.hadoop.hbase.util.Bytes}.
028 * @see org.apache.hadoop.hbase.util.Bytes#putBytes(byte[], int, byte[], int, int)
029 * @see RawBytes
030 * @see OrderedBlob
031 * @see OrderedBlobVar
032 */
033@InterfaceAudience.Public
034public class RawBytesFixedLength extends FixedLengthWrapper<byte[]> {
035
036  /**
037   * Create a {@code RawBytesFixedLength} using the specified {@code order} and {@code length}.
038   */
039  public RawBytesFixedLength(Order order, int length) {
040    super(new RawBytes(order), length);
041  }
042
043  /**
044   * Create a {@code RawBytesFixedLength} of the specified {@code length}.
045   */
046  public RawBytesFixedLength(int length) {
047    super(new RawBytes(), length);
048  }
049
050  /**
051   * Read a {@code byte[]} from the buffer {@code src}.
052   */
053  public byte[] decode(PositionedByteRange src, int length) {
054    return ((RawBytes) base).decode(src, length);
055  }
056
057  /**
058   * Write {@code val} into {@code buff}, respecting {@code offset} and {@code length}.
059   */
060  public int encode(PositionedByteRange dst, byte[] val, int voff, int vlen) {
061    return ((RawBytes) base).encode(dst, val, voff, vlen);
062  }
063}