Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: net/http2/tools/http2_random.cc

Issue 2554683003: Revert of Add new HTTP/2 and HPACK decoder in net/http2/. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http2/tools/http2_random.h ('k') | net/http2/tools/random_decoder_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/http2/tools/http2_random.h"
6
7 #include <limits>
8 #include <memory>
9
10 #include "base/rand_util.h"
11
12 namespace net {
13 namespace test {
14
15 bool Http2Random::OneIn(int n) {
16 return base::RandGenerator(n) == 0;
17 }
18
19 int32_t Http2Random::Uniform(int32_t n) {
20 return base::RandGenerator(n);
21 }
22
23 uint8_t Http2Random::Rand8() {
24 return base::RandGenerator(
25 static_cast<uint64_t>(std::numeric_limits<uint8_t>::max()) + 1);
26 }
27
28 uint16_t Http2Random::Rand16() {
29 return base::RandGenerator(
30 static_cast<uint64_t>(std::numeric_limits<uint16_t>::max()) + 1);
31 }
32
33 uint32_t Http2Random::Rand32() {
34 return base::RandGenerator(
35 static_cast<uint64_t>(std::numeric_limits<uint32_t>::max()) + 1);
36 }
37
38 uint64_t Http2Random::Rand64() {
39 return base::RandUint64();
40 }
41
42 int32_t Http2Random::Next() {
43 return Rand32();
44 }
45
46 int32_t Http2Random::Skewed(int max_log) {
47 const uint32_t base = Rand32() % (max_log + 1);
48 const uint32_t mask = ((base < 32) ? (1u << base) : 0u) - 1u;
49 return Rand32() & mask;
50 }
51
52 std::string Http2Random::RandString(int length) {
53 std::unique_ptr<char[]> buffer(new char[length]);
54 base::RandBytes(buffer.get(), length);
55 return std::string(buffer.get(), length);
56 }
57
58 } // namespace test
59 } // namespace net
OLDNEW
« no previous file with comments | « net/http2/tools/http2_random.h ('k') | net/http2/tools/random_decoder_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698