/* This function encodes a map which contains nested field lists */ RsslRet exampleEncodeMap(RsslEncodeIterator *encIter) { /* use this to store and check return codes */ RsslRet retVal; RsslBool success = RSSL_TRUE; /* create and initialize our map structure */ RsslMap rsslMap = RSSL_INIT_MAP; /* populate map structure prior to call to rsslEncodeMapInit */ /* NOTE: the key names used for this example may not correspond to actual name values */ /* indicate that summary data and a total count hint will be encoded */ rsslMap.flags = RSSL_MPF_HAS_SUMMARY_DATA | RSSL_MPF_HAS_TOTAL_COUNT_HINT; /* populate maps keyPrimitiveType and containerType */ rsslMap.containerType = RSSL_DT_FIELD_LIST; rsslMap.keyPrimitiveType = RSSL_DT_UINT; /* populate total count hint with approximate expected entry count */ rsslMap.totalCountHint = 3; /* begin encoding of map - assumes that the RsslEncodeIterator pointed by the encIter pointer is already populated with buffer and version information, store return value to determine success or failure */ /* expect summary data of approx. 256 bytes, no set definition data */ if ((retVal = rsslEncodeMapInit(encIter, &rsslMap, 256, 0 )) < RSSL_RET_SUCCESS) { /* error condition - switch our success value to false so we can roll back */ success = RSSL_FALSE; /* print out message with return value string, value, and text */ printf("Error %s (%d) encountered with rsslEncodeMapInit(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); } else { /* mapInit encoding was successful */ /* create a single RsslMapEntry and RsslFieldList and reuse for each entry */ RsslMapEntry mapEntry = RSSL_INIT_MAP_ENTRY; RsslUInt entryKeyUInt = 0; /* create a buffer for uInt and field list to encode into - This buffer can come from anywhere (stack allocated, malloc/new heap allocated). Typically, for performance, the transport layer can provide a pool of buffers for use and reuse that avoids the constant allocation/deallocation penalty. For this example I am stack allocating the buffer */ char buf[10] = ""; //10 bytes is large enough for UInt encoding char buf2[500] = ""; //500 bytes is large enough for RsslFieldList encoding /* create a RsslBuffer to set the buffer into */ RsslBuffer encDecBuffer, encDecBuffer2; RsslBuffer *pEncUInt = 0, *pEncFieldList = 0; /* set the data members to encDecBuffer buf and the length I created */ encDecBuffer.data = buf; encDecBuffer.length = 10; encDecBuffer2.data = buf2; encDecBuffer2.length = 500; printf("\tRsslMap Header Encoded\n"); /* encode expected summary data, init for this was done by rsslEncodeMapInit - this type should match rsslMap.containerType */ { printf("\tEncoding Summary Data\n"); /* now encode nested container using its own specific encode functions */ /* begin encoding of field list - using same encIterator as map list */ if ((retVal = exampleEncodeFieldList(encIter)) < RSSL_RET_SUCCESS) { /* error condition - switch our success value to false so we can roll back */ success = RSSL_FALSE; printf("<%s:%d> Error encoding field list.\n", __FILE__, __LINE__); printf("Error %s (%d) encountered with exampleEncodeFieldList(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); } printf("\tSummary Data Encoding Complete\n"); } /* complete encoding of summary data. If any field list encoding failed, success is false */ if ((retVal = rsslEncodeMapSummaryDataComplete(encIter, success)) < RSSL_RET_SUCCESS) { /* error condition - switch our success value to false so we can roll back */ success = RSSL_FALSE; printf("Error %s (%d) encountered with rsslEncodeMapSummaryDataComplete(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); } /* FIRST Map Entry: encode entry from non pre-encoded data and key. Approx. encoded length unknown */ mapEntry.action = RSSL_MPEA_UPDATE_ENTRY; entryKeyUInt = 1; if ((retVal = rsslEncodeMapEntryInit(encIter, &mapEntry, &entryKeyUInt, 0)) < RSSL_RET_SUCCESS) { /* error condition - switch our success value to false so we can roll back */ success = RSSL_FALSE; printf("Error %s (%d) encountered with rsslEncodeMapEntryInit(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); } else /* encode contained field list - this type should match rsslMap.containerType */ { printf("\tEncoding Map Entry (key: " RTR_LLU ") from non pre-encoded data and key\n", entryKeyUInt); /* now encode nested container using its own specific encode functions */ /* clear, then begin encoding of field list - using same encIterator as map */ if ((retVal = exampleEncodeFieldList(encIter)) < RSSL_RET_SUCCESS) { /* error condition - switch our success value to false so we can roll back */ success = RSSL_FALSE; printf("<%s:%d> Error encoding field list.\n", __FILE__, __LINE__); printf("Error %s (%d) encountered with exampleEncodeFieldList(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); } } if ((retVal = rsslEncodeMapEntryComplete(encIter, success)) < RSSL_RET_SUCCESS) { /* error condition - switch our success value to false so we can roll back */ success = RSSL_FALSE; printf("Error %s (%d) encountered with rsslEncodeMapEntryComplete(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); } printf("\tMap Entry (key: " RTR_LLU ") Encoding Complete\n", entryKeyUInt); /* SECOND Map Entry: encode entry from pre-encoded buffer containing an encoded RsslFieldList */ /* because we are re-populating all values on RsslMapEntry, there is no need to clear it */ mapEntry.action = RSSL_MPEA_ADD_ENTRY; entryKeyUInt = 2; printf("\tEncoding Map Entry (key: 2) from pre-encoded buffer\n"); /* assuming pEncUInt RsslBuffer contains the pre-encoded key with length and data properly populated */ if ((retVal = getPreEncodedRsslUIntBuffer(&encDecBuffer, entryKeyUInt)) < RSSL_RET_SUCCESS) { /* error condition - switch our success value to false so we can roll back */ success = RSSL_FALSE; printf("Error %s (%d) encountered with getPreEncodedRsslUIntBuffer(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); } pEncUInt = &encDecBuffer; mapEntry.encKey.length = pEncUInt->length; mapEntry.encKey.data = pEncUInt->data; /* assuming pEncFieldList RsslBuffer contains the pre-encoded payload with data and length populated */ if ((retVal = getPreEncodedRsslFieldListBuffer(&encDecBuffer2)) < RSSL_RET_SUCCESS) { /* error condition - switch our success value to false so we can roll back */ success = RSSL_FALSE; printf("Error %s (%d) encountered with getPreEncodedRsslFieldListBuffer(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); } pEncFieldList = &encDecBuffer2; mapEntry.encData.length = pEncFieldList->length; mapEntry.encData.data = pEncFieldList->data; /* void* parameter is passed in as NULL because pre-encoded key is set on RsslMapEntry itself */ if ((retVal = rsslEncodeMapEntry(encIter, &mapEntry, NULL)) < RSSL_RET_SUCCESS) { /* error condition - switch our success value to false so we can roll back */ success = RSSL_FALSE; printf("Error %s (%d) encountered with rsslEncodeMapEntry(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); } printf("\tMap Entry (key: " RTR_LLU ") Encoding Complete\n", entryKeyUInt); /* THIRD Map Entry: encode entry with delete action. Delete actions have no payload */ /* need to ensure that RsslMapEntry is appropriatley cleared * - clearing will ensure that encData and encKey are properly emptied */ rsslClearMapEntry(&mapEntry); mapEntry.action = RSSL_MPEA_DELETE_ENTRY; entryKeyUInt = 3; printf("\tEncoding Map Entry (key: " RTR_LLU ") with delete action with no payload\n", entryKeyUInt); /* void* parameter is passed in as pointer to key primitive value. encData is empty for delete */ if ((retVal = rsslEncodeMapEntry(encIter, &mapEntry, &entryKeyUInt)) < RSSL_RET_SUCCESS) { /* error condition - switch our success value to false so we can roll back */ success = RSSL_FALSE; printf("Error %s (%d) encountered with rsslEncodeMapEntry(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); } printf("\tMap Entry (key: " RTR_LLU ") Encoding Complete\n", entryKeyUInt); } /* complete map encoding. If success parameter is true, this will finalize encoding. If success parameter is false, this will roll back encoding prior to rsslEncodeMapInit */ if ((retVal = rsslEncodeMapComplete(encIter, success)) < RSSL_RET_SUCCESS) { printf("Error %s (%d) encountered with rsslEncodeMapEntry(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); return retVal; } printf("\tRsslMap Encoding Complete\n"); return RSSL_RET_SUCCESS; }
/* this function will encode a basic field list with several primitives embedded in it */ RsslRet exampleEncodeFieldList(RsslEncodeIterator *encIter) { /* used to store and check return values */ RsslRet retVal; /* create and initialize field list structure */ RsslFieldList fieldList = RSSL_INIT_FIELD_LIST; /* populate field list structure prior to call to rsslEncodeFieldListInit */ /* NOTE: the fieldId, dictionaryId and fieldListNum values used for this example * do not correspond to actual id values */ /* indicate that standard data will be encoded and that dictionaryId and fieldListNum are included */ fieldList.flags = RSSL_FLF_HAS_STANDARD_DATA | RSSL_FLF_HAS_FIELD_LIST_INFO; /* populate dictionaryId and fieldListNum with info needed to cross-reference fieldIds and cache */ fieldList.dictionaryId = 2; fieldList.fieldListNum = 5; /* begin encoding of field list - assumes that the RsslEncodeIterator pointed by the encIter pointer is already populated with buffer and version information */ /* Please note: here for simplicity, we did not use success parameter for rsslEncodeFieldListInit/rsslEncodeFieldListComplete calls. We are just simply displaying an error if it occurs and exit, thus RSSL_TRUE is used in replacement for success parameter */ if ((retVal = rsslEncodeFieldListInit(encIter, &fieldList, 0, 0)) < RSSL_RET_SUCCESS) { /* print out message with return value string, value, and text */ printf("Error %s (%d) encountered with rsslEncodeFieldListInit(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); return retVal; } else { /* fieldListInit encoding was successful */ /* create a single RsslFieldEntry and reuse for each entry */ RsslFieldEntry fieldEntry = RSSL_INIT_FIELD_ENTRY; RsslBool success = RSSL_TRUE; /* stack allocate a date and populate {day, month, year} */ RsslDate rsslDate = {30, 11, 2010}; RsslReal rsslReal = RSSL_INIT_REAL; RsslTime rsslTime = RSSL_INIT_TIME; RsslArray rsslArray = RSSL_INIT_ARRAY; RsslDateTime rsslDateTime = RSSL_INIT_DATETIME; RsslQos rsslQos = RSSL_INIT_QOS; RsslState rsslState = RSSL_INIT_STATE; RsslEnum rsslEnum = 0; RsslBuffer rsslBuffer = RSSL_INIT_BUFFER; RsslUInt uInt = 23456; RsslInt Int = 65432; RsslFloat Float = 3.14f; RsslDouble Double = 3.1416; /* create a buffer for uInt to encode into - This buffer can come from anywhere (stack allocated, malloc/new heap allocated). Typically, for performance, the transport layer can provide a pool of buffers for use and reuse that avoids the constant allocation/deallocation penalty. For this example I am stack allocating the buffer */ char buf[10] = ""; //10 bytes is large enough for UInt encoding /* create a RsslBuffer to set the buffer into */ RsslBuffer encDecBuffer; RsslBuffer *pEncUInt = 0; /* set the data members to encDecBuffer buf and the length I created */ encDecBuffer.data = buf; encDecBuffer.length = 10; printf("\tFieldList Header Encoded\n"); /* FIRST Field Entry: encode entry from the RsslDate primitive type */ /* populate and encode field entry with fieldId and dataType information for this field */ fieldEntry.fieldId = 16; fieldEntry.dataType = RSSL_DT_DATE; if ((retVal = rsslEncodeFieldEntry(encIter, &fieldEntry, &rsslDate)) < RSSL_RET_SUCCESS) { printf("Error %s (%d) encountered with rsslEncodeFieldEntry(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); return retVal; } printf("\t\tFID %d Encoded Date: %d-%d-%d\n", fieldEntry.fieldId, rsslDate.month, rsslDate.day, rsslDate.year); /* SECOND Field Entry: encode entry from the RsslUInt primitive type */ fieldEntry.fieldId = 1080; fieldEntry.dataType = RSSL_DT_UINT; if ((retVal = rsslEncodeFieldEntry(encIter, &fieldEntry, &uInt)) < RSSL_RET_SUCCESS) { printf("Error %s (%d) encountered with rsslEncodeFieldEntry(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); return retVal; } printf("\t\tFID %d Encoded Unsigned Integer: "RTR_LLU"\n", fieldEntry.fieldId, uInt); /* THIRD Field Entry: encode entry from preencoded buffer containing an encoded RsslUInt type */ /* populate and encode field entry with fieldId and dataType information for this field */ /* because we are re-populating all values on RsslFieldEntry, there is no need to clear it */ fieldEntry.fieldId = 1081; fieldEntry.dataType = RSSL_DT_UINT; /* assuming pEncUInt is an RsslBuffer with length and data properly populated */ if ((retVal = getPreEncodedRsslUIntBuffer(&encDecBuffer, uInt)) < RSSL_RET_SUCCESS) { printf("Error %s (%d) encountered with getPreEncodedRsslUIntBuffer(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); return retVal; } pEncUInt = &encDecBuffer; fieldEntry.encData.length = pEncUInt->length; fieldEntry.encData.data = pEncUInt->data; /* void* parameter is passed in as NULL because pre-encoded data is set on RsslFieldEntry itself */ if ((retVal = rsslEncodeFieldEntry(encIter, &fieldEntry, NULL)) < RSSL_RET_SUCCESS) { printf("Error %s (%d) encountered with rsslEncodeFieldEntry(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); return retVal; } printf("\t\tFID %d Encoded Unsigned Integer: from preencoded buffer\n", fieldEntry.fieldId); /* FOURTH Field Entry: encode entry as a blank RsslReal primitive type */ /* populate and encode field entry with fieldId and dataType information for this field */ /* need to ensure that RsslFieldEntry is appropriatley cleared * - clearing will ensure that encData is properly emptied */ rsslClearFieldEntry(&fieldEntry); fieldEntry.fieldId = 22; fieldEntry.dataType = RSSL_DT_REAL; /* void* parameter is passed in as NULL and encData is empty due to clearing */ if ((retVal = rsslEncodeFieldEntry(encIter, &fieldEntry, NULL)) < RSSL_RET_SUCCESS) { printf("Error %s (%d) encountered with rsslEncodeFieldEntry(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); return retVal; } printf("\t\tFID %d Encoded RsslReal as blank.\n", fieldEntry.fieldId); /* FIFTH Field Entry: encode entry for a RsslReal primitive type */ fieldEntry.fieldId = 24; fieldEntry.dataType = RSSL_DT_REAL; rsslReal.hint = RSSL_RH_EXPONENT_2; rsslReal.value = 227; if ((retVal = rsslEncodeFieldEntry(encIter, &fieldEntry, &rsslReal)) < RSSL_RET_SUCCESS) { printf("Error %s (%d) encountered with rsslEncodeFieldEntry(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); return retVal; } printf("\t\tFID %d Encoded RsslReal: hint: %d value: "RTR_LLD"\n", fieldEntry.fieldId, rsslReal.hint, rsslReal.value); /* SIXTH Field Entry: encode entry for another RsslReal primitive type */ fieldEntry.fieldId = 25; fieldEntry.dataType = RSSL_DT_REAL; rsslReal.hint = RSSL_RH_EXPONENT_4; rsslReal.value = 22801; if ((retVal = rsslEncodeFieldEntry(encIter, &fieldEntry, &rsslReal)) < RSSL_RET_SUCCESS) { printf("Error %s (%d) encountered with rsslEncodeFieldEntry(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); return retVal; } printf("\t\tFID %d Encoded RsslReal: hint: %d value: "RTR_LLD"\n", fieldEntry.fieldId, rsslReal.hint, rsslReal.value); /* SEVENTH Field Entry: encode entry for another RsslTime primitive type */ fieldEntry.fieldId = 18; fieldEntry.dataType = RSSL_DT_TIME; rsslTime.hour = 8; rsslTime.minute = 39; rsslTime.second = 24; if ((retVal = rsslEncodeFieldEntry(encIter, &fieldEntry, &rsslTime)) < RSSL_RET_SUCCESS) { printf("Error %s (%d) encountered with rsslEncodeFieldEntry(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); return retVal; } printf("\t\tFID %d Encoded RsslTime: %d:%d:%d\n", fieldEntry.fieldId, rsslTime.hour, rsslTime.minute, rsslTime.second); /* EIGHTH Field Entry: encode entry from the RsslInt primitive type */ fieldEntry.fieldId = FID_INT; fieldEntry.dataType = RSSL_DT_INT; if ((retVal = rsslEncodeFieldEntry(encIter, &fieldEntry, &Int)) < RSSL_RET_SUCCESS) { printf("Error %s (%d) encountered with rsslEncodeFieldEntry(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); return retVal; } printf("\t\tFID %d Encoded signed Integer: "RTR_LLD"\n", fieldEntry.fieldId, Int); /* NINETH Field Entry: encode entry from the RsslFloat primitive type */ fieldEntry.fieldId = FID_FLOAT; fieldEntry.dataType = RSSL_DT_FLOAT; if ((retVal = rsslEncodeFieldEntry(encIter, &fieldEntry, &Float)) < RSSL_RET_SUCCESS) { printf("Error %s (%d) encountered with rsslEncodeFieldEntry(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); return retVal; } printf("\t\tFID %d Encoded float: %f\n", fieldEntry.fieldId, Float); /* TENTH Field Entry: encode entry from the RsslDouble primitive type */ fieldEntry.fieldId = FID_DOUBLE; fieldEntry.dataType = RSSL_DT_DOUBLE; if ((retVal = rsslEncodeFieldEntry(encIter, &fieldEntry, &Double)) < RSSL_RET_SUCCESS) { printf("Error %s (%d) encountered with rsslEncodeFieldEntry(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); return retVal; } printf("\t\tFID %d Encoded Double: %f\n", fieldEntry.fieldId, Double); /* ELEVENTH Field Entry: encode entry from the RsslDateTime primitive type */ fieldEntry.fieldId = FID_DATETIME; fieldEntry.dataType = RSSL_DT_DATETIME; rsslDateTime.date.month = 11; rsslDateTime.date.day = 15; rsslDateTime.date.year = 2011; rsslDateTime.time.hour = 8; rsslDateTime.time.minute = 39; rsslDateTime.time.second = 24; if ((retVal = rsslEncodeFieldEntry(encIter, &fieldEntry, &rsslDateTime)) < RSSL_RET_SUCCESS) { printf("Error %s (%d) encountered with rsslEncodeFieldEntry(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); return retVal; } printf("\t\tFID %d Encoded DateTime: %d-%d-%d %d:%d:%d\n", fieldEntry.fieldId, rsslDateTime.date.month, rsslDateTime.date.day, rsslDateTime.date.year, rsslDateTime.time.hour, rsslDateTime.time.minute, rsslDateTime.time.second); /* TWELVETH Field Entry: encode entry from the RsslQos primitive type */ fieldEntry.fieldId = FID_QOS; fieldEntry.dataType = RSSL_DT_QOS; rsslQos.timeliness = RSSL_QOS_TIME_REALTIME; rsslQos.rate = RSSL_QOS_RATE_TICK_BY_TICK; rsslQos.dynamic = 1; rsslQos.rateInfo = 0; rsslQos.timeInfo = 0; if ((retVal = rsslEncodeFieldEntry(encIter, &fieldEntry, &rsslQos)) < RSSL_RET_SUCCESS) { printf("Error %s (%d) encountered with rsslEncodeFieldEntry(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); return retVal; } printf("\t\tFID %d Encoded QOS: %d %d %d %d %d\n", fieldEntry.fieldId, rsslQos.timeliness, rsslQos.rate, rsslQos.dynamic, rsslQos.rateInfo, rsslQos.timeInfo); /* THIRTEENTH Field Entry: encode entry from the RsslState primitive type */ fieldEntry.fieldId = FID_STATE; fieldEntry.dataType = RSSL_DT_STATE; rsslState.streamState = RSSL_STREAM_OPEN; rsslState.dataState = RSSL_DATA_OK; rsslState.code = RSSL_SC_NONE; rsslState.text.data = (char *)"Succeeded"; rsslState.text.length = 10; // include the null for printing if ((retVal = rsslEncodeFieldEntry(encIter, &fieldEntry, &rsslState)) < RSSL_RET_SUCCESS) { printf("Error %s (%d) encountered with rsslEncodeFieldEntry(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); return retVal; } printf("\t\tFID %d Encoded State: %d %d %d %s\n", fieldEntry.fieldId, rsslState.streamState, rsslState.dataState, rsslState.code, rsslState.text.data); /* FOURTEENTH Field Entry: encode entry from the RsslBuffer primitive type */ fieldEntry.fieldId = FID_BUFFER; fieldEntry.dataType = RSSL_DT_BUFFER; rsslBuffer.data = (char *)"BUFFEREXAMPLE"; rsslBuffer.length = 14; // include the null terminator to make it easier to print if ((retVal = rsslEncodeFieldEntry(encIter, &fieldEntry, &rsslBuffer)) < RSSL_RET_SUCCESS) { printf("Error %s (%d) encountered with rsslEncodeFieldEntry(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); return retVal; } printf("\t\tFID %d Encoded Buffer: %s\n", fieldEntry.fieldId, rsslBuffer.data); /* FIFTEENTH Field Entry: encode entry from the RsslEnum primitive type */ fieldEntry.fieldId = FID_ENUM; fieldEntry.dataType = RSSL_DT_ENUM; rsslEnum = 999; if ((retVal = rsslEncodeFieldEntry(encIter, &fieldEntry, &rsslEnum)) < RSSL_RET_SUCCESS) { printf("Error %s (%d) encountered with rsslEncodeFieldEntry(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); return retVal; } printf("\t\tFID %d Encoded Enum: %d\n", fieldEntry.fieldId, rsslEnum); /* SIXTEENTH Field Entry: encode entry as a complex type, RsslArray primitive */ /* populate and encode field entry with fieldId and dataType information for this field */ /* need to ensure that RsslFieldEntry is appropriatley cleared * - clearing will ensure that encData is properly emptied */ rsslClearFieldEntry(&fieldEntry); fieldEntry.fieldId = 1021; fieldEntry.dataType = RSSL_DT_ARRAY; /* begin complex field entry encoding, we are not sure of the approximate max encoding length */ if ((retVal = rsslEncodeFieldEntryInit(encIter, &fieldEntry, 0)) < RSSL_RET_SUCCESS) { /* error condition - switch our success value to false so we can roll back */ success = RSSL_FALSE; /* print out message with return value string, value, and text */ printf("Error %s (%d) encountered with rsslEncodeFieldEntryInit(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); } else { /* now encode nested container using its own specific encode functions */ /* encode RsslReal values into the array */ rsslArray.primitiveType = RSSL_DT_UINT; /* values are variable length */ rsslArray.itemLength = 2; /* begin encoding of array - using same encIterator as field list */ if ((retVal = rsslEncodeArrayInit(encIter, &rsslArray)) < RSSL_RET_SUCCESS) { /* error condition - switch our success value to false so we can roll back */ success = RSSL_FALSE; /* print out message with return value string, value, and text */ printf("Error %s (%d) encountered with rsslEncodeArrayInit(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); } else { /*----- Continue encoding array entries. ---- */ RsslUInt uInt1 = 10, uInt2 = 20, uInt3 = 30, uInt4 = 40; /* array encoding was successful */ printf("\t\tFID %d Encoded RsslArray: [", fieldEntry.fieldId); /* encode first entry from a UInt from a primitive type */ if ((retVal = rsslEncodeArrayEntry(encIter, NULL, &uInt1)) < RSSL_RET_SUCCESS) { /* error condition - switch our success value to false so we can roll back */ success = RSSL_FALSE; printf("Error %s (%d) encountered with rsslEncodeArrayEntry(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); } printf(" "RTR_LLU" ", uInt1); /* encode second entry from a UInt from a primitive type */ if ((retVal = rsslEncodeArrayEntry(encIter, NULL, &uInt2)) < RSSL_RET_SUCCESS) { /* error condition - switch our success value to false so we can roll back */ success = RSSL_FALSE; printf("Error %s (%d) encountered with rsslEncodeArrayEntry(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); } printf(" "RTR_LLU" ", uInt2); /* encode third entry from a UInt from a primitive type */ if ((retVal = rsslEncodeArrayEntry(encIter, NULL, &uInt3)) < RSSL_RET_SUCCESS) { /* error condition - switch our success value to false so we can roll back */ success = RSSL_FALSE; printf("Error %s (%d) encountered with rsslEncodeArrayEntry(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); } printf(" "RTR_LLU" ", uInt3); /* encode forth entry from a UInt from a primitive type */ if ((retVal = rsslEncodeArrayEntry(encIter, NULL, &uInt4)) < RSSL_RET_SUCCESS) { /* error condition - switch our success value to false so we can roll back */ success = RSSL_FALSE; printf("Error %s (%d) encountered with rsslEncodeArrayEntry(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); ; } printf(" "RTR_LLU" ", uInt4); /* encode fifth entry from a UInt from pre-encoded integer contained in a buffer */ /* this buffer.data should point to encoded int and the length should be number of bytes encoded */ if ((retVal = rsslEncodeArrayEntry(encIter, pEncUInt, NULL)) < RSSL_RET_SUCCESS) { /* error condition - switch our success value to false so we can roll back */ success = RSSL_FALSE; printf("Error %s (%d) encountered with rsslEncodeArrayEntry(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); } printf(" <Preencoded> ]\n"); } /* complete array encoding. If success parameter is true, this will finalize encoding. If success parameter is false, this will roll back encoding prior to rsslEncodeArrayInit */ if ((retVal = rsslEncodeArrayComplete(encIter, success)) < RSSL_RET_SUCCESS) { /* error condition - switch our success value to false so we can roll back */ success = RSSL_FALSE; printf("Error %s (%d) encountered with rsslEncodeArrayComplete(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); } } /* complete encoding of complex field entry. If any array encoding failed, success is false */ if ((retVal = rsslEncodeFieldEntryComplete(encIter, success)) < RSSL_RET_SUCCESS) { printf("Error %s (%d) encountered with rsslEncodeFieldEntryComplete(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); return retVal; } } /* complete fieldList encoding. If success parameter is true, this will finalize encoding. If success parameter is false, this will roll back encoding prior to rsslEncodeFieldListInit */ /* Please note: here for simplicity, we did not use success parameter for rsslEncodeFieldListInit/rsslEncodeFieldListComplete calls. We are just simply displaying an error if it occurs and exit, thus RSSL_TRUE is used in replacement for success parameter */ if ((retVal = rsslEncodeFieldListComplete(encIter, RSSL_TRUE)) < RSSL_RET_SUCCESS) { printf("Error %s (%d) encountered with rsslEncodeFieldListComplete(). Error Text: %s\n", rsslRetCodeToString(retVal), retVal, rsslRetCodeInfo(retVal)); return retVal; } printf("\tFieldList Encoding Complete\n"); return RSSL_RET_SUCCESS; }