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

Side by Side Diff: net/tools/domain_security_preload_generator/trie/trie_bit_buffer.h

Issue 2551153003: Add static domain security state generator tool. (Closed)
Patch Set: Fix iOS? 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
OLDNEW
(Empty)
1 // Copyright (c) 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 #ifndef NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_TRIE_TRIE_BIT_BUFFER_H_
6 #define NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_TRIE_TRIE_BIT_BUFFER_H_
7
8 #include <stdint.h>
9
10 #include <vector>
11
12 #include "net/tools/domain_security_preload_generator/huffman/huffman_frequency_ tracker.h"
13
14 namespace net {
15
16 namespace transport_security_state {
17
18 class BitWriter;
19
20 // TrieBitBuffer acts as a buffer for TrieWriter. It can be used to write bits,
21 // characters, and positions. The characters are stored as their
22 // HuffmanRepresentation. Positions are references to other locations in the
23 // trie.
24 class TrieBitBuffer {
25 public:
26 TrieBitBuffer();
27 ~TrieBitBuffer();
28
29 // Writes |bit| to the buffer.
30 void WriteBit(uint8_t bit);
31
32 // Writes the |number_of_bits| least-significant bits from |bits| to the
33 // buffer.
34 void WriteBits(uint32_t bits, uint8_t number_of_bits);
35
36 // Write a position to the buffer. Actually writes the difference between
37 // |position| and |last_position|. |*last_position| will be updated to equal
38 // the input |position|.
39 void WritePosition(uint32_t position, int32_t* last_position);
40
41 // Writes the character in |byte| to the buffer using its Huffman
42 // representation in |table|. Optionally tracks usage of the character in
43 // |*tracker|.
44 void WriteChar(uint8_t byte,
45 const HuffmanRepresentationTable& table,
46 HuffmanFrequencyTracker* tracker);
47
48 // Writes the entire buffer to |*writer|. Returns the position |*writer| was
49 // at before the buffer was written to it.
50 uint32_t WriteToBitWriter(BitWriter* writer);
51
52 // Appends the buffered bits in |current_byte_| to |elements_|. Empty bits
53 // are filled with zero's.
54 void Flush();
55
56 private:
57 // Represents either the |number_of_bits| least-significant bits in |bits| or
58 // a position (offset) in the trie.
59 struct BitsOrPosition {
60 uint8_t bits;
61 uint8_t number_of_bits;
62 uint32_t position;
63 };
64
65 // Returns the minimum number of bits needed to represent |input|.
66 uint8_t BitLength(uint32_t input) const;
67
68 // Append a new element to |elements_|.
69 void AppendBitsElement(uint8_t bits, uint8_t number_of_bits);
70 void AppendPositionElement(uint32_t position);
71
72 // Buffers bits until they fill a whole byte.
73 uint8_t current_byte_ = 0;
74
75 // The number of bits currently in |current_byte_|.
76 uint32_t used_ = 0;
77
78 std::vector<BitsOrPosition> elements_;
79 };
80
81 } // namespace transport_security_state
82
83 } // namespace net
84
85 #endif // NET_TOOLS_DOMAIN_SECURITY_PRELOAD_GENERATOR_TRIE_TRIE_BIT_BUFFER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698