2 * Copyright 2017 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
29 struct GroupVarintTraits;
32 struct GroupVarintTraits<uint32_t> {
40 struct GroupVarintTraits<uint64_t> {
48 class GroupVarintBase {
50 typedef GroupVarintTraits<T> Traits;
51 enum : uint32_t { kHeaderSize = Traits::kHeaderSize };
57 * Number of integers encoded / decoded in one pass.
59 enum : uint32_t { kGroupSize = Traits::kGroupSize };
62 * Maximum encoded size.
64 enum : uint32_t { kMaxSize = kHeaderSize + sizeof(type) * kGroupSize };
67 * Maximum size for n values.
69 static size_t maxSize(size_t n) {
71 size_t total = (n / kGroupSize) * kFullGroupSize;
72 // Incomplete last group, if any
75 total += kHeaderSize + n * sizeof(type);
81 * Size of n values starting at p.
83 static size_t totalSize(const T* p, size_t n) {
85 for (; n >= kGroupSize; n -= kGroupSize, p += kGroupSize) {
86 size += Derived::size(p);
89 size += Derived::partialSize(p, n);
95 typedef GroupVarint<T> Derived;
96 enum { kFullGroupSize = kHeaderSize + kGroupSize * sizeof(type) };