# encvalue

This built-in function is used to encode a value argument into a bitstring.

- The function returns bitstring.
- If template is used as the first parameter in encvalue(), it has to be resolved to a specific value.
- Type of the first argument has to have an encoding method explicitly set with its attributes.
- The second argument is currently ignored.
- The third argument selects the encoding method to use, if the type has multiple encoding methods set.

Related keywords:

- send
- encode
- encvalue_unichar
- decvalue
- decvalue_unichar

### encvalue( value_part [, encoding_info [, dynamic_encoding]] ) return bitstring;

Example 1:

type float MyFloat with { encode "RAW" }

var MyFloat f := 1.1;

var bitstring bs := encvalue(f);

This will store the "RAW" encoded form of the float value 1.1 into the bitstring variable bs.

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");

This will store the "JSON" encoded form of the record value { num := 3, str := "abc" } into the bitstring variable bs.

BNF definition of encvalue