From: Sage Weil Date: Tue, 31 May 2016 18:43:49 +0000 (-0400) Subject: buffer: add iterator crc32c method X-Git-Tag: v11.0.0~346^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=414d96608db5dd7e09332860f761bd371c533104;p=ceph.git buffer: add iterator crc32c method Calculate crc from an iterator position. Signed-off-by: Sage Weil --- diff --git a/src/common/buffer.cc b/src/common/buffer.cc index b809d92621f3..191b57869594 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -1218,6 +1218,19 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; return l; } + template + uint32_t buffer::list::iterator_impl::crc32c( + size_t length, uint32_t crc) + { + while (length > 0) { + const char *p; + size_t l = get_ptr_and_advance(length, &p); + crc = ceph_crc32c(crc, (unsigned char*)p, l); + length -= l; + } + return crc; + } + // explicitly instantiate only the iterator types we need, so we can hide the // details in this compilation unit without introducing unnecessary link time // dependencies. diff --git a/src/include/buffer.h b/src/include/buffer.h index a4e89005a5c4..999857323786 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -329,6 +329,9 @@ namespace buffer CEPH_BUFFER_API { // and advance the iterator by that amount. size_t get_ptr_and_advance(size_t want, const char **p); + /// calculate crc from iterator position + uint32_t crc32c(size_t length, uint32_t crc); + friend bool operator==(const iterator_impl& lhs, const iterator_impl& rhs) { return &lhs.get_bl() == &rhs.get_bl() && lhs.get_off() == rhs.get_off();