1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.apache.hadoop.hbase.types;
19
20 import org.apache.hadoop.classification.InterfaceAudience;
21 import org.apache.hadoop.classification.InterfaceStability;
22 import org.apache.hadoop.hbase.util.Bytes;
23 import org.apache.hadoop.hbase.util.Order;
24 import org.apache.hadoop.hbase.util.PositionedByteRange;
25
26 /**
27 * An {@code DataType} that encodes fixed-length values encoded using
28 * {@link Bytes#putBytes(byte[], int, byte[], int, int)}. Intended to make it
29 * easier to transition away from direct use of {@link Bytes}.
30 * @see Bytes#putBytes(byte[], int, byte[], int, int)
31 * @see RawBytes
32 * @see OrderedBlob
33 * @see OrderedBlobVar
34 */
35 @InterfaceAudience.Public
36 @InterfaceStability.Evolving
37 public class RawBytesFixedLength extends FixedLengthWrapper<byte[]> {
38
39 /**
40 * Create a {@code RawBytesFixedLength} using the specified {@code order}
41 * and {@code length}.
42 */
43 public RawBytesFixedLength(Order order, int length) {
44 super(new RawBytes(order), length);
45 }
46
47 /**
48 * Create a {@code RawBytesFixedLength} of the specified {@code length}.
49 */
50 public RawBytesFixedLength(int length) {
51 super(new RawBytes(), length);
52 }
53
54 /**
55 * Read a {@code byte[]} from the buffer {@code src}.
56 */
57 public byte[] decode(PositionedByteRange src, int length) {
58 return ((RawBytes) base).decode(src, length);
59 }
60
61 /**
62 * Write {@code val} into {@code buff}, respecting {@code offset} and
63 * {@code length}.
64 */
65 public int encode(PositionedByteRange dst, byte[] val, int voff, int vlen) {
66 return ((RawBytes) base).encode(dst, val, voff, vlen);
67 }
68 }