From 2fa0bcdcaf9b9ed8953f2b6831a7f7683bfe7c8a Mon Sep 17 00:00:00 2001 From: Terraneo Federico <fede.tft@miosix.org> Date: Sun, 6 May 2018 23:20:42 +0200 Subject: [PATCH] Uniformed return codes of buffer API with exception name of stream API --- tscpp.cpp | 4 ++-- tscpp.h | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tscpp.cpp b/tscpp.cpp index 84496dd..934ed80 100644 --- a/tscpp.cpp +++ b/tscpp.cpp @@ -38,7 +38,7 @@ namespace tscpp { int TypePool::unserializeUnknownImpl(const char *name, const void *buffer, int bufSize) const { auto it=types.find(name); - if(it==types.end()) return TypeNotFound; + if(it==types.end()) return UnknownType; if(it->second.size>bufSize) return BufferTooSmall; @@ -79,7 +79,7 @@ int unserializeImpl(const char *name, void *data, int size, const void *buffer, if(serializedSize>bufSize) return BufferTooSmall; const char *buf=reinterpret_cast<const char*>(buffer); - if(memcmp(buf,name,nameSize+1)) return TypeMismatch; + if(memcmp(buf,name,nameSize+1)) return WrongType; //NOTE: we are writing on top of a constructed type without calling its //destructor. However, since it is trivially copyable, we at least aren't diff --git a/tscpp.h b/tscpp.h index 8c58635..e871c63 100644 --- a/tscpp.h +++ b/tscpp.h @@ -44,8 +44,8 @@ namespace tscpp { enum TscppError { BufferTooSmall = -1, ///< Buffer is too small for the given type - TypeMismatch = -2, ///< While unserializing a different type was found - TypeNotFound = -3 ///< While unserializing the type was not found in the pool + WrongType = -2, ///< While unserializing a different type was found + UnknownType = -3 ///< While unserializing the type was not found in the pool }; /** @@ -140,7 +140,7 @@ int unserializeImpl(const char *name, void *data, int size, const void *buffer, * \param buffer pointer to buffer where the serialized type is * \param bufSize buffer size * \return the size of the unserialized type (which is larger than sizeof(T) due - * to serialization overhead), or TscppError::TypeMismatch if the buffer does + * to serialization overhead), or TscppError::WrongType if the buffer does * not contain the given type or TscppError::BufferTooSmall if the type is * truncated, i.e the buffer is smaller tah the serialized type size */ @@ -159,7 +159,7 @@ int unserialize(T& t, const void *buffer, int bufSize) * \param buffer pointer to buffer where the serialized type is * \param bufSize buffer size * \return the size of the unserialized type (which is larger than sizeof(T) due - * to serialization overhead), or TscppError::TypeNotFound if the pool does + * to serialization overhead), or TscppError::UnknownType if the pool does * not contain the type found in the buffer or TscppError::BufferTooSmall if the * type is truncated, i.e the buffer is smaller tah the serialized type size */ @@ -168,12 +168,12 @@ int unserializeUnknown(const TypePool& tp, const void *buffer, int bufSize); /** * Given a buffer where a type has been serialized, return the C++ mangled * name of the serialized type. - * It is useful when unserialize returns TscppError::TypeMismatch to print an + * It is useful when unserialize returns TscppError::WrongType to print an * error message with the name of the type in the buffer * \code * Foo f; * auto result=unserialize(f,buffer,size); - * if(result==TypeMismatch) + * if(result==WrongType) * { * cerr<<"While unserializing Foo, "<<demangle(peekTypeName(buffer,size))<<" was found\n"; * } -- GitLab