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