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 */
018
019 package org.apache.hadoop.record.compiler;
020
021 import org.apache.hadoop.classification.InterfaceAudience;
022 import org.apache.hadoop.classification.InterfaceStability;
023
024
025 /**
026 * Code generator for "int" type
027 *
028 * @deprecated Replaced by <a href="https://hadoop.apache.org/avro/">Avro</a>.
029 */
030 @Deprecated
031 @InterfaceAudience.Public
032 @InterfaceStability.Stable
033 public class JInt extends JType {
034
035 class JavaInt extends JavaType {
036
037 JavaInt() {
038 super("int", "Int", "Integer", "TypeID.RIOType.INT");
039 }
040
041 @Override
042 String getTypeIDObjectString() {
043 return "org.apache.hadoop.record.meta.TypeID.IntTypeID";
044 }
045
046 @Override
047 void genSlurpBytes(CodeBuffer cb, String b, String s, String l) {
048 cb.append("{\n");
049 cb.append("int i = org.apache.hadoop.record.Utils.readVInt("+b+", "+s+");\n");
050 cb.append("int z = org.apache.hadoop.record.Utils.getVIntSize(i);\n");
051 cb.append(s+"+=z; "+l+"-=z;\n");
052 cb.append("}\n");
053 }
054
055 @Override
056 void genCompareBytes(CodeBuffer cb) {
057 cb.append("{\n");
058 cb.append("int i1 = org.apache.hadoop.record.Utils.readVInt(b1, s1);\n");
059 cb.append("int i2 = org.apache.hadoop.record.Utils.readVInt(b2, s2);\n");
060 cb.append("if (i1 != i2) {\n");
061 cb.append("return ((i1-i2) < 0) ? -1 : 0;\n");
062 cb.append("}\n");
063 cb.append("int z1 = org.apache.hadoop.record.Utils.getVIntSize(i1);\n");
064 cb.append("int z2 = org.apache.hadoop.record.Utils.getVIntSize(i2);\n");
065 cb.append("s1+=z1; s2+=z2; l1-=z1; l2-=z2;\n");
066 cb.append("}\n");
067 }
068 }
069
070 class CppInt extends CppType {
071
072 CppInt() {
073 super("int32_t");
074 }
075
076 @Override
077 String getTypeIDObjectString() {
078 return "new ::hadoop::TypeID(::hadoop::RIOTYPE_INT)";
079 }
080 }
081
082 /** Creates a new instance of JInt */
083 public JInt() {
084 setJavaType(new JavaInt());
085 setCppType(new CppInt());
086 setCType(new CType());
087 }
088
089 @Override
090 String getSignature() {
091 return "i";
092 }
093 }