mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-09 04:57:06 +03:00
big merge
This commit is contained in:
37
components/spotify/cspot/include/ProtoHelper.h
Normal file
37
components/spotify/cspot/include/ProtoHelper.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef PROTOBUF_H
|
||||
#define PROTOBUF_H
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include "protobuf.h"
|
||||
#include <PbReader.h>
|
||||
#include <PbCommon.h>
|
||||
|
||||
std::optional<AnyRef> findFieldWithProtobufTag(AnyRef ref, uint32_t tag);
|
||||
void decodeField(std::shared_ptr<PbReader> reader, AnyRef any);
|
||||
void decodeProtobuf(std::shared_ptr<PbReader> reader, AnyRef any);
|
||||
void encodeProtobuf(std::shared_ptr<PbWriter> writer, AnyRef any, uint32_t protobufTag = 0);
|
||||
|
||||
template <typename T>
|
||||
std::vector<uint8_t> encodePb(T & data)
|
||||
{
|
||||
auto ref = AnyRef::of(&data);
|
||||
std::vector<uint8_t> rawData;;
|
||||
auto writer = std::make_shared<PbWriter>(rawData);
|
||||
encodeProtobuf(writer, ref);
|
||||
|
||||
return rawData;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
T decodePb(std::vector<uint8_t> & bytes)
|
||||
{
|
||||
T data = {};
|
||||
auto ref = AnyRef::of(&data);
|
||||
auto writer = std::make_shared<PbReader>(bytes);
|
||||
decodeProtobuf(writer, ref);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user