net.gdface.thrift.Swift2ThriftyStructTransformer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common-thrifty Show documentation
Show all versions of common-thrifty Show documentation
common tools for Thrift/Swift
package net.gdface.thrift;
import static com.google.common.base.Preconditions.*;
import static net.gdface.thrift.ThriftyStructMetadata.STRUCTS_CACHE;
import java.util.Map;
import com.facebook.swift.codec.metadata.ThriftStructMetadata;
import com.google.common.base.Function;
import com.microsoft.thrifty.Struct;
import static net.gdface.thrift.ThriftUtils.*;
/**
* 有{@link com.facebook.swift.codec.ThriftStruct}注释的类型之间的转换
* @author guyadong
*
* @param
* @param
*/
public class Swift2ThriftyStructTransformer implements Function{
private final ThriftStructMetadata leftMetadata;
private final ThriftyStructMetadata rightMetadata;
public Swift2ThriftyStructTransformer(Class left, Class right) {
this.leftMetadata = CATALOG.getThriftStructMetadata(checkNotNull(left,"left is null"));
this.rightMetadata = STRUCTS_CACHE.getUnchecked(checkNotNull(right,"right is null"));
}
@Override
public R apply(L input) {
if(null == input){
return null;
}
Map data = getFieldValues(input,leftMetadata);
return rightMetadata.constructStruct(data);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder()
.append("Swift2ThriftyStructTransformer [leftClass=")
.append(leftMetadata.getStructType())
.append(", rightClass=")
.append(rightMetadata.getStructType())
.append("]");
return builder.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy