Changeset 163:3cfc25edb314 in rrlib_serialization


Ignore:
Timestamp:
08.06.2017 02:53:17 (22 months ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
17.03
Phase:
public
Message:

Adjusts auto-register publishing mechanism to remain compatible with older Finroc versions

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • PublishedRegisters.h

    r160 r163  
    166166   *                      (2) an equivalent method for deserializing element as TRemoteEntry (the handle needn't be deserialized) 
    167167   *                      void DeserializeRegisterEntry(tInputStream& stream); 
     168   * \tparam Tempty_element Whether to create an empty element that is returned when -1 is read 
    168169   * \throw Throws std::invalid_argument on already occupied uid 
    169170   */ 
    170   template <typename TRemoteEntry> 
     171  template <typename TRemoteEntry, bool Tempty_element = false> 
    171172  static void Register(const typename TRemoteEntry::tLocalRegister& r, uint uid); 
    172173 
  • PublishedRegisters.hpp

    r158 r163  
    7575    register_array[register_uid].reset(RegisteredRegisters()[register_uid]->CreateRemoteRegister()); 
    7676  } 
    77   const typename TRemoteType::tHandle cESCAPE = -1; 
     77  const typename TRemoteType::tHandle cESCAPE = -2; 
    7878  auto handle = stream.ReadNumber<typename TRemoteType::tHandle>(); 
    7979  if (handle == cESCAPE) 
     
    8585} 
    8686 
    87 template <typename TRemoteEntry> 
     87template <typename TElement> 
     88static const TElement& EmptyElement() 
     89{ 
     90  static const TElement cEMPTY_ELEMENT; 
     91  return cEMPTY_ELEMENT; 
     92} 
     93 
     94template <typename TRemoteEntry, bool Tempty_element> 
    8895void PublishedRegisters::Register(const typename TRemoteEntry::tLocalRegister& r, uint uid) 
    8996{ 
     
    137144    virtual const void* GetRemoteElement(size_t index) override 
    138145    { 
     146      tHandle handle = static_cast<tHandle>(index); 
     147      if (Tempty_element && handle == static_cast<tHandle>(-1)) 
     148      { 
     149        return &EmptyElement<typename std::conditional<Tempty_element, TRemoteEntry, std::string>::type>(); 
     150      } 
    139151      if (index >= this->Size()) 
    140152      { 
  • tOutputStream.cpp

    r162 r163  
    239239{ 
    240240  bool escape_signal_written = false; 
    241   uint escape_signal = 0xFFFFFFFF; 
    242241 
    243242  // Update on_change registers 
     
    253252        if (!escape_signal_written) 
    254253        { 
    255           Write(&escape_signal, handle_size); 
     254          if (handle_size == 1) 
     255          { 
     256            WriteByte(-2); 
     257          } 
     258          else if (handle_size == 2) 
     259          { 
     260            WriteShort(-2); 
     261          } 
     262          else if (handle_size == 4) 
     263          { 
     264            WriteInt(-2); 
     265          } 
    256266          escape_signal_written = true; 
    257267        } 
Note: See TracChangeset for help on using the changeset viewer.