op_vvec_to_value()
Abstract
Convert a bit representation of a value into a C data type value.
Syntax
op_vvec_to_value (source, byte_order, bit_format, value_type, value_ptr)
| Argument | Type | Description |
|---|---|---|
source |
Vvec_Vector |
value vector containing the bit representation of a value |
byte_order |
Vvec_ByteOrder |
byte order of the source vector [This is a constant that represents the appropriate byte ordering scheme in use by the model (see Table 94 “Value Vector Byte Ordering Symbolic Constants“ on page 33).] |
bit_format |
Vvec_BitFormat |
bit format of the source vector [This is a constant that represents the appropriate bit format in use by the model (see Table 93 “Value Vector Bit Format Symbolic Constants“ on page 33).] |
value_type |
Vvec_NativeType |
data type of the value being decoded. Can be any of the standard C data types. [This is a constant that represents the appropriate type for value (see Table 96 “Value Vector Native Type Symbolic Constants“ on page 34).] |
value_ptr |
void* |
pointer to a variable that will hold the decoded value [This variable stores the value represented by source.] |
Return Type
int
Completion code indicating whether the operation completed successfully.
See Table 95 “Value Vector Completion Code Symbolic Constants“ on page 33 for a list of the possible return values.
Example
/* Generate an ATM cell header from a vector. */
atm_cell_pkptr = op_pk_create_fmt ("ams_atm_cell");
/* first four bits are the GFC. */
temp_vec = op_vvec_remove (output_vector, 0, 4);
op_vvec_to_value (temp_vec, OPC_VVEC_BYTE_ORDER_LITTLE_ENDIAN,
OPC_VVEC_BITFORMAT_BINARY, OPC_VVEC_NATIVE_INT, &i);
op_vvec_destroy (temp_vec);
op_pk_nfd_set (atm_cell_pkptr, "GFC", i);
/* Next 8 bits contain the VPI. */
temp_vec = op_vvec_remove (output_vector, 0, 8);
op_vvec_to_value (temp_vec, OPC_VVEC_BYTE_ORDER_LITTLE_ENDIAN,
OPC_VVEC_BITFORMAT_BINARY, OPC_VVEC_NATIVE_INT, &i);
op_vvec_destroy (temp_vec);
op_pk_nfd_set (atm_cell_pkptr, "VPI", i);
/* Next 16 bits contain the VCI. */
temp_vec = op_vvec_remove (output_vector, 0, 16);
op_vvec_to_value (temp_vec, OPC_VVEC_BYTE_ORDER_LITTLE_ENDIAN,
OPC_VVEC_BITFORMAT_BINARY, OPC_VVEC_NATIVE_INT, &i);
op_vvec_destroy (temp_vec);
Details
This KP converts a bit representation of a value into that value. It then places that value into a variable of the correct type.
For values of type boolean or bit, this function returns one of the following constants:
- OpC_Bool_F and OpC_Bool_T for boolean
- OpC_Bit_0 and OpC_Bit_1 for bit
Purpose
Provide a mechanism to decode a value given its bit representation and information about the methods used to convert the value into a bit representation. The procedure is flexible enough to handle all standard data types while also accommodating standard bit formats and byte ordering conventions.
Errors
- Recoverable Error: Value vector is invalid.
- Recoverable Error: Source and target types in requested conversion are not compatible.
- Recoverable Error: Source vector size (
<size>) is invalid for conversion. - Recoverable Error: General failure in value vector conversion.
- Recoverable Error: Insufficient memory to perform conversion.
Reference
- Use the KP op_vvec_from_value() to convert a value to a bit representation of that value
- Use the KP op_vvec_type_get() to determine the data type of a vector
- Use the KP op_vvec_value_get() to get specific values from within a value vector