Osmocom_Types: Add bool2bit() and bool2bit_templ()

Those can be very handy to convert boolean values and templates
to the BIT1 type that is used a lot in Ericsson code.

Change-Id: I137595edabd2bbf5e6cf8bf9bdb73b3589c94c64
This commit is contained in:
Harald Welte 2018-02-15 20:40:36 +01:00
parent 853c0ada1d
commit c7adaa722b
1 changed files with 29 additions and 0 deletions

View File

@ -1,4 +1,7 @@
module Osmocom_Types {
import from General_Types all;
type integer uint8_t (0..255) with { variant "unsigned 8 bit" };
type integer uint16_t (0..65535) with { variant "unsigned 16 bit" };
type integer uint24_t (0..16777215) with { variant "unsigned 24 bit" };
@ -66,4 +69,30 @@ module Osmocom_Types {
T.timeout;
}
function bool2bit(boolean inp) return BIT1 {
if (inp) {
return '1'B;
} else {
return '0'B;
}
}
function bool2bit_tmpl(template boolean inp) return template BIT1 {
if (istemplatekind(inp, "omit")) {
return omit;
} else if (istemplatekind(inp, "*")) {
return *;
} else if (istemplatekind(inp, "?")) {
} else {
if (valueof(inp)) {
return '1'B;
} else {
return '0'B;
}
}
setverdict(fail, "Unsupported template");
self.stop;
}
} with { encode "RAW"; variant "FIELDORDER(msb)" }