Class PBEventRecovery

java.lang.Object
edu.stanford.slac.archiverappliance.PB.data.PBEventRecovery

public class PBEventRecovery extends Object
Centralises protobuf parse-and-recover logic for all 14 PB event type classes.

The PB on-disk format uses newline (LF, 0x0a) as the record separator. LineByteStream.readLine() splits on bare 0x0a bytes; write-time escaping via LineEscaper.escapeNewLines() is the guarantee that no 0x0a appears unescaped within a record body under normal conditions. If a record nonetheless contains a bare 0x0a — due to hardware corruption, data from an external source, or any other cause — readLine() truncates the record at that byte, leaving an orphaned varint field tag in the ByteArray. A plain mergeFrom() then fails with InvalidProtocolBufferException.

Recovery: if the initial parse fails and the last unescaped byte is an orphaned varint field tag (wire type 0, non-zero), append 0x0a (the byte consumed by readLine()) and retry with buildPartial(). This reconstructs the truncated field value and avoids a silent event drop.

  • Method Details

    • parseWithRecovery

      public static <M> M parseWithRecovery(Supplier<com.google.protobuf.AbstractMessageLite.Builder> builderFactory, ByteArray bar)
      Unescapes bar and parses it with the supplied builder factory. If the first parse fails and the last byte looks like an orphaned varint field tag (wire type 0, non-zero), appends 0x0a (the LF byte that readLine() consumed as a record separator) and retries once with buildPartial(). Throws PBParseException if neither attempt succeeds.

      Usage in each PB event class:

         dbevent = PBEventRecovery.parseWithRecovery(EPICSEvent.ScalarEnum::newBuilder, bar);