1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package org.apache.hadoop.record.compiler; 20 21 /** 22 * Code generator for "byte" type. 23 */ 24 public class JByte extends JType { 25 26 class JavaByte extends JavaType { 27 JavaByte()28 JavaByte() { 29 super("byte", "Byte", "Byte", "TypeID.RIOType.BYTE"); 30 } 31 getTypeIDObjectString()32 String getTypeIDObjectString() { 33 return "org.apache.hadoop.record.meta.TypeID.ByteTypeID"; 34 } 35 genSlurpBytes(CodeBuffer cb, String b, String s, String l)36 void genSlurpBytes(CodeBuffer cb, String b, String s, String l) { 37 cb.append("{\n"); 38 cb.append("if ("+l+"<1) {\n"); 39 cb.append("throw new java.io.IOException(\"Byte is exactly 1 byte."+ 40 " Provided buffer is smaller.\");\n"); 41 cb.append("}\n"); 42 cb.append(s+"++; "+l+"--;\n"); 43 cb.append("}\n"); 44 } 45 genCompareBytes(CodeBuffer cb)46 void genCompareBytes(CodeBuffer cb) { 47 cb.append("{\n"); 48 cb.append("if (l1<1 || l2<1) {\n"); 49 cb.append("throw new java.io.IOException(\"Byte is exactly 1 byte."+ 50 " Provided buffer is smaller.\");\n"); 51 cb.append("}\n"); 52 cb.append("if (b1[s1] != b2[s2]) {\n"); 53 cb.append("return (b1[s1]<b2[s2])?-1:0;\n"); 54 cb.append("}\n"); 55 cb.append("s1++; s2++; l1--; l2--;\n"); 56 cb.append("}\n"); 57 } 58 } 59 60 class CppByte extends CppType { 61 CppByte()62 CppByte() { 63 super("int8_t"); 64 } 65 getTypeIDObjectString()66 String getTypeIDObjectString() { 67 return "new ::hadoop::TypeID(::hadoop::RIOTYPE_BYTE)"; 68 } 69 } 70 JByte()71 public JByte() { 72 setJavaType(new JavaByte()); 73 setCppType(new CppByte()); 74 setCType(new CType()); 75 } 76 getSignature()77 String getSignature() { 78 return "b"; 79 } 80 } 81