new cspot/bell

This commit is contained in:
philippe44
2023-05-06 23:50:26 +02:00
parent e0e7e718ba
commit 8bad480112
163 changed files with 6611 additions and 6739 deletions

View File

@@ -1,47 +1,51 @@
#pragma once
#include <vector>
#include "pb_encode.h"
#include "pb_decode.h"
#include <string>
#include <stdint.h> // for uint8_t
#include <stdio.h> // for printf
#include <string> // for string
#include <vector> // for vector
std::vector<uint8_t> pbEncode(const pb_msgdesc_t *fields, const void *src_struct);
#include "pb.h" // for pb_msgdesc_t, pb_bytes_array_t, PB_GET_ERROR
#include "pb_decode.h" // for pb_istream_from_buffer, pb_decode, pb_istream_s
std::vector<uint8_t> pbEncode(const pb_msgdesc_t* fields,
const void* src_struct);
pb_bytes_array_t* vectorToPbArray(const std::vector<uint8_t>& vectorToPack);
void packString(char* &dst, std::string stringToPack);
void packString(char*& dst, std::string stringToPack);
std::vector<uint8_t> pbArrayToVector(pb_bytes_array_t* pbArray);
template <typename T>
T pbDecode(const pb_msgdesc_t *fields, std::vector<uint8_t> &data)
{
T pbDecode(const pb_msgdesc_t* fields, std::vector<uint8_t>& data) {
T result = {};
// Create stream
pb_istream_t stream = pb_istream_from_buffer(&data[0], data.size());
// Decode the message
if (pb_decode(&stream, fields, &result) == false) {
printf("Decode failed: %s\n", PB_GET_ERROR(&stream));
}
return result;
T result = {};
// Create stream
pb_istream_t stream = pb_istream_from_buffer(&data[0], data.size());
// Decode the message
if (pb_decode(&stream, fields, &result) == false) {
printf("Decode failed: %s\n", PB_GET_ERROR(&stream));
}
return result;
}
template <typename T>
void pbDecode(T &result, const pb_msgdesc_t *fields, std::vector<uint8_t> &data)
{
// Create stream
pb_istream_t stream = pb_istream_from_buffer(&data[0], data.size());
// Decode the message
if (pb_decode(&stream, fields, &result) == false) {
printf("Decode failed: %s\n", PB_GET_ERROR(&stream));
}
void pbDecode(T& result, const pb_msgdesc_t* fields,
std::vector<uint8_t>& data) {
// Create stream
pb_istream_t stream = pb_istream_from_buffer(&data[0], data.size());
// Decode the message
if (pb_decode(&stream, fields, &result) == false) {
printf("Decode failed: %s\n", PB_GET_ERROR(&stream));
}
}
void pbPutString(const std::string &stringToPack, char* dst);
void pbPutCharArray(const char * stringToPack, char* dst);
void pbPutBytes(const std::vector<uint8_t> &data, pb_bytes_array_t &dst);
void pbPutString(const std::string& stringToPack, char* dst);
void pbPutCharArray(const char* stringToPack, char* dst);
void pbPutBytes(const std::vector<uint8_t>& data, pb_bytes_array_t& dst);
const char* pb_encode_to_string(const pb_msgdesc_t *fields, const void *data);
const char* pb_encode_to_string(const pb_msgdesc_t* fields, const void* data);