RobotCore
1.0
WPILib port to raspberry Pi
Toggle main menu visibility
Loading...
Searching...
No Matches
VectorProto.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.math.linalg.proto;
6
7
import
org.ejml.simple.SimpleMatrix;
8
import
org.wpilib.math.linalg.Vector;
9
import
org.wpilib.math.linalg.proto.detail.ProtobufVector;
10
import
org.wpilib.math.util.Nat;
11
import
org.wpilib.math.util.Num;
12
import
org.wpilib.util.protobuf.Protobuf;
13
import
us.hebi.quickbuf.Descriptors.Descriptor;
14
15
public
final
class
VectorProto
<R
extends
Num
> implements
Protobuf
<Vector<R>, ProtobufVector> {
16
private
final
Nat<R>
m_rows;
17
23
public
VectorProto
(
Nat<R>
rows) {
24
m_rows = rows;
25
}
26
27
@Override
28
public
Class<Vector<R>>
getTypeClass
() {
29
@SuppressWarnings(
"unchecked"
)
30
var clazz = (Class<Vector<R>>) (Class<?>)
Vector
.class;
31
return
clazz;
32
}
33
34
@Override
35
public
Descriptor
getDescriptor
() {
36
return
ProtobufVector
.
getDescriptor
();
37
}
38
39
@Override
40
public
ProtobufVector
createMessage
() {
41
return
ProtobufVector
.
newInstance
();
42
}
43
44
@Override
45
public
Vector<R>
unpack(
ProtobufVector
msg) {
46
if
(msg.
getRows
().length() != m_rows.getNum()) {
47
throw
new
IllegalArgumentException(
48
"Tried to unpack msg "
49
+ msg
50
+
" with "
51
+ msg.
getRows
().length()
52
+
" rows into Vector with "
53
+ m_rows.getNum()
54
+
" rows"
);
55
}
56
var storage =
new
SimpleMatrix(
Protobuf
.
unpackArray
(msg.
getRows
()));
57
return
new
Vector<R>
(storage);
58
}
59
60
@Override
61
public
void
pack(ProtobufVector msg, Vector<R> value) {
62
Protobuf.packArray(msg.getMutableRows(), value.getData());
63
}
64
}
org.wpilib.math.linalg.Vector
Definition
Vector.java:28
org.wpilib.math.linalg.Vector.Vector
Vector(Nat< R > rows)
Definition
Vector.java:34
org.wpilib.math.linalg.proto.VectorProto.VectorProto
VectorProto(Nat< R > rows)
Definition
VectorProto.java:23
org.wpilib.math.linalg.proto.VectorProto.createMessage
ProtobufVector createMessage()
Definition
VectorProto.java:40
org.wpilib.math.linalg.proto.VectorProto.getDescriptor
Descriptor getDescriptor()
Definition
VectorProto.java:35
org.wpilib.math.linalg.proto.VectorProto.getTypeClass
Class< Vector< R > > getTypeClass()
Definition
VectorProto.java:28
org.wpilib.math.linalg.proto.detail.ProtobufVector
Definition
ProtobufVector.java:23
org.wpilib.math.linalg.proto.detail.ProtobufVector.getRows
RepeatedDouble getRows()
Definition
ProtobufVector.java:69
org.wpilib.math.linalg.proto.detail.ProtobufVector.getDescriptor
static Descriptors.Descriptor getDescriptor()
Definition
ProtobufVector.java:290
org.wpilib.math.linalg.proto.detail.ProtobufVector.newInstance
static ProtobufVector newInstance()
Definition
ProtobufVector.java:37
org.wpilib.math.util.Num
Definition
Num.java:8
org.wpilib.math.util.Nat
Definition
Nat.java:41
org.wpilib.util.protobuf.Protobuf
Definition
Protobuf.java:32
org.wpilib.util.protobuf.Protobuf.unpackArray
static< T, MessageType extends ProtoMessage< MessageType > > T[] unpackArray(RepeatedMessage< MessageType > msg, Protobuf< T, MessageType > proto)
Definition
Protobuf.java:161
org
wpilib
math
linalg
proto
VectorProto.java
Generated by
1.18.0