\doxysection{msgb.\+h} \label{msgb_8h_source}\index{include/osmocom/core/msgb.h@{include/osmocom/core/msgb.h}} \textbf{ Go to the documentation of this file.} \begin{DoxyCode}{0} \DoxyCodeLine{1 \textcolor{preprocessor}{\#pragma once}} \DoxyCodeLine{2 } \DoxyCodeLine{3 \textcolor{comment}{/* (C) 2008 by Harald Welte }} \DoxyCodeLine{4 \textcolor{comment}{ * All Rights Reserved}} \DoxyCodeLine{5 \textcolor{comment}{ *}} \DoxyCodeLine{6 \textcolor{comment}{ * This program is free software; you can redistribute it and/or modify}} \DoxyCodeLine{7 \textcolor{comment}{ * it under the terms of the GNU General Public License as published by}} \DoxyCodeLine{8 \textcolor{comment}{ * the Free Software Foundation; either version 2 of the License, or}} \DoxyCodeLine{9 \textcolor{comment}{ * (at your option) any later version.}} \DoxyCodeLine{10 \textcolor{comment}{ *}} \DoxyCodeLine{11 \textcolor{comment}{ * This program is distributed in the hope that it will be useful,}} \DoxyCodeLine{12 \textcolor{comment}{ * but WITHOUT ANY WARRANTY; without even the implied warranty of}} \DoxyCodeLine{13 \textcolor{comment}{ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the}} \DoxyCodeLine{14 \textcolor{comment}{ * GNU General Public License for more details.}} \DoxyCodeLine{15 \textcolor{comment}{ *}} \DoxyCodeLine{16 \textcolor{comment}{ */}} \DoxyCodeLine{17 } \DoxyCodeLine{18 \textcolor{preprocessor}{\#include }} \DoxyCodeLine{19 \textcolor{preprocessor}{\#include }} \DoxyCodeLine{20 \textcolor{preprocessor}{\#include }} \DoxyCodeLine{21 \textcolor{preprocessor}{\#include }} \DoxyCodeLine{22 \textcolor{preprocessor}{\#include }} \DoxyCodeLine{23 } \DoxyCodeLine{28 \textcolor{preprocessor}{\#define MSGB\_DEBUG}} \DoxyCodeLine{29 } \DoxyCodeLine{31 \textcolor{keyword}{struct }msgb \{} \DoxyCodeLine{32 \textcolor{keyword}{struct }llist\_head list; } \DoxyCodeLine{35 \textcolor{comment}{/* Part of which TRX logical channel we were received / transmitted */}} \DoxyCodeLine{36 \textcolor{comment}{/* FIXME: move them into the control buffer */}} \DoxyCodeLine{37 \textcolor{keyword}{union }\{} \DoxyCodeLine{38 \textcolor{keywordtype}{void} *dst; } \DoxyCodeLine{39 \textcolor{keyword}{struct }gsm\_bts\_trx *trx;} \DoxyCodeLine{40 \};} \DoxyCodeLine{41 \textcolor{keyword}{struct }gsm\_lchan *lchan; } \DoxyCodeLine{43 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *l1h; } \DoxyCodeLine{44 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *l2h; } \DoxyCodeLine{45 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *l3h; } \DoxyCodeLine{46 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *l4h; } \DoxyCodeLine{48 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{long} cb[5]; } \DoxyCodeLine{50 uint16\_t data\_len; } \DoxyCodeLine{51 uint16\_t len; } \DoxyCodeLine{53 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *head; } \DoxyCodeLine{54 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *tail; } \DoxyCodeLine{55 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *data; } \DoxyCodeLine{56 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} \_data[0]; } \DoxyCodeLine{57 \};} \DoxyCodeLine{58 } \DoxyCodeLine{59 \textcolor{keyword}{extern} \textcolor{keyword}{struct }msgb *msgb\_alloc\_c(\textcolor{keyword}{const} \textcolor{keywordtype}{void} *ctx, uint16\_t size, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *name);} \DoxyCodeLine{60 \textcolor{keyword}{extern} \textcolor{keyword}{struct }msgb *msgb\_alloc(uint16\_t size, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *name);} \DoxyCodeLine{61 \textcolor{keyword}{extern} \textcolor{keywordtype}{void} msgb\_free(\textcolor{keyword}{struct} msgb *m);} \DoxyCodeLine{62 \textcolor{keyword}{extern} \textcolor{keywordtype}{void} msgb\_enqueue(\textcolor{keyword}{struct} llist\_head *queue, \textcolor{keyword}{struct} msgb *msg);} \DoxyCodeLine{63 \textcolor{keyword}{extern} \textcolor{keyword}{struct }msgb *msgb\_dequeue(\textcolor{keyword}{struct} llist\_head *queue);} \DoxyCodeLine{64 \textcolor{keyword}{extern} \textcolor{keywordtype}{void} msgb\_reset(\textcolor{keyword}{struct} msgb *m);} \DoxyCodeLine{65 uint16\_t msgb\_length(\textcolor{keyword}{const} \textcolor{keyword}{struct} msgb *msg);} \DoxyCodeLine{66 \textcolor{keyword}{extern} \textcolor{keyword}{const} \textcolor{keywordtype}{char} *msgb\_hexdump(\textcolor{keyword}{const} \textcolor{keyword}{struct} msgb *msg);} \DoxyCodeLine{67 \textcolor{keywordtype}{char} *msgb\_hexdump\_buf(\textcolor{keywordtype}{char} *buf, \textcolor{keywordtype}{size\_t} buf\_len, \textcolor{keyword}{const} \textcolor{keyword}{struct} msgb *msg);} \DoxyCodeLine{68 \textcolor{keywordtype}{char} *msgb\_hexdump\_c(\textcolor{keyword}{const} \textcolor{keywordtype}{void} *ctx, \textcolor{keyword}{const} \textcolor{keyword}{struct} msgb *msg);} \DoxyCodeLine{69 \textcolor{keyword}{extern} \textcolor{keywordtype}{int} msgb\_resize\_area(\textcolor{keyword}{struct} msgb *msg, uint8\_t *area,} \DoxyCodeLine{70 \textcolor{keywordtype}{int} old\_size, \textcolor{keywordtype}{int} new\_size);} \DoxyCodeLine{71 \textcolor{keyword}{extern} \textcolor{keyword}{struct }msgb *msgb\_copy(\textcolor{keyword}{const} \textcolor{keyword}{struct} msgb *msg, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *name);} \DoxyCodeLine{72 \textcolor{keyword}{extern} \textcolor{keyword}{struct }msgb *msgb\_copy\_c(\textcolor{keyword}{const} \textcolor{keywordtype}{void} *ctx, \textcolor{keyword}{const} \textcolor{keyword}{struct} msgb *msg, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *name);} \DoxyCodeLine{73 \textcolor{keyword}{extern} \textcolor{keyword}{struct }msgb *msgb\_copy\_resize(\textcolor{keyword}{const} \textcolor{keyword}{struct} msgb *msg, uint16\_t new\_len, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *name);} \DoxyCodeLine{74 \textcolor{keyword}{extern} \textcolor{keyword}{struct }msgb *msgb\_copy\_resize\_c(\textcolor{keyword}{const} \textcolor{keywordtype}{void} *ctx, \textcolor{keyword}{const} \textcolor{keyword}{struct} msgb *msg, uint16\_t new\_len, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *name);} \DoxyCodeLine{75 \textcolor{keyword}{static} \textcolor{keywordtype}{int} msgb\_test\_invariant(\textcolor{keyword}{const} \textcolor{keyword}{struct} msgb *msg) \_\_attribute\_\_((pure));} \DoxyCodeLine{76 } \DoxyCodeLine{80 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{void} msgb\_queue\_free(\textcolor{keyword}{struct} llist\_head *queue)} \DoxyCodeLine{81 \{} \DoxyCodeLine{82 \textcolor{keyword}{struct }msgb *msg;} \DoxyCodeLine{83 \textcolor{keywordflow}{while} ((msg = msgb\_dequeue(queue))) msgb\_free(msg);} \DoxyCodeLine{84 \}} \DoxyCodeLine{85 } \DoxyCodeLine{95 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{void} msgb\_enqueue\_count(\textcolor{keyword}{struct} llist\_head *queue, \textcolor{keyword}{struct} msgb *msg,} \DoxyCodeLine{96 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} *count)} \DoxyCodeLine{97 \{} \DoxyCodeLine{98 msgb\_enqueue(queue, msg);} \DoxyCodeLine{99 (*count)++;} \DoxyCodeLine{100 \}} \DoxyCodeLine{101 } \DoxyCodeLine{111 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keyword}{struct }msgb *msgb\_dequeue\_count(\textcolor{keyword}{struct} llist\_head *queue,} \DoxyCodeLine{112 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} *count)} \DoxyCodeLine{113 \{} \DoxyCodeLine{114 \textcolor{keyword}{struct }msgb *msg = msgb\_dequeue(queue);} \DoxyCodeLine{115 \textcolor{keywordflow}{if} (msg)} \DoxyCodeLine{116 (*count)-\/-\/;} \DoxyCodeLine{117 \textcolor{keywordflow}{return} msg;} \DoxyCodeLine{118 \}} \DoxyCodeLine{119 } \DoxyCodeLine{120 \textcolor{preprocessor}{\#ifdef MSGB\_DEBUG}} \DoxyCodeLine{121 \textcolor{preprocessor}{\#include }} \DoxyCodeLine{122 \textcolor{preprocessor}{\#define MSGB\_ABORT(msg, fmt, args ...) do \{ \(\backslash\)}} \DoxyCodeLine{123 \textcolor{preprocessor}{ osmo\_panic("{}msgb(\%p): "{}} fmt, msg, \#\# args); \(\backslash\)} \DoxyCodeLine{124 \} while(0)} \DoxyCodeLine{125 \textcolor{preprocessor}{\#else}} \DoxyCodeLine{126 \textcolor{preprocessor}{\#define MSGB\_ABORT(msg, fmt, args ...)}} \DoxyCodeLine{127 \textcolor{preprocessor}{\#endif}} \DoxyCodeLine{128 } \DoxyCodeLine{130 \textcolor{preprocessor}{\#define msgb\_l1(m) ((void *)((m)-\/>l1h))}} \DoxyCodeLine{132 \textcolor{preprocessor}{\#define msgb\_l2(m) ((void *)((m)-\/>l2h))}} \DoxyCodeLine{134 \textcolor{preprocessor}{\#define msgb\_l3(m) ((void *)((m)-\/>l3h))}} \DoxyCodeLine{136 \textcolor{preprocessor}{\#define msgb\_l4(m) ((void *)((m)-\/>l4h))}} \DoxyCodeLine{138 \textcolor{preprocessor}{\#define msgb\_sms(m) msgb\_l4(m)}} \DoxyCodeLine{139 } \DoxyCodeLine{147 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} msgb\_l1len(\textcolor{keyword}{const} \textcolor{keyword}{struct} msgb *msgb)} \DoxyCodeLine{148 \{} \DoxyCodeLine{149 OSMO\_ASSERT(msgb-\/>l1h);} \DoxyCodeLine{150 \textcolor{keywordflow}{return} msgb-\/>tail -\/ (uint8\_t *)msgb\_l1(msgb);} \DoxyCodeLine{151 \}} \DoxyCodeLine{152 } \DoxyCodeLine{160 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} msgb\_l2len(\textcolor{keyword}{const} \textcolor{keyword}{struct} msgb *msgb)} \DoxyCodeLine{161 \{} \DoxyCodeLine{162 OSMO\_ASSERT(msgb-\/>l2h);} \DoxyCodeLine{163 \textcolor{keywordflow}{return} msgb-\/>tail -\/ (uint8\_t *)msgb\_l2(msgb);} \DoxyCodeLine{164 \}} \DoxyCodeLine{165 } \DoxyCodeLine{173 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} msgb\_l3len(\textcolor{keyword}{const} \textcolor{keyword}{struct} msgb *msgb)} \DoxyCodeLine{174 \{} \DoxyCodeLine{175 OSMO\_ASSERT(msgb-\/>l3h);} \DoxyCodeLine{176 \textcolor{keywordflow}{return} msgb-\/>tail -\/ (uint8\_t *)msgb\_l3(msgb);} \DoxyCodeLine{177 \}} \DoxyCodeLine{178 } \DoxyCodeLine{186 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} msgb\_l4len(\textcolor{keyword}{const} \textcolor{keyword}{struct} msgb *msgb)} \DoxyCodeLine{187 \{} \DoxyCodeLine{188 OSMO\_ASSERT(msgb-\/>l4h);} \DoxyCodeLine{189 \textcolor{keywordflow}{return} msgb-\/>tail -\/ (uint8\_t *)msgb\_l4(msgb);} \DoxyCodeLine{190 \}} \DoxyCodeLine{191 } \DoxyCodeLine{199 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} msgb\_headlen(\textcolor{keyword}{const} \textcolor{keyword}{struct} msgb *msgb)} \DoxyCodeLine{200 \{} \DoxyCodeLine{201 \textcolor{keywordflow}{return} msgb-\/>len -\/ msgb-\/>data\_len;} \DoxyCodeLine{202 \}} \DoxyCodeLine{203 } \DoxyCodeLine{211 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{int} msgb\_tailroom(\textcolor{keyword}{const} \textcolor{keyword}{struct} msgb *msgb)} \DoxyCodeLine{212 \{} \DoxyCodeLine{213 \textcolor{keywordflow}{return} (msgb-\/>head + msgb-\/>data\_len) -\/ msgb-\/>tail;} \DoxyCodeLine{214 \}} \DoxyCodeLine{215 } \DoxyCodeLine{223 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{int} msgb\_headroom(\textcolor{keyword}{const} \textcolor{keyword}{struct} msgb *msgb)} \DoxyCodeLine{224 \{} \DoxyCodeLine{225 \textcolor{keywordflow}{return} (msgb-\/>data -\/ msgb-\/>head);} \DoxyCodeLine{226 \}} \DoxyCodeLine{227 } \DoxyCodeLine{240 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *msgb\_put(\textcolor{keyword}{struct} msgb *msgb, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} len)} \DoxyCodeLine{241 \{} \DoxyCodeLine{242 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *tmp = msgb-\/>tail;} \DoxyCodeLine{243 \textcolor{keywordflow}{if} (OSMO\_UNLIKELY(msgb\_tailroom(msgb) < (\textcolor{keywordtype}{int}) len))} \DoxyCodeLine{244 MSGB\_ABORT(msgb, \textcolor{stringliteral}{"{}Not enough tailroom msgb\_put"{}}} \DoxyCodeLine{245 \textcolor{stringliteral}{"{} (allocated \%u, head at \%u, len \%u, tailroom \%u < want tailroom \%u)\(\backslash\)n"{}},} \DoxyCodeLine{246 msgb-\/>data\_len -\/ \textcolor{keyword}{sizeof}(\textcolor{keyword}{struct} msgb),} \DoxyCodeLine{247 msgb-\/>head -\/ msgb-\/>\_data,} \DoxyCodeLine{248 msgb-\/>len,} \DoxyCodeLine{249 msgb\_tailroom(msgb), len);} \DoxyCodeLine{250 msgb-\/>tail += len;} \DoxyCodeLine{251 msgb-\/>len += len;} \DoxyCodeLine{252 \textcolor{keywordflow}{return} tmp;} \DoxyCodeLine{253 \}} \DoxyCodeLine{254 } \DoxyCodeLine{259 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{void} msgb\_put\_u8(\textcolor{keyword}{struct} msgb *msgb, uint8\_t word)} \DoxyCodeLine{260 \{} \DoxyCodeLine{261 uint8\_t *space = msgb\_put(msgb, 1);} \DoxyCodeLine{262 space[0] = word \& 0xFF;} \DoxyCodeLine{263 \}} \DoxyCodeLine{264 } \DoxyCodeLine{269 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{void} msgb\_put\_u16(\textcolor{keyword}{struct} msgb *msgb, uint16\_t word)} \DoxyCodeLine{270 \{} \DoxyCodeLine{271 uint8\_t *space = msgb\_put(msgb, 2);} \DoxyCodeLine{272 osmo\_store16be(word, space);} \DoxyCodeLine{273 \}} \DoxyCodeLine{274 } \DoxyCodeLine{279 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{void} msgb\_put\_u32(\textcolor{keyword}{struct} msgb *msgb, uint32\_t word)} \DoxyCodeLine{280 \{} \DoxyCodeLine{281 uint8\_t *space = msgb\_put(msgb, 4);} \DoxyCodeLine{282 osmo\_store32be(word, space);} \DoxyCodeLine{283 \}} \DoxyCodeLine{284 } \DoxyCodeLine{289 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *msgb\_get(\textcolor{keyword}{struct} msgb *msgb, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} len)} \DoxyCodeLine{290 \{} \DoxyCodeLine{291 \textcolor{keywordflow}{if} (OSMO\_UNLIKELY(msgb\_length(msgb) < len))} \DoxyCodeLine{292 MSGB\_ABORT(msgb, \textcolor{stringliteral}{"{}msgb too small to get \%u (len \%u)\(\backslash\)n"{}},} \DoxyCodeLine{293 len, msgb\_length(msgb));} \DoxyCodeLine{294 msgb-\/>tail -\/= len;} \DoxyCodeLine{295 msgb-\/>len -\/= len;} \DoxyCodeLine{296 \textcolor{keywordflow}{return} msgb-\/>tail;} \DoxyCodeLine{297 \}} \DoxyCodeLine{298 } \DoxyCodeLine{303 \textcolor{keyword}{static} \textcolor{keyword}{inline} uint8\_t msgb\_get\_u8(\textcolor{keyword}{struct} msgb *msgb)} \DoxyCodeLine{304 \{} \DoxyCodeLine{305 uint8\_t *space = msgb\_get(msgb, 1);} \DoxyCodeLine{306 \textcolor{keywordflow}{return} space[0];} \DoxyCodeLine{307 \}} \DoxyCodeLine{308 } \DoxyCodeLine{313 \textcolor{keyword}{static} \textcolor{keyword}{inline} uint16\_t msgb\_get\_u16(\textcolor{keyword}{struct} msgb *msgb)} \DoxyCodeLine{314 \{} \DoxyCodeLine{315 uint8\_t *space = msgb\_get(msgb, 2);} \DoxyCodeLine{316 \textcolor{keywordflow}{return} osmo\_load16be(space);} \DoxyCodeLine{317 \}} \DoxyCodeLine{318 } \DoxyCodeLine{323 \textcolor{keyword}{static} \textcolor{keyword}{inline} uint32\_t msgb\_get\_u32(\textcolor{keyword}{struct} msgb *msgb)} \DoxyCodeLine{324 \{} \DoxyCodeLine{325 uint8\_t *space = msgb\_get(msgb, 4);} \DoxyCodeLine{326 \textcolor{keywordflow}{return} osmo\_load32be(space);} \DoxyCodeLine{327 \}} \DoxyCodeLine{328 } \DoxyCodeLine{341 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *msgb\_push(\textcolor{keyword}{struct} msgb *msgb, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} len)} \DoxyCodeLine{342 \{} \DoxyCodeLine{343 \textcolor{keywordflow}{if} (OSMO\_UNLIKELY(msgb\_headroom(msgb) < (\textcolor{keywordtype}{int}) len))} \DoxyCodeLine{344 MSGB\_ABORT(msgb, \textcolor{stringliteral}{"{}Not enough headroom msgb\_push"{}}} \DoxyCodeLine{345 \textcolor{stringliteral}{"{} (allocated \%u, head at \%u < want headroom \%u, len \%u, tailroom \%u)\(\backslash\)n"{}},} \DoxyCodeLine{346 msgb-\/>data\_len -\/ \textcolor{keyword}{sizeof}(\textcolor{keyword}{struct} msgb),} \DoxyCodeLine{347 msgb-\/>head -\/ msgb-\/>\_data,} \DoxyCodeLine{348 len,} \DoxyCodeLine{349 msgb-\/>len,} \DoxyCodeLine{350 msgb\_tailroom(msgb));} \DoxyCodeLine{351 msgb-\/>data -\/= len;} \DoxyCodeLine{352 msgb-\/>len += len;} \DoxyCodeLine{353 \textcolor{keywordflow}{return} msgb-\/>data;} \DoxyCodeLine{354 \}} \DoxyCodeLine{355 } \DoxyCodeLine{360 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{void} msgb\_push\_u8(\textcolor{keyword}{struct} msgb *msg, uint8\_t word)} \DoxyCodeLine{361 \{} \DoxyCodeLine{362 uint8\_t *space = msgb\_push(msg, 1);} \DoxyCodeLine{363 space[0] = word;} \DoxyCodeLine{364 \}} \DoxyCodeLine{365 } \DoxyCodeLine{370 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{void} msgb\_push\_u16(\textcolor{keyword}{struct} msgb *msg, uint16\_t word)} \DoxyCodeLine{371 \{} \DoxyCodeLine{372 uint16\_t *space = (uint16\_t *) msgb\_push(msg, 2);} \DoxyCodeLine{373 osmo\_store16be(word, space);} \DoxyCodeLine{374 \}} \DoxyCodeLine{375 } \DoxyCodeLine{380 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{void} msgb\_push\_u32(\textcolor{keyword}{struct} msgb *msg, uint32\_t word)} \DoxyCodeLine{381 \{} \DoxyCodeLine{382 uint32\_t *space = (uint32\_t *) msgb\_push(msg, 4);} \DoxyCodeLine{383 osmo\_store32be(word, space);} \DoxyCodeLine{384 \}} \DoxyCodeLine{385 } \DoxyCodeLine{386 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *msgb\_push\_tl(\textcolor{keyword}{struct} msgb *msgb, uint8\_t tag)} \DoxyCodeLine{387 \{} \DoxyCodeLine{388 uint8\_t *data = msgb\_push(msgb, 2);} \DoxyCodeLine{389 } \DoxyCodeLine{390 data[0] = tag;} \DoxyCodeLine{391 data[1] = msgb-\/>len -\/ 2;} \DoxyCodeLine{392 \textcolor{keywordflow}{return} data;} \DoxyCodeLine{393 \}} \DoxyCodeLine{394 } \DoxyCodeLine{404 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *msgb\_pull(\textcolor{keyword}{struct} msgb *msgb, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} len)} \DoxyCodeLine{405 \{} \DoxyCodeLine{406 \textcolor{keywordflow}{if} (OSMO\_UNLIKELY(msgb\_length(msgb) < len))} \DoxyCodeLine{407 MSGB\_ABORT(msgb, \textcolor{stringliteral}{"{}msgb too small to pull \%u (len \%u)\(\backslash\)n"{}},} \DoxyCodeLine{408 len, msgb\_length(msgb));} \DoxyCodeLine{409 msgb-\/>len -\/= len;} \DoxyCodeLine{410 \textcolor{keywordflow}{return} msgb-\/>data += len;} \DoxyCodeLine{411 \}} \DoxyCodeLine{412 } \DoxyCodeLine{421 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *msgb\_pull\_to\_l3(\textcolor{keyword}{struct} msgb *msg)} \DoxyCodeLine{422 \{} \DoxyCodeLine{423 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *ret = msgb\_pull(msg, msg-\/>l3h -\/ msg-\/>data);} \DoxyCodeLine{424 msg-\/>l1h = msg-\/>l2h = NULL;} \DoxyCodeLine{425 \textcolor{keywordflow}{return} ret;} \DoxyCodeLine{426 \}} \DoxyCodeLine{427 } \DoxyCodeLine{436 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *msgb\_pull\_to\_l2(\textcolor{keyword}{struct} msgb *msg)} \DoxyCodeLine{437 \{} \DoxyCodeLine{438 \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *ret = msgb\_pull(msg, msg-\/>l2h -\/ msg-\/>data);} \DoxyCodeLine{439 msg-\/>l1h = NULL;} \DoxyCodeLine{440 \textcolor{keywordflow}{return} ret;} \DoxyCodeLine{441 \}} \DoxyCodeLine{442 } \DoxyCodeLine{447 \textcolor{keyword}{static} \textcolor{keyword}{inline} uint8\_t msgb\_pull\_u8(\textcolor{keyword}{struct} msgb *msgb)} \DoxyCodeLine{448 \{} \DoxyCodeLine{449 uint8\_t *space = msgb\_pull(msgb, 1) -\/ 1;} \DoxyCodeLine{450 \textcolor{keywordflow}{return} space[0];} \DoxyCodeLine{451 \}} \DoxyCodeLine{452 } \DoxyCodeLine{457 \textcolor{keyword}{static} \textcolor{keyword}{inline} uint16\_t msgb\_pull\_u16(\textcolor{keyword}{struct} msgb *msgb)} \DoxyCodeLine{458 \{} \DoxyCodeLine{459 uint8\_t *space = msgb\_pull(msgb, 2) -\/ 2;} \DoxyCodeLine{460 \textcolor{keywordflow}{return} osmo\_load16be(space);} \DoxyCodeLine{461 \}} \DoxyCodeLine{462 } \DoxyCodeLine{467 \textcolor{keyword}{static} \textcolor{keyword}{inline} uint32\_t msgb\_pull\_u32(\textcolor{keyword}{struct} msgb *msgb)} \DoxyCodeLine{468 \{} \DoxyCodeLine{469 uint8\_t *space = msgb\_pull(msgb, 4) -\/ 4;} \DoxyCodeLine{470 \textcolor{keywordflow}{return} osmo\_load32be(space);} \DoxyCodeLine{471 \}} \DoxyCodeLine{472 } \DoxyCodeLine{484 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{void} msgb\_reserve(\textcolor{keyword}{struct} msgb *msg, \textcolor{keywordtype}{int} len)} \DoxyCodeLine{485 \{} \DoxyCodeLine{486 msg-\/>data += len;} \DoxyCodeLine{487 msg-\/>tail += len;} \DoxyCodeLine{488 \}} \DoxyCodeLine{489 } \DoxyCodeLine{495 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{int} msgb\_trim(\textcolor{keyword}{struct} msgb *msg, \textcolor{keywordtype}{int} len)} \DoxyCodeLine{496 \{} \DoxyCodeLine{497 \textcolor{keywordflow}{if} (OSMO\_UNLIKELY(len < 0))} \DoxyCodeLine{498 MSGB\_ABORT(msg, \textcolor{stringliteral}{"{}Negative length is not allowed\(\backslash\)n"{}});} \DoxyCodeLine{499 \textcolor{keywordflow}{if} (OSMO\_UNLIKELY(len > msg-\/>data\_len))} \DoxyCodeLine{500 \textcolor{keywordflow}{return} -\/1;} \DoxyCodeLine{501 } \DoxyCodeLine{502 msg-\/>len = len;} \DoxyCodeLine{503 msg-\/>tail = msg-\/>data + len;} \DoxyCodeLine{504 } \DoxyCodeLine{505 \textcolor{keywordflow}{return} 0;} \DoxyCodeLine{506 \}} \DoxyCodeLine{507 } \DoxyCodeLine{513 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{int} msgb\_l3trim(\textcolor{keyword}{struct} msgb *msg, \textcolor{keywordtype}{int} l3len)} \DoxyCodeLine{514 \{} \DoxyCodeLine{515 \textcolor{keywordflow}{return} msgb\_trim(msg, (msg-\/>l3h -\/ msg-\/>data) + l3len);} \DoxyCodeLine{516 \}} \DoxyCodeLine{517 } \DoxyCodeLine{529 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keyword}{struct }msgb *msgb\_alloc\_headroom\_c(\textcolor{keyword}{const} \textcolor{keywordtype}{void} *ctx, uint16\_t size, uint16\_t headroom,} \DoxyCodeLine{530 \textcolor{keyword}{const} \textcolor{keywordtype}{char} *name)} \DoxyCodeLine{531 \{} \DoxyCodeLine{532 OSMO\_ASSERT(size >= headroom);} \DoxyCodeLine{533 } \DoxyCodeLine{534 \textcolor{keyword}{struct }msgb *msg = msgb\_alloc\_c(ctx, size, name);} \DoxyCodeLine{535 \textcolor{keywordflow}{if} (OSMO\_LIKELY(msg))} \DoxyCodeLine{536 msgb\_reserve(msg, headroom);} \DoxyCodeLine{537 \textcolor{keywordflow}{return} msg;} \DoxyCodeLine{538 \}} \DoxyCodeLine{539 } \DoxyCodeLine{540 } \DoxyCodeLine{551 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keyword}{struct }msgb *msgb\_alloc\_headroom(uint16\_t size, uint16\_t headroom,} \DoxyCodeLine{552 \textcolor{keyword}{const} \textcolor{keywordtype}{char} *name)} \DoxyCodeLine{553 \{} \DoxyCodeLine{554 OSMO\_ASSERT(size >= headroom);} \DoxyCodeLine{555 } \DoxyCodeLine{556 \textcolor{keyword}{struct }msgb *msg = msgb\_alloc(size, name);} \DoxyCodeLine{557 \textcolor{keywordflow}{if} (OSMO\_LIKELY(msg))} \DoxyCodeLine{558 msgb\_reserve(msg, headroom);} \DoxyCodeLine{559 \textcolor{keywordflow}{return} msg;} \DoxyCodeLine{560 \}} \DoxyCodeLine{561 } \DoxyCodeLine{566 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{int} msgb\_test\_invariant(\textcolor{keyword}{const} \textcolor{keyword}{struct} msgb *msg)} \DoxyCodeLine{567 \{} \DoxyCodeLine{568 \textcolor{keyword}{const} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *lbound;} \DoxyCodeLine{569 \textcolor{keywordflow}{if} (!msg || !msg-\/>data || !msg-\/>tail ||} \DoxyCodeLine{570 (msg-\/>data + msg-\/>len != msg-\/>tail) ||} \DoxyCodeLine{571 (msg-\/>data < msg-\/>head) ||} \DoxyCodeLine{572 (msg-\/>tail > msg-\/>head + msg-\/>data\_len))} \DoxyCodeLine{573 \textcolor{keywordflow}{return} 0;} \DoxyCodeLine{574 } \DoxyCodeLine{575 lbound = msg-\/>head;} \DoxyCodeLine{576 } \DoxyCodeLine{577 \textcolor{keywordflow}{if} (msg-\/>l1h) \{} \DoxyCodeLine{578 \textcolor{keywordflow}{if} (msg-\/>l1h < lbound)} \DoxyCodeLine{579 \textcolor{keywordflow}{return} 0;} \DoxyCodeLine{580 lbound = msg-\/>l1h;} \DoxyCodeLine{581 \}} \DoxyCodeLine{582 \textcolor{keywordflow}{if} (msg-\/>l2h) \{} \DoxyCodeLine{583 \textcolor{keywordflow}{if} (msg-\/>l2h < lbound)} \DoxyCodeLine{584 \textcolor{keywordflow}{return} 0;} \DoxyCodeLine{585 lbound = msg-\/>l2h;} \DoxyCodeLine{586 \}} \DoxyCodeLine{587 \textcolor{keywordflow}{if} (msg-\/>l3h) \{} \DoxyCodeLine{588 \textcolor{keywordflow}{if} (msg-\/>l3h < lbound)} \DoxyCodeLine{589 \textcolor{keywordflow}{return} 0;} \DoxyCodeLine{590 lbound = msg-\/>l3h;} \DoxyCodeLine{591 \}} \DoxyCodeLine{592 \textcolor{keywordflow}{if} (msg-\/>l4h) \{} \DoxyCodeLine{593 \textcolor{keywordflow}{if} (msg-\/>l4h < lbound)} \DoxyCodeLine{594 \textcolor{keywordflow}{return} 0;} \DoxyCodeLine{595 lbound = msg-\/>l4h;} \DoxyCodeLine{596 \}} \DoxyCodeLine{597 } \DoxyCodeLine{598 \textcolor{keywordflow}{return} lbound <= msg-\/>head + msg-\/>data\_len;} \DoxyCodeLine{599 \}} \DoxyCodeLine{600 } \DoxyCodeLine{601 } \DoxyCodeLine{602 \textcolor{comment}{/* msgb data comparison helpers */}} \DoxyCodeLine{603 } \DoxyCodeLine{610 \textcolor{preprocessor}{\#define msgb\_eq\_data(msg, data, len) \(\backslash\)}} \DoxyCodeLine{611 \textcolor{preprocessor}{ \_msgb\_eq(\_\_FILE\_\_, \_\_LINE\_\_, \_\_func\_\_, 0, msg, data, len, false)}} \DoxyCodeLine{612 } \DoxyCodeLine{619 \textcolor{preprocessor}{\#define msgb\_eq\_l1\_data(msg, data, len) \(\backslash\)}} \DoxyCodeLine{620 \textcolor{preprocessor}{ \_msgb\_eq(\_\_FILE\_\_, \_\_LINE\_\_, \_\_func\_\_, 1, msg, data, len, false)}} \DoxyCodeLine{621 } \DoxyCodeLine{628 \textcolor{preprocessor}{\#define msgb\_eq\_l2\_data(msg, data, len) \(\backslash\)}} \DoxyCodeLine{629 \textcolor{preprocessor}{ \_msgb\_eq(\_\_FILE\_\_, \_\_LINE\_\_, \_\_func\_\_, 2, msg, data, len, false)}} \DoxyCodeLine{630 } \DoxyCodeLine{637 \textcolor{preprocessor}{\#define msgb\_eq\_l3\_data(msg, data, len) \(\backslash\)}} \DoxyCodeLine{638 \textcolor{preprocessor}{ \_msgb\_eq(\_\_FILE\_\_, \_\_LINE\_\_, \_\_func\_\_, 3, msg, data, len, false)}} \DoxyCodeLine{639 } \DoxyCodeLine{646 \textcolor{preprocessor}{\#define msgb\_eq\_l4\_data(msg, data, len) \(\backslash\)}} \DoxyCodeLine{647 \textcolor{preprocessor}{ \_msgb\_eq(\_\_FILE\_\_, \_\_LINE\_\_, \_\_func\_\_, 4, msg, data, len, false)}} \DoxyCodeLine{648 } \DoxyCodeLine{649 } \DoxyCodeLine{650 \textcolor{comment}{/* msgb test/debug helpers */}} \DoxyCodeLine{651 } \DoxyCodeLine{658 \textcolor{preprocessor}{\#define msgb\_eq\_data\_print(msg, data, len) \(\backslash\)}} \DoxyCodeLine{659 \textcolor{preprocessor}{ \_msgb\_eq(\_\_FILE\_\_, \_\_LINE\_\_, \_\_func\_\_, 0, msg, data, len, true)}} \DoxyCodeLine{660 } \DoxyCodeLine{667 \textcolor{preprocessor}{\#define msgb\_eq\_l1\_data\_print(msg, data, len) \(\backslash\)}} \DoxyCodeLine{668 \textcolor{preprocessor}{ \_msgb\_eq(\_\_FILE\_\_, \_\_LINE\_\_, \_\_func\_\_, 1, msg, data, len, true)}} \DoxyCodeLine{669 } \DoxyCodeLine{676 \textcolor{preprocessor}{\#define msgb\_eq\_l2\_data\_print(msg, data, len) \(\backslash\)}} \DoxyCodeLine{677 \textcolor{preprocessor}{ \_msgb\_eq(\_\_FILE\_\_, \_\_LINE\_\_, \_\_func\_\_, 2, msg, data, len, true)}} \DoxyCodeLine{678 } \DoxyCodeLine{685 \textcolor{preprocessor}{\#define msgb\_eq\_l3\_data\_print(msg, data, len) \(\backslash\)}} \DoxyCodeLine{686 \textcolor{preprocessor}{ \_msgb\_eq(\_\_FILE\_\_, \_\_LINE\_\_, \_\_func\_\_, 3, msg, data, len, true)}} \DoxyCodeLine{687 } \DoxyCodeLine{688 } \DoxyCodeLine{695 \textcolor{preprocessor}{\#define msgb\_eq\_l4\_data\_print(msg, data, len) \(\backslash\)}} \DoxyCodeLine{696 \textcolor{preprocessor}{ \_msgb\_eq(\_\_FILE\_\_, \_\_LINE\_\_, \_\_func\_\_, 4, msg, data, len, true)}} \DoxyCodeLine{697 } \DoxyCodeLine{698 \textcolor{keywordtype}{bool} \_msgb\_eq(\textcolor{keyword}{const} \textcolor{keywordtype}{char} *file, \textcolor{keywordtype}{size\_t} line, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *func, uint8\_t level,} \DoxyCodeLine{699 \textcolor{keyword}{const} \textcolor{keyword}{struct} msgb *msg, \textcolor{keyword}{const} uint8\_t *data, \textcolor{keywordtype}{size\_t} len, \textcolor{keywordtype}{bool} print);} \DoxyCodeLine{700 } \DoxyCodeLine{701 } \DoxyCodeLine{702 \textcolor{comment}{/* msgb data comparison */}} \DoxyCodeLine{703 } \DoxyCodeLine{709 \textcolor{preprocessor}{\#define msgb\_eq(msg1, msg2) msgb\_eq\_data(msg1, msgb\_data(msg2), msgb\_length(msg2))}} \DoxyCodeLine{710 } \DoxyCodeLine{716 \textcolor{preprocessor}{\#define msgb\_eq\_l1(msg1, msg2) msgb\_eq\_l1\_data(msg1, msgb\_l1(msg2), msgb\_l1len(msg2))}} \DoxyCodeLine{717 } \DoxyCodeLine{723 \textcolor{preprocessor}{\#define msgb\_eq\_l2(msg1, msg2) msgb\_eq\_l2\_data(msg1, msgb\_l2(msg2), msgb\_l2len(msg2))}} \DoxyCodeLine{724 } \DoxyCodeLine{730 \textcolor{preprocessor}{\#define msgb\_eq\_l3(msg1, msg2) msgb\_eq\_l3\_data(msg1, msgb\_l3(msg2), msgb\_l3len(msg2))}} \DoxyCodeLine{731 } \DoxyCodeLine{737 \textcolor{preprocessor}{\#define msgb\_eq\_l4(msg1, msg2) msgb\_eq\_l4\_data(msg1, msgb\_l4(msg2), msgb\_l4len(msg2))}} \DoxyCodeLine{738 } \DoxyCodeLine{739 } \DoxyCodeLine{740 \textcolor{comment}{/* non inline functions to ease binding */}} \DoxyCodeLine{741 } \DoxyCodeLine{742 uint8\_t *msgb\_data(\textcolor{keyword}{const} \textcolor{keyword}{struct} msgb *msg);} \DoxyCodeLine{743 } \DoxyCodeLine{744 \textcolor{keywordtype}{void} *msgb\_talloc\_ctx\_init(\textcolor{keywordtype}{void} *root\_ctx, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} pool\_size);} \DoxyCodeLine{745 \textcolor{keywordtype}{void} msgb\_set\_talloc\_ctx(\textcolor{keywordtype}{void} *ctx) OSMO\_DEPRECATED(\textcolor{stringliteral}{"{}Use msgb\_talloc\_ctx\_init() instead"{}});} \DoxyCodeLine{746 \textcolor{keywordtype}{int} msgb\_printf(\textcolor{keyword}{struct} msgb *msgb, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *format, ...);} \DoxyCodeLine{747 } \DoxyCodeLine{748 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keyword}{const} \textcolor{keywordtype}{char} *msgb\_hexdump\_l1(\textcolor{keyword}{const} \textcolor{keyword}{struct} msgb *msg)} \DoxyCodeLine{749 \{} \DoxyCodeLine{750 \textcolor{keywordflow}{if} (!msgb\_l1(msg) || !(msgb\_l1len(msg)))} \DoxyCodeLine{751 \textcolor{keywordflow}{return} \textcolor{stringliteral}{"{}[]"{}};} \DoxyCodeLine{752 \textcolor{keywordflow}{return} osmo\_hexdump((\textcolor{keyword}{const} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *) msgb\_l1(msg), msgb\_l1len(msg));} \DoxyCodeLine{753 \}} \DoxyCodeLine{754 } \DoxyCodeLine{755 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keyword}{const} \textcolor{keywordtype}{char} *msgb\_hexdump\_l2(\textcolor{keyword}{const} \textcolor{keyword}{struct} msgb *msg)} \DoxyCodeLine{756 \{} \DoxyCodeLine{757 \textcolor{keywordflow}{if} (!msgb\_l2(msg) || !(msgb\_l2len(msg)))} \DoxyCodeLine{758 \textcolor{keywordflow}{return} \textcolor{stringliteral}{"{}[]"{}};} \DoxyCodeLine{759 \textcolor{keywordflow}{return} osmo\_hexdump((\textcolor{keyword}{const} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *) msgb\_l2(msg), msgb\_l2len(msg));} \DoxyCodeLine{760 \}} \DoxyCodeLine{761 } \DoxyCodeLine{762 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keyword}{const} \textcolor{keywordtype}{char} *msgb\_hexdump\_l3(\textcolor{keyword}{const} \textcolor{keyword}{struct} msgb *msg)} \DoxyCodeLine{763 \{} \DoxyCodeLine{764 \textcolor{keywordflow}{if} (!msgb\_l3(msg) || !(msgb\_l3len(msg)))} \DoxyCodeLine{765 \textcolor{keywordflow}{return} \textcolor{stringliteral}{"{}[]"{}};} \DoxyCodeLine{766 \textcolor{keywordflow}{return} osmo\_hexdump((\textcolor{keyword}{const} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char}*) msgb\_l3(msg), msgb\_l3len(msg));} \DoxyCodeLine{767 \}} \DoxyCodeLine{768 } \DoxyCodeLine{769 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keyword}{const} \textcolor{keywordtype}{char} *msgb\_hexdump\_l4(\textcolor{keyword}{const} \textcolor{keyword}{struct} msgb *msg)} \DoxyCodeLine{770 \{} \DoxyCodeLine{771 \textcolor{keywordflow}{if} (!msgb\_l4(msg) || !(msgb\_l4len(msg)))} \DoxyCodeLine{772 \textcolor{keywordflow}{return} \textcolor{stringliteral}{"{}[]"{}};} \DoxyCodeLine{773 \textcolor{keywordflow}{return} osmo\_hexdump((\textcolor{keyword}{const} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char}*) msgb\_l4(msg), msgb\_l4len(msg));} \DoxyCodeLine{774 \}} \DoxyCodeLine{775 } \end{DoxyCode}