RASCSI/cpp/shared/protobuf_util.h
Uwe Seimet 41bdcd4aed
Issues 1179 and 1182 (#1232)
* Update logging

* Remove duplicate code

* Update unit tests

* Clean up includes

* Merge ProtobufSerializer into protobuf_util namespace

* Precompile regex

* Add const

* Add Split() convenience method, update log level/ID parsing

* Move log.h to legacy folder

* Elimininate gotos

* Fixes for gcc 13

* Update compiler flags

* Update default folder handling

* Use references instead of pointers

* Move code for better encapsulation

* Move code

* Remove unused method argument

* Move device logger

* Remove redundant to_string

* Rename for consistency

* Update handling of protobuf pointers

* Simplify protobuf usage

* Memory handling update

* Add hasher
2023-10-15 08:38:15 +02:00

50 lines
1.3 KiB
C++

//---------------------------------------------------------------------------
//
// SCSI Target Emulator PiSCSI
// for Raspberry Pi
//
// Copyright (C) 2021-2023 Uwe Seimet
//
// Helper methods for setting up/evaluating protobuf messages
//
//---------------------------------------------------------------------------
#pragma once
#include <string>
#include <span>
#include <vector>
#include "generated/piscsi_interface.pb.h"
using namespace std;
using namespace piscsi_interface;
namespace protobuf_util
{
static const char KEY_VALUE_SEPARATOR = '=';
string GetParam(const auto& item, const string& key)
{
const auto& it = item.params().find(key);
return it != item.params().end() ? it->second : "";
}
void SetParam(auto& item, const string& key, string_view value)
{
if (!key.empty() && !value.empty()) {
auto& map = *item.mutable_params();
map[key] = value;
}
}
void ParseParameters(PbDeviceDefinition&, const string&);
void SetPatternParams(PbCommand&, const string&);
void SetProductData(PbDeviceDefinition&, const string&);
string SetIdAndLun(PbDeviceDefinition&, const string&);
string ListDevices(const vector<PbDevice>&);
void SerializeMessage(int, const google::protobuf::Message&);
void DeserializeMessage(int, google::protobuf::Message&);
size_t ReadBytes(int, span<byte>);
}