package org.apache.logging.log4j.core.appender;

import java.nio.charset.Charset;

public class TlsSyslogFrame {
   public static final char SPACE = ' ';
   private String message;
   private int messageLengthInBytes;

   public TlsSyslogFrame(String message) {
      this.setMessage(message);
   }

   public String getMessage() {
      return this.message;
   }

   public void setMessage(String message) {
      this.message = message;
      this.setLengthInBytes();
   }

   private void setLengthInBytes() {
      this.messageLengthInBytes = this.message.length();
   }

   public byte[] getBytes() {
      String frame = this.toString();
      return frame.getBytes(Charset.defaultCharset());
   }

   public String toString() {
      String length = Integer.toString(this.messageLengthInBytes);
      return length + ' ' + this.message;
   }

   public boolean equals(Object frame) {
      return super.equals(frame);
   }

   public boolean equals(TlsSyslogFrame frame) {
      return this.isLengthEquals(frame) && this.isMessageEquals(frame);
   }

   private boolean isLengthEquals(TlsSyslogFrame frame) {
      return this.messageLengthInBytes == frame.messageLengthInBytes;
   }

   private boolean isMessageEquals(TlsSyslogFrame frame) {
      return this.message.equals(frame.message);
   }
}
