コード例 #1
0
  /**
   * Returns whether the specified Structure is compatible with NTUnion.
   *
   * <p>Checks if the specified Structure is compatible with this version of NTUnion through the
   * introspection interface.
   *
   * @param structure the Structure to test
   * @return (false,true) if (is not, is) a compatible NTUnion
   */
  public static boolean isCompatible(Structure structure) {
    if (structure == null) return false;

    Union valueField = structure.getField(Union.class, "value");
    if (valueField == null) return false;

    NTField ntField = NTField.get();

    Field field = structure.getField("descriptor");
    if (field != null) {
      Scalar descriptorField = structure.getField(Scalar.class, "descriptor");
      if (descriptorField == null || descriptorField.getScalarType() != ScalarType.pvString)
        return false;
    }

    field = structure.getField("alarm");
    if (field != null && !ntField.isAlarm(field)) return false;

    field = structure.getField("timeStamp");
    if (field != null && !ntField.isTimeStamp(field)) return false;

    return true;
  }