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