michael@0: //* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef ChunkSet_h__ michael@0: #define ChunkSet_h__ michael@0: michael@0: michael@0: #include "Entries.h" michael@0: #include "nsString.h" michael@0: #include "nsTArray.h" michael@0: michael@0: namespace mozilla { michael@0: namespace safebrowsing { michael@0: michael@0: /** michael@0: * Store the chunk numbers as an array of uint32_t. We need chunk numbers in michael@0: * order to ask for incremental updates from the server. michael@0: * XXX: We should optimize this further to compress the many consecutive michael@0: * numbers. michael@0: */ michael@0: class ChunkSet { michael@0: public: michael@0: ChunkSet() {} michael@0: ~ChunkSet() {} michael@0: michael@0: nsresult Serialize(nsACString& aStr); michael@0: nsresult Set(uint32_t aChunk); michael@0: nsresult Unset(uint32_t aChunk); michael@0: void Clear(); michael@0: nsresult Merge(const ChunkSet& aOther); michael@0: nsresult Remove(const ChunkSet& aOther); michael@0: michael@0: bool Has(uint32_t chunk) const; michael@0: michael@0: uint32_t Length() const { return mChunks.Length(); } michael@0: michael@0: nsresult Write(nsIOutputStream* aOut) { michael@0: return WriteTArray(aOut, mChunks); michael@0: } michael@0: michael@0: nsresult Read(nsIInputStream* aIn, uint32_t aNumElements) { michael@0: return ReadTArray(aIn, &mChunks, aNumElements); michael@0: } michael@0: michael@0: uint32_t *Begin() { return mChunks.Elements(); } michael@0: uint32_t *End() { return mChunks.Elements() + mChunks.Length(); } michael@0: michael@0: private: michael@0: nsTArray mChunks; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif