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/**
026 * @deprecated Replaced by <a href="https://hadoop.apache.org/avro/">Avro</a>.
027 */
028@Deprecated
029@InterfaceAudience.Public
030@InterfaceStability.Stable
031public class JString extends JCompType {
032    
033  class JavaString extends JavaCompType {
034    
035    JavaString() {
036      super("String", "String", "String", "TypeID.RIOType.STRING");
037    }
038    
039    String getTypeIDObjectString() {
040      return "org.apache.hadoop.record.meta.TypeID.StringTypeID";
041    }
042
043    void genSlurpBytes(CodeBuffer cb, String b, String s, String l) {
044      cb.append("{\n");
045      cb.append("int i = org.apache.hadoop.record.Utils.readVInt("+b+", "+s+");\n");
046      cb.append("int z = org.apache.hadoop.record.Utils.getVIntSize(i);\n");
047      cb.append(s+"+=(z+i); "+l+"-= (z+i);\n");
048      cb.append("}\n");
049    }
050    
051    void genCompareBytes(CodeBuffer cb) {
052      cb.append("{\n");
053      cb.append("int i1 = org.apache.hadoop.record.Utils.readVInt(b1, s1);\n");
054      cb.append("int i2 = org.apache.hadoop.record.Utils.readVInt(b2, s2);\n");
055      cb.append("int z1 = org.apache.hadoop.record.Utils.getVIntSize(i1);\n");
056      cb.append("int z2 = org.apache.hadoop.record.Utils.getVIntSize(i2);\n");
057      cb.append("s1+=z1; s2+=z2; l1-=z1; l2-=z2;\n");
058      cb.append("int r1 = org.apache.hadoop.record.Utils.compareBytes(b1,s1,i1,b2,s2,i2);\n");
059      cb.append("if (r1 != 0) { return (r1<0)?-1:0; }\n");
060      cb.append("s1+=i1; s2+=i2; l1-=i1; l1-=i2;\n");
061      cb.append("}\n");
062    }
063    
064    void genClone(CodeBuffer cb, String fname) {
065      cb.append(Consts.RIO_PREFIX + "other."+fname+" = this."+fname+";\n");
066    }
067  }
068
069  class CppString extends CppCompType {
070    
071    CppString() {
072      super("::std::string");
073    }
074    
075    String getTypeIDObjectString() {
076      return "new ::hadoop::TypeID(::hadoop::RIOTYPE_STRING)";
077    }
078  }
079  
080  /** Creates a new instance of JString */
081  public JString() {
082    setJavaType(new JavaString());
083    setCppType(new CppString());
084    setCType(new CCompType());
085  }
086    
087  String getSignature() {
088    return "s";
089  }
090}