All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.unistuttgart.isw.sfsc.commonjava.protocol.pubsub.DataProtocol Maven / Gradle / Ivy

package de.unistuttgart.isw.sfsc.commonjava.protocol.pubsub;

import java.util.List;

public enum DataProtocol {
  TOPIC_FRAME(0),
  DATA_FRAME(1);

  private static final int LENGTH = values().length; //cache
  private final int position;

  DataProtocol(int position) {
    this.position = position;
    assert this.position == ordinal();
  }

  public static int frameCount() {
    return LENGTH;
  }

  public static List newMessage(byte[] topic, byte[] data) {
    return List.of(topic, data);
  }

  public static boolean isValid(List message){
    return message.size() == LENGTH;
  }

  public static byte[] getTopic(List message) {
    return message.get(TOPIC_FRAME.position);
  }

  public static byte[] getData(List message) {
    return message.get(DATA_FRAME.position);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy