// Copyright (c) FIRST and other WPILib contributors. // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. package edu.wpi.first.networktables; import java.nio.ByteBuffer; import java.util.function.Consumer; /** NetworkTables generic publisher. */ public interface GenericPublisher extends Publisher, Consumer { /** * Get the corresponding topic. * * @return Topic */ @Override Topic getTopic(); /** * Publish a new value. * * @param value value to publish * @return False if the topic already exists with a different type */ boolean set(NetworkTableValue value); /** * Publish a new value. * * @param value value to publish * @return False if the topic already exists with a different type * @throws IllegalArgumentException if the value is not a known type */ default boolean setValue(Object value) { return setValue(value, 0); } /** * Publish a new value. * * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used * @return False if the topic already exists with a different type * @throws IllegalArgumentException if the value is not a known type */ boolean setValue(Object value, long time); {% for t in types %} /** * Publish a new value. * * @param value value to publish * @return False if the topic already exists with a different type */ default boolean set{{ t.TypeName }}({{ t.java.ValueType }} value) { return set{{ t.TypeName }}(value, 0); } {% if t.TypeName == "Raw" %} /** * Publish a new value. * * @param value value to publish * @return False if the topic already exists with a different type */ default boolean setRaw(ByteBuffer value) { return setRaw(value, 0); } /** * Publish a new value. * * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used * @return False if the topic already exists with a different type */ default boolean setRaw(byte[] value, long time) { return setRaw(value, 0, value.length, time); } /** * Publish a new value. * * @param value value to publish; will send from value.position() to value.limit() * @param time timestamp; 0 indicates current NT time should be used * @return False if the topic already exists with a different type */ default boolean setRaw(ByteBuffer value, long time) { int pos = value.position(); return setRaw(value, pos, value.limit() - pos, time); } /** * Publish a new value. * * @param value value to publish * @param start Start position of data (in buffer) * @param len Length of data (must be less than or equal to value.length - start) * @return False if the topic already exists with a different type */ default boolean setRaw(byte[] value, int start, int len) { return setRaw(value, start, len, 0); } /** * Publish a new value. * * @param value value to publish * @param start Start position of data (in buffer) * @param len Length of data (must be less than or equal to value.length - start) * @param time timestamp; 0 indicates current NT time should be used * @return False if the topic already exists with a different type */ boolean setRaw(byte[] value, int start, int len, long time); /** * Publish a new value. * * @param value value to publish * @param start Start position of data (in buffer) * @param len Length of data (must be less than or equal to value.capacity() - start) * @return False if the topic already exists with a different type */ default boolean setRaw(ByteBuffer value, int start, int len) { return setRaw(value, start, len, 0); } /** * Publish a new value. * * @param value value to publish * @param start Start position of data (in buffer) * @param len Length of data (must be less than or equal to value.capacity() - start) * @param time timestamp; 0 indicates current NT time should be used * @return False if the topic already exists with a different type */ boolean setRaw(ByteBuffer value, int start, int len, long time); {% else %} /** * Publish a new value. * * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used * @return False if the topic already exists with a different type */ boolean set{{ t.TypeName }}({{ t.java.ValueType }} value, long time); {% endif -%} {% if t.java.WrapValueType %} /** * Publish a new value. * * @param value value to publish * @return False if the topic already exists with a different type */ default boolean set{{ t.TypeName }}({{ t.java.WrapValueType }} value) { return set{{ t.TypeName }}(value, 0); } /** * Publish a new value. * * @param value value to publish * @param time timestamp; 0 indicates current NT time should be used * @return False if the topic already exists with a different type */ boolean set{{ t.TypeName }}({{ t.java.WrapValueType }} value, long time); {% endif -%} {% endfor %} /** * Sets the entry's value if it does not exist. * * @param defaultValue the default value to set * @return False if the entry exists with a different type */ boolean setDefault(NetworkTableValue defaultValue); /** * Sets the entry's value if it does not exist. * * @param defaultValue the default value to set * @return False if the entry exists with a different type * @throws IllegalArgumentException if the value is not a known type */ boolean setDefaultValue(Object defaultValue); {% for t in types %} {% if t.TypeName == "Raw" %} /** * Sets the entry's value if it does not exist. * * @param defaultValue the default value to set * @return False if the entry exists with a different type */ default boolean setDefaultRaw(byte[] defaultValue) { return setDefaultRaw(defaultValue, 0, defaultValue.length); } /** * Sets the entry's value if it does not exist. * * @param defaultValue the default value to set; will send from defaultValue.position() to * defaultValue.limit() * @return False if the entry exists with a different type */ default boolean setDefaultRaw(ByteBuffer defaultValue) { int pos = defaultValue.position(); return setDefaultRaw(defaultValue, pos, defaultValue.limit() - pos); } /** * Sets the entry's value if it does not exist. * * @param defaultValue the default value to set * @param start Start position of data (in buffer) * @param len Length of data (must be less than or equal to value.length - start) * @return False if the entry exists with a different type */ boolean setDefaultRaw(byte[] defaultValue, int start, int len); /** * Sets the entry's value if it does not exist. * * @param defaultValue the default value to set * @param start Start position of data (in buffer) * @param len Length of data (must be less than or equal to value.capacity() - start) * @return False if the entry exists with a different type */ boolean setDefaultRaw(ByteBuffer defaultValue, int start, int len); {% else %} /** * Sets the entry's value if it does not exist. * * @param defaultValue the default value to set * @return False if the entry exists with a different type */ boolean setDefault{{ t.TypeName }}({{ t.java.ValueType }} defaultValue); {% endif -%} {% if t.java.WrapValueType %} boolean setDefault{{ t.TypeName }}({{ t.java.WrapValueType }} defaultValue); {% endif -%} {% endfor %} @Override default void accept(NetworkTableValue value) { set(value); } }