\doxysection{hpack.\+h}
\hypertarget{hpack_8h_source}{}\label{hpack_8h_source}\index{src/hpack.h@{src/hpack.h}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{comment}{/*******************************************************************************}}
\DoxyCodeLine{00002\ \textcolor{comment}{\ *\ Copyright\ (c)\ 2014,\ Jan\ Koester\ jan.koester@gmx.net}}
\DoxyCodeLine{00003\ \textcolor{comment}{\ *\ All\ rights\ reserved.}}
\DoxyCodeLine{00004\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00005\ \textcolor{comment}{\ *\ Redistribution\ and\ use\ in\ source\ and\ binary\ forms,\ with\ or\ without}}
\DoxyCodeLine{00006\ \textcolor{comment}{\ *\ modification,\ are\ permitted\ provided\ that\ the\ following\ conditions\ are\ met:}}
\DoxyCodeLine{00007\ \textcolor{comment}{\ *\ Redistributions\ of\ source\ code\ must\ retain\ the\ above\ copyright}}
\DoxyCodeLine{00008\ \textcolor{comment}{\ *\ \ \ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer.}}
\DoxyCodeLine{00009\ \textcolor{comment}{\ *\ Redistributions\ in\ binary\ form\ must\ reproduce\ the\ above\ copyright}}
\DoxyCodeLine{00010\ \textcolor{comment}{\ *\ \ \ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer\ in\ the}}
\DoxyCodeLine{00011\ \textcolor{comment}{\ *\ \ \ \ \ \ documentation\ and/or\ other\ materials\ provided\ with\ the\ distribution.}}
\DoxyCodeLine{00012\ \textcolor{comment}{\ *\ Neither\ the\ name\ of\ the\ <organization>\ nor\ the}}
\DoxyCodeLine{00013\ \textcolor{comment}{\ *\ \ \ \ \ \ names\ of\ its\ contributors\ may\ be\ used\ to\ endorse\ or\ promote\ products}}
\DoxyCodeLine{00014\ \textcolor{comment}{\ *\ \ \ \ \ \ derived\ from\ this\ software\ without\ specific\ prior\ written\ permission.}}
\DoxyCodeLine{00015\ \textcolor{comment}{\ *\ }}
\DoxyCodeLine{00016\ \textcolor{comment}{\ *\ THIS\ SOFTWARE\ IS\ PROVIDED\ BY\ THE\ COPYRIGHT\ HOLDERS\ AND\ CONTRIBUTORS\ "{}AS\ IS"{}\ AND}}
\DoxyCodeLine{00017\ \textcolor{comment}{\ *\ ANY\ EXPRESS\ OR\ IMPLIED\ WARRANTIES,\ INCLUDING,\ BUT\ NOT\ LIMITED\ TO,\ THE\ IMPLIED}}
\DoxyCodeLine{00018\ \textcolor{comment}{\ *\ WARRANTIES\ OF\ MERCHANTABILITY\ AND\ FITNESS\ FOR\ A\ PARTICULAR\ PURPOSE\ ARE}}
\DoxyCodeLine{00019\ \textcolor{comment}{\ *\ DISCLAIMED.\ IN\ NO\ EVENT\ SHALL\ <COPYRIGHT\ HOLDER>\ BE\ LIABLE\ FOR\ ANY}}
\DoxyCodeLine{00020\ \textcolor{comment}{\ *\ DIRECT,\ INDIRECT,\ INCIDENTAL,\ SPECIAL,\ EXEMPLARY,\ OR\ CONSEQUENTIAL\ DAMAGES}}
\DoxyCodeLine{00021\ \textcolor{comment}{\ *\ (INCLUDING,\ BUT\ NOT\ LIMITED\ TO,\ PROCUREMENT\ OF\ SUBSTITUTE\ GOODS\ OR\ SERVICES;}}
\DoxyCodeLine{00022\ \textcolor{comment}{\ *\ LOSS\ OF\ USE,\ DATA,\ OR\ PROFITS;\ OR\ BUSINESS\ INTERRUPTION)\ HOWEVER\ CAUSED\ AND}}
\DoxyCodeLine{00023\ \textcolor{comment}{\ *\ ON\ ANY\ THEORY\ OF\ LIABILITY,\ WHETHER\ IN\ CONTRACT,\ STRICT\ LIABILITY,\ OR\ TORT}}
\DoxyCodeLine{00024\ \textcolor{comment}{\ *\ (INCLUDING\ NEGLIGENCE\ OR\ OTHERWISE)\ ARISING\ IN\ ANY\ WAY\ OUT\ OF\ THE\ USE\ OF\ THIS}}
\DoxyCodeLine{00025\ \textcolor{comment}{\ *\ SOFTWARE,\ EVEN\ IF\ ADVISED\ OF\ THE\ POSSIBILITY\ OF\ SUCH\ DAMAGE.}}
\DoxyCodeLine{00026\ \textcolor{comment}{\ *******************************************************************************/}}
\DoxyCodeLine{00027\ }
\DoxyCodeLine{00028\ \textcolor{preprocessor}{\#pragma\ once}}
\DoxyCodeLine{00029\ }
\DoxyCodeLine{00030\ \textcolor{preprocessor}{\#include\ <cstddef>}}
\DoxyCodeLine{00031\ \textcolor{preprocessor}{\#include\ <cstdint>}}
\DoxyCodeLine{00032\ \textcolor{preprocessor}{\#include\ <deque>}}
\DoxyCodeLine{00033\ \textcolor{preprocessor}{\#include\ <string>}}
\DoxyCodeLine{00034\ \textcolor{preprocessor}{\#include\ <vector>}}
\DoxyCodeLine{00035\ }
\DoxyCodeLine{00036\ \textcolor{keyword}{namespace\ }libhttppp::hpack\ \{}
\DoxyCodeLine{00037\ }
\DoxyCodeLine{00038\ \textcolor{keyword}{struct\ }\mbox{\hyperlink{structlibhttppp_1_1hpack_1_1HeaderField}{HeaderField}}\ \{}
\DoxyCodeLine{00039\ \ \ \ \ std::string\ name;}
\DoxyCodeLine{00040\ \ \ \ \ std::string\ value;}
\DoxyCodeLine{00041\ \ \ \ \ \textcolor{keywordtype}{bool}\ incremental\_index\ =\ \textcolor{keyword}{false};}
\DoxyCodeLine{00042\ \};}
\DoxyCodeLine{00043\ }
\DoxyCodeLine{00044\ \textcolor{keyword}{class\ }\mbox{\hyperlink{classlibhttppp_1_1hpack_1_1Encoder}{Encoder}}\ \{}
\DoxyCodeLine{00045\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00046\ \ \ \ \ \textcolor{keyword}{static}\ std::string\ encodeResponseHeaders(uint16\_t\ status\_code,}
\DoxyCodeLine{00047\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ std::string\ \&content\_type,}
\DoxyCodeLine{00048\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{size\_t}\ content\_length,}
\DoxyCodeLine{00049\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ std::vector<HeaderField>\ \&extra\ =\ \{\});}
\DoxyCodeLine{00050\ }
\DoxyCodeLine{00051\ \ \ \ \ \textcolor{keyword}{static}\ std::string\ encodeRequestHeaders(\textcolor{keyword}{const}\ std::string\ \&method,}
\DoxyCodeLine{00052\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ std::string\ \&path,}
\DoxyCodeLine{00053\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ std::string\ \&scheme,}
\DoxyCodeLine{00054\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ std::string\ \&authority,}
\DoxyCodeLine{00055\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ std::vector<HeaderField>\ \&extra\ =\ \{\});}
\DoxyCodeLine{00056\ }
\DoxyCodeLine{00057\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00058\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}\ appendLiteral(std::string\ \&out,}
\DoxyCodeLine{00059\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ std::string\ \&name,}
\DoxyCodeLine{00060\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ std::string\ \&value,}
\DoxyCodeLine{00061\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{bool}\ incremental\_index);}
\DoxyCodeLine{00062\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}\ appendLiteralWithNameIndex(std::string\ \&out,}
\DoxyCodeLine{00063\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ uint8\_t\ name\_index,}
\DoxyCodeLine{00064\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ std::string\ \&value,}
\DoxyCodeLine{00065\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{bool}\ incremental\_index);}
\DoxyCodeLine{00066\ \};}
\DoxyCodeLine{00067\ }
\DoxyCodeLine{00068\ \textcolor{keyword}{class\ }\mbox{\hyperlink{classlibhttppp_1_1hpack_1_1Decoder}{Decoder}}\ \{}
\DoxyCodeLine{00069\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00070\ \ \ \ \ \mbox{\hyperlink{classlibhttppp_1_1hpack_1_1Decoder}{Decoder}}()\ =\ \textcolor{keywordflow}{default};}
\DoxyCodeLine{00071\ \ \ \ \ \mbox{\hyperlink{classlibhttppp_1_1hpack_1_1Decoder}{\string~Decoder}}()\ =\ \textcolor{keywordflow}{default};}
\DoxyCodeLine{00072\ }
\DoxyCodeLine{00073\ \ \ \ \ \textcolor{comment}{//\ Non-\/copyable\ /\ non-\/movable\ —\ the\ dynamic\ table\ must\ not\ be}}
\DoxyCodeLine{00074\ \ \ \ \ \textcolor{comment}{//\ accidentally\ shared\ or\ left\ in\ a\ moved-\/from\ state.}}
\DoxyCodeLine{00075\ \ \ \ \ \mbox{\hyperlink{classlibhttppp_1_1hpack_1_1Decoder}{Decoder}}(\textcolor{keyword}{const}\ \mbox{\hyperlink{classlibhttppp_1_1hpack_1_1Decoder}{Decoder}}\ \&)\ =\ \textcolor{keyword}{delete};}
\DoxyCodeLine{00076\ \ \ \ \ \mbox{\hyperlink{classlibhttppp_1_1hpack_1_1Decoder}{Decoder}}\ \&operator=(\textcolor{keyword}{const}\ \mbox{\hyperlink{classlibhttppp_1_1hpack_1_1Decoder}{Decoder}}\ \&)\ =\ \textcolor{keyword}{delete};}
\DoxyCodeLine{00077\ \ \ \ \ \mbox{\hyperlink{classlibhttppp_1_1hpack_1_1Decoder}{Decoder}}(\mbox{\hyperlink{classlibhttppp_1_1hpack_1_1Decoder}{Decoder}}\ \&\&)\ =\ \textcolor{keyword}{delete};}
\DoxyCodeLine{00078\ \ \ \ \ \mbox{\hyperlink{classlibhttppp_1_1hpack_1_1Decoder}{Decoder}}\ \&operator=(\mbox{\hyperlink{classlibhttppp_1_1hpack_1_1Decoder}{Decoder}}\ \&\&)\ =\ \textcolor{keyword}{delete};}
\DoxyCodeLine{00079\ }
\DoxyCodeLine{00080\ \ \ \ \ \textcolor{keywordtype}{void}\ reset()\ \{\ \_dynTable.clear();\ \_dynTableSize\ =\ 0;\ \}}
\DoxyCodeLine{00081\ }
\DoxyCodeLine{00082\ \ \ \ \ \textcolor{comment}{//\ Instance\ method:\ decode\ using\ (and\ updating)\ the\ dynamic\ table}}
\DoxyCodeLine{00083\ \ \ \ \ std::vector<HeaderField>\ decode(\textcolor{keyword}{const}\ uint8\_t\ *data,\ \textcolor{keywordtype}{size\_t}\ len);}
\DoxyCodeLine{00084\ \ \ \ \ std::vector<HeaderField>\ decode(\textcolor{keyword}{const}\ std::string\ \&data);}
\DoxyCodeLine{00085\ }
\DoxyCodeLine{00086\ \ \ \ \ \textcolor{comment}{//\ Static\ convenience\ (stateless,\ no\ dynamic\ table\ —\ for\ one-\/shot\ use)}}
\DoxyCodeLine{00087\ \ \ \ \ \textcolor{keyword}{static}\ std::vector<HeaderField>\ decodeStateless(\textcolor{keyword}{const}\ uint8\_t\ *data,\ \textcolor{keywordtype}{size\_t}\ len);}
\DoxyCodeLine{00088\ }
\DoxyCodeLine{00089\ \ \ \ \ \textcolor{comment}{//\ Shared\ utilities\ (also\ used\ by\ QPACK\ decoder)}}
\DoxyCodeLine{00090\ \ \ \ \ \textcolor{keyword}{static}\ uint32\_t\ decodeInt(\textcolor{keyword}{const}\ uint8\_t\ *data,\ \textcolor{keywordtype}{size\_t}\ len,\ uint8\_t\ prefix\_bits,\ \textcolor{keywordtype}{size\_t}\ \&bytes\_read);}
\DoxyCodeLine{00091\ \ \ \ \ \textcolor{keyword}{static}\ std::string\ decodeString(\textcolor{keyword}{const}\ uint8\_t\ *data,\ \textcolor{keywordtype}{size\_t}\ len,\ \textcolor{keywordtype}{size\_t}\ \&bytes\_read);}
\DoxyCodeLine{00092\ \ \ \ \ \textcolor{keyword}{static}\ std::string\ huffmanDecode(\textcolor{keyword}{const}\ uint8\_t\ *data,\ \textcolor{keywordtype}{size\_t}\ len);}
\DoxyCodeLine{00093\ }
\DoxyCodeLine{00094\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00095\ \ \ \ \ \textcolor{comment}{//\ Dynamic\ table\ (RFC\ 7541\ §2.3.2):\ newest\ entry\ at\ front}}
\DoxyCodeLine{00096\ \ \ \ \ \textcolor{keyword}{struct\ }DynEntry\ \{\ std::string\ name;\ std::string\ value;\ \};}
\DoxyCodeLine{00097\ \ \ \ \ std::deque<DynEntry>\ \_dynTable;}
\DoxyCodeLine{00098\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ \_dynTableSize\ =\ 0;\ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ current\ size\ in\ octets}}
\DoxyCodeLine{00099\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ \_dynTableMaxSize\ =\ 4096;\ \ \ \ \ \textcolor{comment}{//\ default\ per\ RFC\ 7541\ §6.5.2}}
\DoxyCodeLine{00100\ }
\DoxyCodeLine{00101\ \ \ \ \ \textcolor{comment}{//\ Look\ up\ an\ index\ across\ static\ +\ dynamic\ tables}}
\DoxyCodeLine{00102\ \ \ \ \ \textcolor{keywordtype}{bool}\ lookupIndex(uint32\_t\ idx,\ std::string\ \&name,\ std::string\ \&value)\ \textcolor{keyword}{const};}
\DoxyCodeLine{00103\ \ \ \ \ \textcolor{keywordtype}{bool}\ lookupIndexName(uint32\_t\ idx,\ std::string\ \&name)\ \textcolor{keyword}{const};}
\DoxyCodeLine{00104\ }
\DoxyCodeLine{00105\ \ \ \ \ \textcolor{comment}{//\ Add\ an\ entry\ to\ the\ dynamic\ table,\ evicting\ as\ necessary}}
\DoxyCodeLine{00106\ \ \ \ \ \textcolor{keywordtype}{void}\ addEntry(\textcolor{keyword}{const}\ std::string\ \&name,\ \textcolor{keyword}{const}\ std::string\ \&value);}
\DoxyCodeLine{00107\ \ \ \ \ \textcolor{keywordtype}{void}\ evict(\textcolor{keywordtype}{size\_t}\ required);}
\DoxyCodeLine{00108\ }
\DoxyCodeLine{00109\ \ \ \ \ \textcolor{keyword}{struct\ }StaticEntry\ \{\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *name;\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *value;\ \};}
\DoxyCodeLine{00110\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ StaticEntry\ STATIC\_TABLE[];}
\DoxyCodeLine{00111\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{size\_t}\ STATIC\_TABLE\_SIZE;}
\DoxyCodeLine{00112\ \};}
\DoxyCodeLine{00113\ }
\DoxyCodeLine{00114\ \}\ \textcolor{comment}{//\ namespace\ libhttppp::hpack}}

\end{DoxyCode}
