@Override
public void write(T instance, TProtocol protocol)
throws Exception
{
TProtocolWriter writer = new TProtocolWriter(protocol);
writer.writeStructBegin(metadata.getStructName());
for (ThriftFieldMetadata fieldMetadata : metadata.getFields(THRIFT_FIELD)) {
// is the field readable?
if (fieldMetadata.isWriteOnly()) {
continue;
}
// get the field value
Object fieldValue = getFieldValue(instance, fieldMetadata);
// write the field
if (fieldValue != null) {
@SuppressWarnings("unchecked")
ThriftCodec<Object> codec = (ThriftCodec<Object>) fields.get(fieldMetadata.getId());
writer.writeField(fieldMetadata.getName(), fieldMetadata.getId(), codec, fieldValue);
}
}
writer.writeStructEnd();
}