#include "Replicable.hpp" #include "JSONSerializer.hpp" #include "BinarySerializer.hpp" namespace sprawl { namespace serialization { ReplicationKey::ReplicationKey(sprawl::serialization::ReplicationKey const& other) : m_size(other.m_size) { memcpy( m_data, other.m_data, sizeof(int32_t) * other.m_size ); } bool ReplicationKey::operator==(ReplicationKey const& other) const { if( m_size != other.m_size ) { return false; } return (memcmp( m_data, other.m_data, sizeof(int32_t) * m_size ) == 0); } bool ReplicationKey::operator<(ReplicationKey const& other) const { uint32_t size = (m_size < other.m_size ? m_size : other.m_size); for(uint32_t i = 0; i < size; ++i) { if( m_data[i] == other.m_data[i] ) continue; return abs(m_data[i]) < abs(other.m_data[i]); } return m_size < other.m_size; } SPRAWL_WARN_UNUSED_RESULT ErrorState<void> ReplicationKey::Serialize(SerializerBase& s) { if(s.IsBinary()) { SPRAWL_RETHROW(s % prepare_data(m_size, "size", true)); } s.StartArray("ReplicationKey", m_size, true); if(s.IsBinary()) { SPRAWL_RETHROW(s.serialize(m_data, m_size * sizeof(int32_t), "data", true)); } else { for(uint32_t i=0; i<m_size; ++i) { SPRAWL_RETHROW(s % prepare_data(m_data[i], "data")); } } s.EndArray(); return ErrorState<void>(); } bool StartsWith(ReplicationKey const& x, ReplicationKey const& y) { uint32_t xsize = x.size(); uint32_t ysize = y.size(); if(xsize < ysize) return false; const int32_t* xArr = &x[0]; const int32_t* yArr = &y[0]; for(uint32_t i = 0; i < ysize; i++) { if(xArr[i] != yArr[i]) return false; } return true; } template class ReplicableSerializer<JSONSerializer>; template class ReplicableDeserializer<JSONDeserializer>; template class ReplicableSerializer<BinarySerializer>; template class ReplicableDeserializer<BinaryDeserializer>; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 16768 | ShadauxCat |
Improvements to error handling in builds with exceptions disabled: - In debug builds or with SPRAWL_ERRORSTATE_STRICT enabled, ErrorState will output a message to stderr and terminate if Get() is called when an error flag is set. (In release buils or with SPRAWL_ERRORSTATE_PERMISSIVE defined, Get() will return junk memory in this case.) - In debug builds or with SPRAWL_ERRORSTATE_STRICT enabled, ErrorState will output a message to stderr and terminate if its destructor is called without checking the errorstate if an error is present (equivalent to an exception terminating the application if no catch() block is present for it). - On linux builds and when running "Analyze" through visual studio, a warning will be issued if any function returning ErrorState has its return value ignored. (This only applies to builds with exceptions not enabled; when exceptions are enabled no warning is issued) - Many functions that could return ErrorState were having their return values silently ignored in internal sprawl code so the user would not find out about errors if exceptions are disabled; now anything in sprawl code that calls a function returning ErrorState will either handle the error, or (in most cases) surface it back up to the user. - As a positive side-effect of the warnings for ignoring ErrorState, several constructors that were capable of throwing exceptions are no longer capable of doing so. #review-16769 |
||
#2 | 14783 | ShadauxCat |
Style corrections (placement of const) #review-14784 |
||
#1 | 11496 | ShadauxCat | Initial checkin: Current states for csbuild and libSprawl |