Example #3 |
DEVELOPER |
This topic contains further example that demonstrates the using Task/Function parameters and P4API parameter passing:
Example #3
Suppose you have a PROIV Function that takes three parameters:
Name |
Type |
Size |
Array/Number of Elements |
Purpose |
FParam1 |
Wide |
10 |
Scalar, not array |
Special Code, holds up to 10 wide characters (20 bytes) |
FParam2 |
Wide |
50 |
2 elements |
Two descriptions, each holds up to 50 wide characters (100 bytes) |
FParam3 |
Long |
20 |
2 elements |
Two balances |
Assume you define a Task with that function as the only member function. Corresponding Task parameters that match those function parameters could be:
Name |
Type |
Size |
Array |
T_Param1 |
w |
10 |
<blank> |
T_Param2 |
w |
50 |
2 |
T_Param3 |
l |
20 |
2 |
If you want to invoke that task using P4API calls, you might send the following strings as the sParams parameter in a p4ExecTask() call:
Example 3A
Delimiter separated list stream format to invoke task with parameters using a comma as the delimiter (sParamFormat set to 'D,' in the p4ExecTask() call):
T_Param1=,T_Param2()=(Main Acct,Swiss Acct),T_Param3()=(746.34,192382.23)
They would be a set of consecutive bytes set to whatever byte values correspond to the supplied wide alpha literal value. For the purpose of these examples, the string will be taken as six bytes long (which may be only three wide characters), with a value of "?$?$?$"
Main Acct and Swiss Acct are two sets of consecutive bytes (separated by a comma) set to whatever byte values correspond to the wide alpha values for the two strings. For the purpose of these examples, the strings will be taken as 18 and 20 bytes long respectively, with a value of "M!a!i!n! !A!c!c!t!" and "S!w!i!s!s! !A!c!c!t!"
Example 3B
Length-Prefixed Stream Format using same data in short form:
<0x00><0x08>T_Param1<0x00><0x06>?$?$?$<0x00><0x0a>T_Param2()
<0x00><0x02><0x00><0x2c><0x00><0x12>M!a!i!n! !A!c!c!t!
<0x00><0x14>S!w!i!s!s! !A!c!c!t!
<0x00><0x0a>T_Param3()<0x00><0x02><0x00><0x15><0x00><0x06>746.34
<0x00><0x09>192382.23
Explanation
Section |
Reason |
<0x00><0x08>T_Param1 |
The number of bytes in the literal $T_Param1$is eight. Represented as two hex bytes with that value. Followed by the name of the Task parameter defined in the Task definition. |
<0x00><0x06>?$?$?$ |
The number of bytes in the wide character value $?$?$?$$ is six. Represented as two hex bytes with that value. Followed by the value of the T_Param1 parameter. |
<0x00><0x0a>T_Param2() |
The number of bytes in the literal $T_Param2()$ is ten. Represented as two hex bytes with that value. Followed by the name of the Task parameter defined in the Task definition. |
<0x00><0x02> |
The number of array elements being passed (two), represented as two hex bytes with that value. |
<0x00><0x2c> |
The number of bytes from this point (including these two characters) to the last byte of the last element of the T_Param2 array. This totals 44 characters. Represent this total as two hex bytes. To accumulate the total, count 2 for these two hex bytes, add two for the length count of the first element (the two bytes <0x00> and <0x12>), add eighteen for the number of bytes in the literal $M!a!I!n! !A!c!c!t!$, and so on. |
<0x00><0x12>M!a!i!n! !A!c!c!t! |
Details of the first element of the T_Param2() array. The number of bytes in the literal $M!a!I!n! A!c!c!t!$ is 18. Represented as two hex bytes with this value. Followed by the value of the first element. |
<0x00><0x14>S!w!I!s!s! !A!c!c!t! |
Details of the second element of the T_Param2() array. The number of bytes in the literal $S!w!I!s!s! !A!c!c!t!$ is 20. Represented as two hex bytes with this value. Followed by the value of the second element. |
|
This sequence is repeated for the third and fourth elements of the T_Param2() array. |
<0x00><0x02> |
The number of elements (two) in the T_Param3() array being passed, represented by two hex bytes with that value |
<0x00><0x15> |
The number of bytes from this point (including these two bytes) to the last byte of the last element of the T_Param3() array. This totals 21 bytes. Represented by two hex bytes with this value. |
<0x00><0x06>746.34 |
Details of the first element of the T_Param3() array. The number of bytes in the literal $746.34$ is six. Represented by two hex bytes with this value. Followed by the value for this element. |
<0x00><0x09>192382.23 |
Details of the second and last element in the T_Param3() array. The number of bytes in the literal $192382.23$ is nine. Represented by two hex bytes with this value. Followed by the value for this element. |
Topic ID: 540055