code: public LogEvent decode(LogBuffer buffer, LogContext context) throws IOException {
          final int limit = buffer.limit();
  
          if (limit >= FormatDescriptionLogEvent.LOG_EVENT_HEADER_LEN) {
              LogHeader header = new LogHeader(buffer, context.getFormatDescription());
  
              final int len = header.getEventLen();
              if (limit >= len) {
                  LogEvent event;
  
                  /* Checking binary-log's header */
                  if (handleSet.get(header.getType())) {
                      buffer.limit(len);
                      try {
                          /* Decoding binary-log to event */
                          event = decode(buffer, header, context);
                      } catch (IOException e) {
                          if (logger.isWarnEnabled()) {
                              logger.warn("Decoding " + LogEvent.getTypeName(header.getType()) + " failed from: "
                                          + context.getLogPosition(), e);
                          }
                          throw e;
                      } finally {
                          buffer.limit(limit); /* Restore limit */
                      }
                  } else {
                      /* Ignore unsupported binary-log. */
                      event = new UnknownLogEvent(header);
                  }
  
                  if (event != null) {
                      // set logFileName
                      event.getHeader().setLogFileName(context.getLogPosition().getFileName());
                      event.setSemival(buffer.semival);
                  }
  
                  /* consume this binary-log. */
                  buffer.consume(len);
                  return event;
              }
          }
  
          /* Rewind buffer's position to 0. */
          buffer.rewind();
          return null;
      }
docs: Decoding an event from binary-log buffer.
  
  @return <code>UknownLogEvent</code> if event type is unknown or skipped,
  <code>null</code> if buffer is not including a full event.