1 /*
   2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 
  25 package org.graalvm.compiler.core.common.util;
  26 
  27 /**
  28  * Provides low-level read access for signed and unsigned values of size 1, 2, 4, and 8 bytes.
  29  */
  30 public interface TypeReader {
  31 
  32     /** Returns the next byte index to be read. */
  33     long getByteIndex();
  34 
  35     /** Sets the next byte index to be read. */
  36     void setByteIndex(long byteIndex);
  37 
  38     /** Reads a signed 1 byte value. */
  39     int getS1();
  40 
  41     /** Reads an unsigned 1 byte value. */
  42     int getU1();
  43 
  44     /** Reads a signed 2 byte value. */
  45     int getS2();
  46 
  47     /** Reads an unsigned 2 byte value. */
  48     int getU2();
  49 
  50     /** Reads a signed 4 byte value. */
  51     int getS4();
  52 
  53     /** Reads an unsigned 4 byte value. */
  54     long getU4();
  55 
  56     /** Reads a signed 4 byte value. */
  57     long getS8();
  58 
  59     /**
  60      * Reads a signed value that has been written using {@link TypeWriter#putSV variable byte size
  61      * encoding}.
  62      */
  63     long getSV();
  64 
  65     /**
  66      * Reads a signed variable byte size encoded value that is known to fit into the range of int.
  67      */
  68     default int getSVInt() {
  69         return TypeConversion.asS4(getSV());
  70     }
  71 
  72     /**
  73      * Reads an unsigned value that has been written using {@link TypeWriter#putSV variable byte
  74      * size encoding}.
  75      */
  76     long getUV();
  77 
  78     /**
  79      * Reads an unsigned variable byte size encoded value that is known to fit into the range of
  80      * int.
  81      */
  82     default int getUVInt() {
  83         return TypeConversion.asS4(getUV());
  84     }
  85 }