op_vvec_from_value()
Abstract
Convert a given value to a bit representation of that value, and then place the bit representation in a new value vector.
Syntax
op_vvec_from_value (target, byte_order, bit_format, target_size, value_type, value)
| Argument | Type | Description |
|---|---|---|
target |
Vvec_Vector* |
pointer to a value vector that will hold a bit representation of value |
byte_order |
Vvec_ByteOrder |
byte order to use when converting value to bit 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 to use when converting value to bit 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).] |
target_size |
int |
size of the new vector in bits [This value determines which bit formats may be used in the conversion of the value to a bit vector.] |
value_type |
Vvec_NativeType |
format of the value to be converted to a bit vector [This is a constant that represents the appropriate type for value (see Table 96 “Value Vector Native Type Symbolic Constants“ on page 34).] |
value |
Vartype |
value to be converted to a bit vector |
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 complete list of the possible return values.
Example
/* Convert a packet to a value vector by iterating over its fields. */
max = op_pk_fd_max_index (source);
for (i = 0; i <= max; i++)
{
switch (op_pk_fd_type (pkptr, i))
{
Vvec_Vector temp_vec;
case OPC_FIELD_TYPE_INTEGER:
op_pk_fd_get (pkptr, i, &pk_int);
if (op_pk_fd_size (pkptr , i))
{
op_vvec_from_value (&temp_vec, OPC_VVEC_BYTE_ORDER_LITTLE_ENDIAN,
OPC_VVEC_BITFORMAT_BINARY, op_pk_fd_size (pkptr, i),
OPC_VVEC_NATIVE_INT, pk_int);
}
break;
case OPC_FIELD_TYPE_DOUBLE:
op_pk_fd_get (pkptr, i, &pk_dbl);
if (op_pk_fd_size (pkptr , i))
{
op_vvec_from_value (&temp_vec, OPC_VVEC_BYTE_ORDER_LITTLE_ENDIAN,
OPC_VVEC_BITFORMAT_FP, op_pk_fd_size (pkptr, i),
OPC_VVEC_NATIVE_DOUBLE, pk_dbl);
}
break;
}
}
Details
This KP converts a single value to the bit representation of that value and then places it into a new target value vector.
For value arguments of type boolean or bit, do not assign the literal values 0 and 1. Instead, use the corresponding constants:
- OpC_BoolL_F and OpC_Bool_T for boolean
- OpC_Bit_0 and OpC_Bit_1 for bit
Typically, op_vvec_from_value() will be used to prepare data for placement on esys interfaces in an external system.
The value of target size must be consistent with the byte ordering and bit format specifications. If the Simulation Kernel cannot meet this request because of memory limitations or other causes, a target size error results.
Purpose
ProvideS a mechanism to create a value vector containing the bit representation of a given value. The procedure is flexible enough to handle all standard data types while also accommodating standard bit formats and byte ordering conventions.
Errors
- Recoverable Error: Source and target types in requested conversion are not compatible.
- Recoverable Error: Conversion target size (
<size>) is invalid. - Recoverable Error: General failure in value vector conversion.
- Recoverable Error: Insufficient memory to perform conversion.
Reference
- Use the KP op_vvec_to_value() to convert a bit representation to a value
- Use the KP op_vvec_type_get() to find out the type of a given value vector
- Use the KP op_vvec_value_get() to get specific values from within a value vector