src
urg_sim
encode.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2024 The urg_stamped Authors
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
16
17
#include <cstdint>
18
#include <string>
19
#include <vector>
20
21
#include <
urg_sim/encode.h
>
22
23
namespace
urg_sim
24
{
25
namespace
encode
26
{
27
28
std::string
checksum
(
const
std::string& s)
29
{
30
char
sum = 0;
31
for
(
const
char
c :
s
)
32
{
33
sum += c;
34
}
35
return
std::string(1, (sum & 0x3F) + 0x30);
36
}
37
38
std::string
withChecksum
(
const
std::string& s)
39
{
40
return
s
+
checksum
(
s
);
41
}
42
43
std::string
encode
(
const
std::vector<uint32_t>& v,
const
EncodeType
ced)
44
{
45
std::string out;
46
47
for
(
const
uint32_t w : v)
48
{
49
for
(
int
i = 0; i < static_cast<int>(ced); ++i)
50
{
51
out += ((w >> ((
static_cast<
int
>
(ced) - i - 1) * 6)) & 0x3F) + 0x30;
52
}
53
}
54
return
out;
55
}
56
57
}
// namespace encode
58
}
// namespace urg_sim
59
urg_sim::encode::encode
std::string encode(const std::vector< uint32_t > &v, const EncodeType ced)
Definition:
encode.cpp:43
urg_sim
Definition:
encode.h:24
encode.h
s
XmlRpcServer s
urg_sim::encode::EncodeType
EncodeType
Definition:
encode.h:32
urg_sim::encode::checksum
std::string checksum(const std::string &a)
Definition:
encode.cpp:28
urg_sim::encode::withChecksum
std::string withChecksum(const std::string &s)
Definition:
encode.cpp:38
urg_stamped
Author(s): Atsushi Watanabe
autogenerated on Wed Dec 18 2024 03:10:57