mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Add Java support for raw values.
Either ByteBuffer or byte[] can be used for putRaw(). getRaw() returns byte[].
This commit is contained in:
@@ -3,6 +3,7 @@ package edu.wpi.first.wpilibj.networktables;
|
||||
import edu.wpi.first.wpilibj.tables.*;
|
||||
import edu.wpi.first.wpilibj.networktables2.type.*;
|
||||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -765,6 +766,69 @@ public class NetworkTable implements ITable, IRemote {
|
||||
return NetworkTablesJNI.getStringArray(path + PATH_SEPARATOR + key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps the specified key to the specified value in this table. The key can
|
||||
* not be null. The value can be retrieved by calling the get method with a
|
||||
* key that is equal to the original key.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @param value
|
||||
* the value
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
public boolean putRaw(String key, byte[] value) {
|
||||
return NetworkTablesJNI.putRaw(path + PATH_SEPARATOR + key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps the specified key to the specified value in this table. The key can
|
||||
* not be null. The value can be retrieved by calling the get method with a
|
||||
* key that is equal to the original key.
|
||||
*
|
||||
* @param key
|
||||
* the key
|
||||
* @param value
|
||||
* the value
|
||||
* @param len
|
||||
* the length of the value
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
public boolean putRaw(String key, ByteBuffer value, int len) {
|
||||
if (!value.isDirect())
|
||||
throw new IllegalArgumentException("must be a direct buffer");
|
||||
if (value.capacity() < len)
|
||||
throw new IllegalArgumentException("buffer is too small, must be at least " + len);
|
||||
return NetworkTablesJNI.putRaw(path + PATH_SEPARATOR + key, value, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key that the name maps to.
|
||||
*
|
||||
* @param key
|
||||
* the key name
|
||||
* @return the key
|
||||
* @throws TableKeyNotDefinedException
|
||||
* if the specified key is null
|
||||
*/
|
||||
public byte[] getRaw(String key) throws TableKeyNotDefinedException {
|
||||
return NetworkTablesJNI.getRaw(path + PATH_SEPARATOR + key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key that the name maps to. If the key is null, it will return
|
||||
* the default value
|
||||
*
|
||||
* @param key
|
||||
* the key name
|
||||
* @param defaultValue
|
||||
* the default value if the key is null
|
||||
* @return the key
|
||||
*/
|
||||
public byte[] getRaw(String key, byte[] defaultValue) {
|
||||
return NetworkTablesJNI.getRaw(path + PATH_SEPARATOR + key, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps the specified key to the specified value in this table. The key can
|
||||
* not be null. The value can be retrieved by calling the get method with a
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class NetworkTablesJNI {
|
||||
static boolean libraryLoaded = false;
|
||||
@@ -70,6 +71,7 @@ public class NetworkTablesJNI {
|
||||
public static native boolean putDouble(String key, double value);
|
||||
public static native boolean putString(String key, String value);
|
||||
public static native boolean putRaw(String key, byte[] value);
|
||||
public static native boolean putRaw(String key, ByteBuffer value, int len);
|
||||
public static native boolean putBooleanArray(String key, boolean[] value);
|
||||
public static native boolean putDoubleArray(String key, double[] value);
|
||||
public static native boolean putStringArray(String key, String[] value);
|
||||
@@ -78,6 +80,7 @@ public class NetworkTablesJNI {
|
||||
public static native void forcePutDouble(String key, double value);
|
||||
public static native void forcePutString(String key, String value);
|
||||
public static native void forcePutRaw(String key, byte[] value);
|
||||
public static native void forcePutRaw(String key, ByteBuffer value, int len);
|
||||
public static native void forcePutBooleanArray(String key, boolean[] value);
|
||||
public static native void forcePutDoubleArray(String key, double[] value);
|
||||
public static native void forcePutStringArray(String key, String[] value);
|
||||
@@ -123,9 +126,11 @@ public class NetworkTablesJNI {
|
||||
public static native void removeConnectionListener(int connListenerUid);
|
||||
|
||||
// public static native void createRpc(String key, byte[] def, IRpc rpc);
|
||||
// public static native void createRpc(String key, ByteBuffer def, int def_len, IRpc rpc);
|
||||
public static native byte[] getRpc(String key) throws TableKeyNotDefinedException;
|
||||
public static native byte[] getRpc(String key, byte[] defaultValue);
|
||||
public static native int callRpc(String key, byte[] params);
|
||||
public static native int callRpc(String key, ByteBuffer params, int params_len);
|
||||
// public static native byte[] getRpcResultBlocking(int callUid);
|
||||
// public static native byte[] getRpcResultNonblocking(int callUid) throws RpcNoResponseException;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package edu.wpi.first.wpilibj.tables;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -297,6 +298,36 @@ public interface ITable {
|
||||
*/
|
||||
public String[] getStringArray(String key, String[] defaultValue);
|
||||
|
||||
/**
|
||||
* Put a raw value (byte array) in the table
|
||||
* @param key the key to be assigned to
|
||||
* @param value the value that will be assigned
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
public boolean putRaw(String key, byte[] value);
|
||||
/**
|
||||
* Put a raw value (bytes from a byte buffer) in the table
|
||||
* @param key the key to be assigned to
|
||||
* @param value the value that will be assigned
|
||||
* @param len the length of the value
|
||||
* @return False if the table key already exists with a different type
|
||||
*/
|
||||
public boolean putRaw(String key, ByteBuffer value, int len);
|
||||
/**
|
||||
* @param key the key to look up
|
||||
* @return the value associated with the given key
|
||||
* @throws TableKeyNotDefinedException if there is no value associated with
|
||||
* the given key
|
||||
*/
|
||||
public byte[] getRaw(String key) throws TableKeyNotDefinedException;
|
||||
/**
|
||||
* @param key the key to look up
|
||||
* @param defaultValue the value to be returned if no value is found
|
||||
* @return the value associated with the given key or the given default value
|
||||
* if there is no value associated with the key
|
||||
*/
|
||||
public byte[] getRaw(String key, byte[] defaultValue);
|
||||
|
||||
/** Notifier flag values. */
|
||||
public static final int NOTIFY_IMMEDIATE = 0x01;
|
||||
public static final int NOTIFY_LOCAL = 0x02;
|
||||
|
||||
Reference in New Issue
Block a user