# setencode

The self.setencode operation sets the default encoding method for encoding and decoding operations on values of a specified type.

- The type (first) argument indicates which type's default encoding method is set by the operation. This type must have at least two encoding methods set with its attributes.
- The encoding (second) argument indicates which encoding method is to be set as default. This must match one of the encoding methods set for the type.
- This operation affects all encvalue, decvalue, encvalue_unichar and decvalue_unichar operations with no dynamic encoding argument, all decmatch templates, and all value and parameter redirects with the @decoded modifier within the scope of the current component (self).

Related keywords:

- encvalue
- encvalue_unichar
- decvalue
- decvalue_unichar

### self.setencode (type, encoding);

Example:

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

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

self.setencode(MyRecord, "XML");

var bitstring bs1 := encvalue(r); // uses the "XML" encoding method set by the 'setencode' operation

var bitstring bs2 := encvalue(r, "", "JSON"); // ignores the 'setencode' operation and uses the "JSON" encoding method set by the dynamic encoding argument

BNF definition of setencode