Files
utun2/tools/chatgui/zxing-cpp/core/src/DecoderResult.h
T
evgeny 38c9f229bc stcp: ed25519 pubkey exchange in handshake, fix instance destroy segfault, fix chat_tcp_test
- u_async.c: process immediate_queue BEFORE epoll_wait in uasync_poll
- stcp_link.c: defensive NULL etcp_conn/etcp_link in stcp_link_close
- utun_instance.c: move stcp_server_list_destroy_all to Phase J (before ETCP),
  add deferred drain in both Phase J and L
- stcp.h/c: STCP_HS_ENC_CLIENT 6→38, STCP_HS_ENC_SERVER 7→39,
  exchange ed25519_pubkey in both handshake directions
- etcp_connections.c: copy peer_ed25519 from STCP to ETCP_CONN in
  etcp_link_enter_ready_tcp; guard link->etcp in tcp_link_close_cb
- chat_sync.c: fix lk->conn NULL dereference for TCP links
- test_stcp.c: update stcp_server_create/stcp_client_connect callsites
- tools/chat_tcp_test: change transport udp→tcp
2026-08-07 00:48:27 +03:00

93 lines
2.9 KiB
C++

/*
* Copyright 2016 Nu-book Inc.
* Copyright 2016 ZXing authors
*/
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "Content.h"
#include "Error.h"
#include "JSON.h"
#include "StructuredAppend.h"
#include <memory>
#include <string>
#include <utility>
namespace ZXing {
struct CustomData
{
virtual ~CustomData() = default;
};
class DecoderResult
{
Content _content;
std::string _ecLevel;
int _lineCount = 0;
int _versionNumber = 0;
StructuredAppendInfo _structuredAppend;
bool _isMirrored = false;
bool _readerInit = false;
Error _error;
std::string _json;
std::shared_ptr<CustomData> _customData;
public:
DecoderResult() = default;
DecoderResult(Error error) : _error(std::move(error)) {}
DecoderResult(Content&& bytes) : _content(std::move(bytes)) {}
DecoderResult(DecoderResult&&) noexcept = default;
DecoderResult& operator=(DecoderResult&&) noexcept = default;
DecoderResult(const DecoderResult&) = delete;
DecoderResult& operator=(const DecoderResult&) = delete;
bool isValid(bool includeErrors = false) const
{
return (!_content.bytes.empty() && !_error) || (includeErrors && !!_error);
}
const Content& content() const & { return _content; }
Content&& content() && { return std::move(_content); }
// to keep the unit tests happy for now:
std::wstring text() const { return _content.utfW(); }
std::string symbologyIdentifier() const { return _content.symbology.toString(false); }
// Simple macro to set up getter/setter methods that save lots of boilerplate.
// It sets up a standard 'const & () const', 2 setters for setting lvalues via
// copy and 2 for setting rvalues via move. They are provided each to work
// either on lvalues (normal 'void (...)') or on rvalues (returning '*this' as
// rvalue). The latter can be used to optionally initialize a temporary in a
// return statement, e.g.
// return DecoderResult(bytes, text).setEcLevel(level);
#define ZX_PROPERTY(TYPE, GETTER, SETTER) \
const TYPE& GETTER() const & { return _##GETTER; } \
TYPE&& GETTER() && { return std::move(_##GETTER); } \
void SETTER(const TYPE& v) & { _##GETTER = v; } \
void SETTER(TYPE&& v) & { _##GETTER = std::move(v); } \
DecoderResult&& SETTER(const TYPE& v) && { _##GETTER = v; return std::move(*this); } \
DecoderResult&& SETTER(TYPE&& v) && { _##GETTER = std::move(v); return std::move(*this); }
ZX_PROPERTY(std::string, ecLevel, setEcLevel)
ZX_PROPERTY(int, lineCount, setLineCount)
ZX_PROPERTY(int, versionNumber, setVersionNumber)
ZX_PROPERTY(StructuredAppendInfo, structuredAppend, setStructuredAppend)
ZX_PROPERTY(Error, error, setError)
ZX_PROPERTY(bool, isMirrored, setIsMirrored)
ZX_PROPERTY(bool, readerInit, setReaderInit)
ZX_PROPERTY(std::string, json, setJson)
ZX_PROPERTY(std::shared_ptr<CustomData>, customData, setCustomData)
#undef ZX_PROPERTY
template<typename T>
DecoderResult&& addExtra(std::string_view key, T val, T ignore = {}) { _json += JsonProp(key, val, ignore); return std::move(*this); }
};
} // ZXing