krickert commented on PR #3451:
URL: https://github.com/apache/tika/pull/3451#issuecomment-6477630494

   So the plugin - 
   
   Protobufs are already strongly typed.  Just write a java mapper class to 
make the object go from one type of object to antoher.
   
   Using SPI, it will bring the java protobuf class into the classpath.  If it 
is an Any object, you can just proxy it too if you want.
   
   You really should try to have everything strongly typed and avoid converting 
it from type->string->type.  You can just do type->type with this solution.
   
   ```java
   public class WarcRecordParser implements MessageParser<WarcRecord> {
       static final Property STATUS = 
Property.externalInteger("warc:http-status");
   
       public Class<WarcRecord> messageType() { return WarcRecord.class; }
   
       public List<Property> properties() { return List.of(STATUS); }
   
       public List<Metadata> parse(WarcRecord record) {
           Metadata m = new Metadata();
           m.set(TikaCoreProperties.SOURCE_PATH, record.getTargetUri());
           m.set(STATUS, record.getHttpStatus());
           m.set(TikaCoreProperties.TIKA_CONTENT, record.getText());
           return List.of(m);
       }
   }
   ```
   and also to serialize we'd just call pack():
   
   ```java
   ParseMessageResponse r = stub.parseMessage(
           
ParseMessageRequest.newBuilder().setMessage(Any.pack(record)).build());
   ```
   
   The idea is that you don't convert it to a string.  Converting some types 
from data->string->data can cause serialization headaches.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to