\doxysection{bitvec.\+h}
\label{bitvec_8h_source}\index{include/osmocom/core/bitvec.h@{include/osmocom/core/bitvec.h}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{1 \textcolor{comment}{/* (C) 2009 by Harald Welte <laforge@gnumonks.org>}}
\DoxyCodeLine{2 \textcolor{comment}{ * (C) 2012 Ivan Klyuchnikov}}
\DoxyCodeLine{3 \textcolor{comment}{ * (C) 2015 sysmocom -\/ s.f.m.c. GmbH}}
\DoxyCodeLine{4 \textcolor{comment}{ *}}
\DoxyCodeLine{5 \textcolor{comment}{ * All Rights Reserved}}
\DoxyCodeLine{6 \textcolor{comment}{ *}}
\DoxyCodeLine{7 \textcolor{comment}{ * This program is free software; you can redistribute it and/or modify}}
\DoxyCodeLine{8 \textcolor{comment}{ * it under the terms of the GNU General Public License as published by}}
\DoxyCodeLine{9 \textcolor{comment}{ * the Free Software Foundation; either version 2 of the License, or}}
\DoxyCodeLine{10 \textcolor{comment}{ * (at your option) any later version.}}
\DoxyCodeLine{11 \textcolor{comment}{ *}}
\DoxyCodeLine{12 \textcolor{comment}{ * This program is distributed in the hope that it will be useful,}}
\DoxyCodeLine{13 \textcolor{comment}{ * but WITHOUT ANY WARRANTY; without even the implied warranty of}}
\DoxyCodeLine{14 \textcolor{comment}{ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the}}
\DoxyCodeLine{15 \textcolor{comment}{ * GNU General Public License for more details.}}
\DoxyCodeLine{16 \textcolor{comment}{ *}}
\DoxyCodeLine{17 \textcolor{comment}{ */}}
\DoxyCodeLine{18 }
\DoxyCodeLine{19 \textcolor{preprocessor}{\#pragma once}}
\DoxyCodeLine{20 }
\DoxyCodeLine{25 \textcolor{preprocessor}{\#include <stdint.h>}}
\DoxyCodeLine{26 \textcolor{preprocessor}{\#include <osmocom/core/defs.h>}}
\DoxyCodeLine{27 \textcolor{preprocessor}{\#include <stdbool.h>}}
\DoxyCodeLine{28 }
\DoxyCodeLine{33 \textcolor{keyword}{enum} bit\_value \{}
\DoxyCodeLine{34         ZERO        = 0,    }
\DoxyCodeLine{35         ONE  = 1,    }
\DoxyCodeLine{36         L      = 2,    }
\DoxyCodeLine{37         H      = 3,    }
\DoxyCodeLine{38 \};}
\DoxyCodeLine{39 }
\DoxyCodeLine{41 \textcolor{keyword}{struct }bitvec \{}
\DoxyCodeLine{42         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} cur\_bit;    }
\DoxyCodeLine{43         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} data\_len;  }
\DoxyCodeLine{44         uint8\_t *data;              }
\DoxyCodeLine{45 \};}
\DoxyCodeLine{46 }
\DoxyCodeLine{47 \textcolor{keyword}{enum} bit\_value bitvec\_get\_bit\_pos(\textcolor{keyword}{const} \textcolor{keyword}{struct} bitvec *bv, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} bitnr);}
\DoxyCodeLine{48 \textcolor{keyword}{enum} bit\_value bitvec\_get\_bit\_pos\_high(\textcolor{keyword}{const} \textcolor{keyword}{struct} bitvec *bv,}
\DoxyCodeLine{49                                         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} bitnr);}
\DoxyCodeLine{50 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} bitvec\_get\_nth\_set\_bit(\textcolor{keyword}{const} \textcolor{keyword}{struct} bitvec *bv, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} n);}
\DoxyCodeLine{51 \textcolor{keywordtype}{int} bitvec\_set\_bit\_pos(\textcolor{keyword}{struct} bitvec *bv, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} bitnum,}
\DoxyCodeLine{52                         \textcolor{keyword}{enum} bit\_value bit);}
\DoxyCodeLine{53 \textcolor{keywordtype}{int} bitvec\_set\_bit(\textcolor{keyword}{struct} bitvec *bv, \textcolor{keyword}{enum} bit\_value bit);}
\DoxyCodeLine{54 \textcolor{keywordtype}{int} bitvec\_get\_bit\_high(\textcolor{keyword}{struct} bitvec *bv);}
\DoxyCodeLine{55 \textcolor{keywordtype}{int} bitvec\_set\_bits(\textcolor{keyword}{struct} bitvec *bv, \textcolor{keyword}{const} \textcolor{keyword}{enum} bit\_value *bits, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} count);}
\DoxyCodeLine{56 \textcolor{keywordtype}{int} bitvec\_set\_u64(\textcolor{keyword}{struct} bitvec *bv, uint64\_t v, uint8\_t num\_bits, \textcolor{keywordtype}{bool} use\_lh);}
\DoxyCodeLine{57 \textcolor{keywordtype}{int} bitvec\_set\_uint(\textcolor{keyword}{struct} bitvec *bv, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} in, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} count);}
\DoxyCodeLine{58 \textcolor{keywordtype}{int} bitvec\_get\_uint(\textcolor{keyword}{struct} bitvec *bv, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} num\_bits);}
\DoxyCodeLine{59 \textcolor{keywordtype}{int} bitvec\_find\_bit\_pos(\textcolor{keyword}{const} \textcolor{keyword}{struct} bitvec *bv, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} n, \textcolor{keyword}{enum} bit\_value val);}
\DoxyCodeLine{60 \textcolor{keywordtype}{int} bitvec\_spare\_padding(\textcolor{keyword}{struct} bitvec *bv, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} up\_to\_bit);}
\DoxyCodeLine{61 \textcolor{keywordtype}{int} bitvec\_get\_bytes(\textcolor{keyword}{struct} bitvec *bv, uint8\_t *bytes, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} count);}
\DoxyCodeLine{62 \textcolor{keywordtype}{int} bitvec\_set\_bytes(\textcolor{keyword}{struct} bitvec *bv, \textcolor{keyword}{const} uint8\_t *bytes, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} count);}
\DoxyCodeLine{63 \textcolor{keyword}{struct }bitvec *bitvec\_alloc(\textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} size, \textcolor{keywordtype}{void} *bvctx);}
\DoxyCodeLine{64 \textcolor{keywordtype}{void} bitvec\_free(\textcolor{keyword}{struct} bitvec *bv);}
\DoxyCodeLine{65 \textcolor{keywordtype}{int} bitvec\_unhex(\textcolor{keyword}{struct} bitvec *bv, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *src);}
\DoxyCodeLine{66 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} bitvec\_pack(\textcolor{keyword}{const} \textcolor{keyword}{struct} bitvec *bv, uint8\_t *buffer);}
\DoxyCodeLine{67 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} bitvec\_unpack(\textcolor{keyword}{struct} bitvec *bv, \textcolor{keyword}{const} uint8\_t *buffer);}
\DoxyCodeLine{68 uint64\_t bitvec\_read\_field(\textcolor{keyword}{struct} bitvec *bv, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} *read\_index, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} len);}
\DoxyCodeLine{69 \textcolor{keywordtype}{int} bitvec\_write\_field(\textcolor{keyword}{struct} bitvec *bv, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} *write\_index, uint64\_t val, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} len);}
\DoxyCodeLine{70 \textcolor{keywordtype}{int} bitvec\_fill(\textcolor{keyword}{struct} bitvec *bv, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} num\_bits, \textcolor{keyword}{enum} bit\_value fill);}
\DoxyCodeLine{71 \textcolor{keywordtype}{char} bit\_value\_to\_char(\textcolor{keyword}{enum} bit\_value v);}
\DoxyCodeLine{72 \textcolor{keywordtype}{void} bitvec\_to\_string\_r(\textcolor{keyword}{const} \textcolor{keyword}{struct} bitvec *bv, \textcolor{keywordtype}{char} *str);}
\DoxyCodeLine{73 \textcolor{keywordtype}{void} bitvec\_zero(\textcolor{keyword}{struct} bitvec *bv);}
\DoxyCodeLine{74 \textcolor{keywordtype}{unsigned} bitvec\_rl(\textcolor{keyword}{const} \textcolor{keyword}{struct} bitvec *bv, \textcolor{keywordtype}{bool} b);}
\DoxyCodeLine{75 \textcolor{keywordtype}{unsigned} bitvec\_rl\_curbit(\textcolor{keyword}{struct} bitvec *bv, \textcolor{keywordtype}{bool} b, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} max\_bits);}
\DoxyCodeLine{76 \textcolor{keywordtype}{void} bitvec\_shiftl(\textcolor{keyword}{struct} bitvec *bv, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} n);}
\DoxyCodeLine{77 int16\_t bitvec\_get\_int16\_msb(\textcolor{keyword}{const} \textcolor{keyword}{struct} bitvec *bv, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} num\_bits);}
\DoxyCodeLine{78 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} bitvec\_add\_array(\textcolor{keyword}{struct} bitvec *bv, \textcolor{keyword}{const} uint32\_t *array,}
\DoxyCodeLine{79                               \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} array\_len, \textcolor{keywordtype}{bool} dry\_run,}
\DoxyCodeLine{80                               \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} num\_bits);}
\DoxyCodeLine{81 }
\DoxyCodeLine{83 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} bitvec\_used\_bytes(\textcolor{keyword}{const} \textcolor{keyword}{struct} bitvec *bv)}
\DoxyCodeLine{84 \{}
\DoxyCodeLine{85         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} bytes = bv-\/>cur\_bit/8;}
\DoxyCodeLine{86         \textcolor{keywordflow}{if} (bv-\/>cur\_bit\%8)}
\DoxyCodeLine{87                 bytes++;}
\DoxyCodeLine{88         \textcolor{keywordflow}{return} bytes;}
\DoxyCodeLine{89 \}}
\DoxyCodeLine{90 }
\DoxyCodeLine{92 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} bitvec\_tailroom\_bits(\textcolor{keyword}{const} \textcolor{keyword}{struct} bitvec *bv)}
\DoxyCodeLine{93 \{}
\DoxyCodeLine{94         \textcolor{keywordflow}{return} bv-\/>data\_len*8 -\/ bv-\/>cur\_bit;}
\DoxyCodeLine{95 \}}
\DoxyCodeLine{96 }

\end{DoxyCode}
