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 "byte" 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 JByte extends JType {
033  
034  class JavaByte extends JavaType {
035    
036    JavaByte() {
037      super("byte", "Byte", "Byte", "TypeID.RIOType.BYTE");
038    }
039    
040    String getTypeIDObjectString() {
041      return "org.apache.hadoop.record.meta.TypeID.ByteTypeID";
042    }
043
044    void genSlurpBytes(CodeBuffer cb, String b, String s, String l) {
045      cb.append("{\n");
046      cb.append("if ("+l+"<1) {\n");
047      cb.append("throw new java.io.IOException(\"Byte is exactly 1 byte."+
048                " Provided buffer is smaller.\");\n");
049      cb.append("}\n");
050      cb.append(s+"++; "+l+"--;\n");
051      cb.append("}\n");
052    }
053    
054    void genCompareBytes(CodeBuffer cb) {
055      cb.append("{\n");
056      cb.append("if (l1<1 || l2<1) {\n");
057      cb.append("throw new java.io.IOException(\"Byte is exactly 1 byte."+
058                " Provided buffer is smaller.\");\n");
059      cb.append("}\n");
060      cb.append("if (b1[s1] != b2[s2]) {\n");
061      cb.append("return (b1[s1]<b2[s2])?-1:0;\n");
062      cb.append("}\n");
063      cb.append("s1++; s2++; l1--; l2--;\n");
064      cb.append("}\n");
065    }
066  }
067  
068  class CppByte extends CppType {
069    
070    CppByte() {
071      super("int8_t");
072    }
073    
074    String getTypeIDObjectString() {
075      return "new ::hadoop::TypeID(::hadoop::RIOTYPE_BYTE)";
076    }
077  }
078
079  public JByte() {
080    setJavaType(new JavaByte());
081    setCppType(new CppByte());
082    setCType(new CType());
083  }
084  
085  String getSignature() {
086    return "b";
087  }
088}