# decvalue

This built-in function decodes a value from a bitstring and cuts the consumed part from the bitstring.

- The function return type is integer holding the error code: 0 - decoding was successful, 1 - unspecified cause of decoding failure, 2 - decoding failed because the bitstring did not contain enough bits.
- Decoded value returned through the second (out) argument.
- Type of the second argument has to have an encoding method explicitly set with its atributes.
- The third argument is currently ignored.
- The fourth argument selects the encoding method to use, if the type has multiple encoding methods set.

Related keywords:

- encode
- encvalue
- encvalue_unichar
- decvalue_unichar

### decvalue( inout bitstring_value, out decoded_value [, in encoding_info [, in dynamic_encoding]] ) return integer;

Example 1:

type float MyFloat with { encode "RAW" }

var MyFloat f := 1.1;

var bitstring bs := encvalue(f);

var integer i := decvalue(bs, f);

Example 2:

type record MyRecord {
integer num,
charstring str
}
with {
encode "XML";
encode "JSON";
}

var MyRecord r := { num := 3, str := "abc" };

var bitstring bs := encvalue(r, "", "JSON");

var integer i := decvalue(bs, r, "", "JSON");

BNF definition of decvalue