Files
praxisandClaude Fable 5.2 c2194c59d4 Protocol core: packet translation between source and native
127 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:47 +02:00

49 lines
2.0 KiB
C++

#pragma once
#include "gateway/keyring_slots.hpp"
#include <array>
#include <cstdint>
#include <stdexcept>
// Serialization-local context, set and consumed inside the SAME codec DLL.
// Backend inventory routing includes keyring_slots.hpp only. No state crosses
// the C ABI, and neither SDK object layout nor its108-entry array is changed.
namespace gateway::keyring_wire {
template<class Guid> struct View {
std::array<Guid,keyring_slots::Count> guids{};
uint32_t changed=0;
};
#if defined(__GNUC__) && !defined(_WIN32)
#define GW_KEYRING_LOCAL __attribute__((visibility("hidden")))
#else
#define GW_KEYRING_LOCAL
#endif
template<class Guid> GW_KEYRING_LOCAL inline thread_local View<Guid> const* current=nullptr;
template<class Guid> class GW_KEYRING_LOCAL Scope {
View<Guid> const* previous;
public:
explicit Scope(View<Guid> const& view) noexcept:previous(current<Guid>){current<Guid> = &view;}
~Scope(){current<Guid> = previous;}
Scope(Scope const&)=delete;
Scope& operator=(Scope const&)=delete;
};
template<class Guid,class Buffer> GW_KEYRING_LOCAL void create_tail(Buffer& data,unsigned slot){
if(slot<keyring_slots::SdkInventoryCount || slot>=keyring_slots::NativeInventoryCount)
throw std::out_of_range("native keyring create tail extent");
auto view=current<Guid>;
data << (view && keyring_slots::native(slot)?view->guids[slot-keyring_slots::NativeFirst]:Guid{});
}
template<class Guid> GW_KEYRING_LOCAL void overlay_mask(std::array<uint32_t,14>& blocks){
if(auto view=current<Guid>)for(unsigned i=0;i<keyring_slots::Count;++i)
if(view->changed&(uint32_t(1)<<i)){
const unsigned bit=keyring_slots::NativeMaskFirst+i;
blocks[bit/32]|=uint32_t(1)<<(bit%32);
}
// The existing native mask writer recomputes group168 after this overlay.
}
template<class Guid,class Buffer> GW_KEYRING_LOCAL void update_tail(Buffer& data){
if(auto view=current<Guid>)for(unsigned i=0;i<keyring_slots::Count;++i)
if(view->changed&(uint32_t(1)<<i))data << view->guids[i];
}
#undef GW_KEYRING_LOCAL
}