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 "buffer" 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 JBuffer extends JCompType { 034 035 class JavaBuffer extends JavaCompType { 036 037 JavaBuffer() { 038 super("org.apache.hadoop.record.Buffer", "Buffer", 039 "org.apache.hadoop.record.Buffer", "TypeID.RIOType.BUFFER"); 040 } 041 042 @Override 043 String getTypeIDObjectString() { 044 return "org.apache.hadoop.record.meta.TypeID.BufferTypeID"; 045 } 046 047 @Override 048 void genCompareTo(CodeBuffer cb, String fname, String other) { 049 cb.append(Consts.RIO_PREFIX + "ret = "+fname+".compareTo("+other+");\n"); 050 } 051 052 @Override 053 void genEquals(CodeBuffer cb, String fname, String peer) { 054 cb.append(Consts.RIO_PREFIX + "ret = "+fname+".equals("+peer+");\n"); 055 } 056 057 @Override 058 void genHashCode(CodeBuffer cb, String fname) { 059 cb.append(Consts.RIO_PREFIX + "ret = "+fname+".hashCode();\n"); 060 } 061 062 @Override 063 void genSlurpBytes(CodeBuffer cb, String b, String s, String l) { 064 cb.append("{\n"); 065 cb.append("int i = org.apache.hadoop.record.Utils.readVInt("+ 066 b+", "+s+");\n"); 067 cb.append("int z = org.apache.hadoop.record.Utils.getVIntSize(i);\n"); 068 cb.append(s+" += z+i; "+l+" -= (z+i);\n"); 069 cb.append("}\n"); 070 } 071 072 @Override 073 void genCompareBytes(CodeBuffer cb) { 074 cb.append("{\n"); 075 cb.append("int i1 = org.apache.hadoop.record.Utils.readVInt(b1, s1);\n"); 076 cb.append("int i2 = org.apache.hadoop.record.Utils.readVInt(b2, s2);\n"); 077 cb.append("int z1 = org.apache.hadoop.record.Utils.getVIntSize(i1);\n"); 078 cb.append("int z2 = org.apache.hadoop.record.Utils.getVIntSize(i2);\n"); 079 cb.append("s1+=z1; s2+=z2; l1-=z1; l2-=z2;\n"); 080 cb.append("int r1 = org.apache.hadoop.record.Utils.compareBytes(b1,s1,i1,b2,s2,i2);\n"); 081 cb.append("if (r1 != 0) { return (r1<0)?-1:0; }\n"); 082 cb.append("s1+=i1; s2+=i2; l1-=i1; l1-=i2;\n"); 083 cb.append("}\n"); 084 } 085 } 086 087 class CppBuffer extends CppCompType { 088 089 CppBuffer() { 090 super(" ::std::string"); 091 } 092 093 @Override 094 void genGetSet(CodeBuffer cb, String fname) { 095 cb.append("virtual const "+getType()+"& get"+toCamelCase(fname)+"() const {\n"); 096 cb.append("return "+fname+";\n"); 097 cb.append("}\n"); 098 cb.append("virtual "+getType()+"& get"+toCamelCase(fname)+"() {\n"); 099 cb.append("return "+fname+";\n"); 100 cb.append("}\n"); 101 } 102 103 @Override 104 String getTypeIDObjectString() { 105 return "new ::hadoop::TypeID(::hadoop::RIOTYPE_BUFFER)"; 106 } 107 108 } 109 /** Creates a new instance of JBuffer */ 110 public JBuffer() { 111 setJavaType(new JavaBuffer()); 112 setCppType(new CppBuffer()); 113 setCType(new CCompType()); 114 } 115 116 @Override 117 String getSignature() { 118 return "B"; 119 } 120 }