• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 Google Inc. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.flatbuffers;
18 
19 import static com.google.flatbuffers.Constants.*;
20 import java.nio.ByteBuffer;
21 import java.nio.ByteOrder;
22 import java.nio.charset.Charset;
23 
24 /**
25  * Helper type for accessing vector of signed or unsigned 32-bit values.
26  */
27 public final class IntVector extends BaseVector {
28   /**
29    * Assigns vector access object to vector data.
30    *
31    * @param _vector Start data of a vector.
32    * @param _bb Table's ByteBuffer.
33    * @return Returns current vector access object assigned to vector data whose offset is stored at
34    *         `vector`.
35    */
__assign(int _vector, ByteBuffer _bb)36   public IntVector __assign(int _vector, ByteBuffer _bb) {
37     __reset(_vector, Constants.SIZEOF_INT, _bb); return this;
38   }
39 
40   /**
41    * Reads the integer at the given index.
42    *
43    * @param j The index from which the integer will be read.
44    * @return the 32-bit value at the given index.
45    */
get(int j)46   public int get(int j) {
47     return bb.getInt(__element(j));
48   }
49 
50   /**
51    * Reads the integer at the given index, zero-extends it to type long, and returns the result,
52    * which is therefore in the range 0 through 4294967295.
53    *
54    * @param j The index from which the integer will be read.
55    * @return the unsigned 32-bit at the given index.
56    */
getAsUnsigned(int j)57   public long getAsUnsigned(int j) {
58     return (long) get(j) & 0xFFFFFFFFL;
59   }
60 }
61