YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Vocab64.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025-2025 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include <yarp/os/Vocab64.h>
7
8using namespace yarp::os;
9
10NetInt64 Vocab64::encode64(const std::string& str)
11{
12 char a = '\0';
13 char b = '\0';
14 char c = '\0';
15 char d = '\0';
16 char e = '\0';
17 char f = '\0';
18 char g = '\0';
19 char h = '\0';
20 if (str.length() >= 1) {
21 a = str[0];
22 if (str.length() >= 2) {
23 b = str[1];
24 if (str.length() >= 3) {
25 c = str[2];
26 if (str.length() >= 4) {
27 d = str[3];
28 if (str.length() >= 5) {
29 e = str[4];
30 if (str.length() >= 6) {
31 f = str[5];
32 if (str.length() >= 7) {
33 g = str[6];
34 if (str.length() >= 8) {
35 h = str[7];
36 }
37 }
38 }
39 }
40 }
41 }
42 }
43 }
44 return createVocab64(a, b, c, d, e, f, g, h);
45}
46
47
48std::string Vocab64::decode64(NetInt64 code)
49{
50 std::string str;
51 for (int i = 0; i < 8; i++) {
52 int ch = code % 256;
53 if (ch > 0) {
54 str += ((char)ch);
55 }
56 code /= 256;
57 }
58 return str;
59}
A mini-server for performing network communication in the background.
NetInt64 encode64(const std::string &str)
Convert a string into a vocabulary identifier.
Definition Vocab64.cpp:10
std::string decode64(NetInt64 code)
Convert a vocabulary identifier into a string.
Definition Vocab64.cpp:48
An interface to the operating system, including Port based communication.
constexpr yarp::conf::vocab64_t createVocab64(char a, char b=0, char c=0, char d=0, char e=0, char f=0, char g=0, char h=0)
Create a vocab from chars.
Definition Vocab64.h:26
std::int64_t NetInt64
Definition of the NetInt64 type.
Definition NetInt64.h:29