001package net.gdface.codegen.thrift.metadata; 002 003import com.facebook.swift.codec.ThriftField.Requiredness; 004import com.facebook.swift.codec.metadata.DecoratorThriftFieldMetadata; 005import com.facebook.swift.codec.metadata.ThriftFieldMetadataUtil; 006import com.google.common.base.Function; 007 008import net.gdface.annotation.CodegenRequired; 009import static net.gdface.codegen.thrift.metadata.CodegenPreAllocFilter.PREALLOC_FILTER; 010 011public class ErpcTypePrefixGetter implements Function<DecoratorThriftFieldMetadata, String> { 012 public static final ErpcTypePrefixGetter TYPE_PREFIX_GETTER = new ErpcTypePrefixGetter(); 013 public ErpcTypePrefixGetter() { 014 } 015 016 @Override 017 public String apply(DecoratorThriftFieldMetadata input) { 018 if(!PREALLOC_FILTER.apply(input)){ 019 if(!Requiredness.REQUIRED.equals(input.getRequiredness())){ 020 CodegenRequired ann = ThriftFieldMetadataUtil.extractFieldAnnotation(input,CodegenRequired.class); 021 if(ann == null || !ann.value()){ 022 switch (input.getErpcType().getProtocolType()) { 023 case LIST: 024 case STRING: 025 case BINARY: 026 return ""; 027 default: 028 return "byref "; 029 } 030 } 031 } 032 033 } 034 return ""; 035 } 036 037}