RobotCore
1.0
WPILib port to raspberry Pi
Toggle main menu visibility
Loading...
Searching...
No Matches
Struct.java
1
// Copyright (c) FIRST and other WPILib contributors.
2
// Open Source Software; you can modify and/or share it under the terms of
3
// the WPILib BSD license file in the root directory of this project.
4
5
package
org.wpilib.util.struct;
6
7
import
java.lang.reflect.Array;
8
import
java.nio.ByteBuffer;
9
22
public
interface
Struct
<T> {
24
int
BOOL_SIZE
= 1;
25
27
int
INT8_SIZE
= 1;
28
30
int
INT16_SIZE
= 2;
31
33
int
INT32_SIZE
= 4;
34
36
int
INT64_SIZE
= 8;
37
39
int
FLOAT_SIZE
= 4;
40
42
int
DOUBLE_SIZE
= 8;
43
49
Class<T>
getTypeClass
();
50
57
String
getTypeName
();
58
65
default
String
getTypeString
() {
66
return
"struct:"
+
getTypeName
();
67
}
68
74
int
getSize
();
75
81
String
getSchema
();
82
88
default
Struct<?>
[]
getNested
() {
89
return
new
Struct<?>
[] {};
90
}
91
100
T
unpack
(ByteBuffer bb);
101
110
void
pack
(ByteBuffer bb, T value);
111
124
default
void
unpackInto
(T out, ByteBuffer bb) {
125
throw
new
UnsupportedOperationException(
"object does not support unpackInto"
);
126
}
127
139
static <T> T[]
unpackArray
(ByteBuffer bb,
int
size,
Struct<T>
struct) {
140
@SuppressWarnings(
"unchecked"
)
141
T[] arr = (T[]) Array.newInstance(struct.getTypeClass(), size);
142
for
(
int
i = 0; i < arr.length; i++) {
143
arr[i] = struct.unpack(bb);
144
}
145
return
arr;
146
}
147
157
static
double
[]
unpackDoubleArray
(ByteBuffer bb,
int
size) {
158
double
[] arr =
new
double
[size];
159
for
(
int
i = 0; i < size; i++) {
160
arr[i] = bb.getDouble();
161
}
162
return
arr;
163
}
164
175
static <T>
void
packArray
(ByteBuffer bb, T[] arr,
Struct<T>
struct) {
176
for
(T obj : arr) {
177
struct.pack(bb, obj);
178
}
179
}
180
189
static
void
packArray
(ByteBuffer bb,
double
[] arr) {
190
for
(
double
obj : arr) {
191
bb.putDouble(obj);
192
}
193
}
194
201
default
boolean
isImmutable
() {
202
return
false
;
203
}
204
211
default
boolean
isCloneable
() {
212
return
false
;
213
}
214
224
default
T
clone
(T obj)
throws
CloneNotSupportedException {
225
throw
new
CloneNotSupportedException();
226
}
227
}
org.wpilib.util.struct.Struct
Definition
Struct.java:22
org.wpilib.util.struct.Struct.unpackArray
static< T > T[] unpackArray(ByteBuffer bb, int size, Struct< T > struct)
Definition
Struct.java:139
org.wpilib.util.struct.Struct.getTypeClass
Class< T > getTypeClass()
org.wpilib.util.struct.Struct.getNested
default Struct<?>[] getNested()
Definition
Struct.java:88
org.wpilib.util.struct.Struct.getSize
int getSize()
org.wpilib.util.struct.Struct.INT8_SIZE
int INT8_SIZE
Definition
Struct.java:27
org.wpilib.util.struct.Struct.isImmutable
default boolean isImmutable()
Definition
Struct.java:201
org.wpilib.util.struct.Struct.getSchema
String getSchema()
org.wpilib.util.struct.Struct.clone
default T clone(T obj)
Definition
Struct.java:224
org.wpilib.util.struct.Struct.INT32_SIZE
int INT32_SIZE
Definition
Struct.java:33
org.wpilib.util.struct.Struct.INT64_SIZE
int INT64_SIZE
Definition
Struct.java:36
org.wpilib.util.struct.Struct.unpackInto
default void unpackInto(T out, ByteBuffer bb)
Definition
Struct.java:124
org.wpilib.util.struct.Struct.BOOL_SIZE
int BOOL_SIZE
Definition
Struct.java:24
org.wpilib.util.struct.Struct.pack
void pack(ByteBuffer bb, T value)
org.wpilib.util.struct.Struct.DOUBLE_SIZE
int DOUBLE_SIZE
Definition
Struct.java:42
org.wpilib.util.struct.Struct.packArray
static< T > void packArray(ByteBuffer bb, T[] arr, Struct< T > struct)
Definition
Struct.java:175
org.wpilib.util.struct.Struct.FLOAT_SIZE
int FLOAT_SIZE
Definition
Struct.java:39
org.wpilib.util.struct.Struct.getTypeString
default String getTypeString()
Definition
Struct.java:65
org.wpilib.util.struct.Struct.unpackDoubleArray
static double[] unpackDoubleArray(ByteBuffer bb, int size)
Definition
Struct.java:157
org.wpilib.util.struct.Struct.unpack
T unpack(ByteBuffer bb)
org.wpilib.util.struct.Struct.packArray
static void packArray(ByteBuffer bb, double[] arr)
Definition
Struct.java:189
org.wpilib.util.struct.Struct.isCloneable
default boolean isCloneable()
Definition
Struct.java:211
org.wpilib.util.struct.Struct.INT16_SIZE
int INT16_SIZE
Definition
Struct.java:30
org.wpilib.util.struct.Struct.getTypeName
String getTypeName()
org
wpilib
util
struct
Struct.java
Generated by
1.18.0