Adjust Buffer size when encoding a message
Hello
When encoding a message using the rssl functions, often the size of the resulting message is unknown so at the start a big buffer needs to be created (sometimes way larger than the resulting message size). Is there a clean way of creating a buffer and then making it bigger if it is not large enough?
Thanks
Best Answer
-
UPA has a helper method exactly for this purpose. The general idea when you see BUFFER_TOO_SMALL when encoding, you can use the rsslRealignEncodeIteratorBuffer method to associate a new buffer with your encoding iterator and continue encoding from where you left off.
The general process is that you would get a new buffer, ensuring you have a reference to the old buffer if it came from rsslGetBuffer(…). If your failed encoding occurred via an EncodeInit method, you should roll back to the last successful point (by calling the EncodeComplete method with success=false). If you were using a non-Init encode method (e.g. rsslEncodeFieldEntry()) you do not need to roll back as these will automatically roll back upon failure. Once content is rolled back to the last successful point of encode and you have a new, larger buffer you pass the encode iterator and the new buffer into rsslRealignEncodeIteratorBuffer. This will copy your encoding and update the iterator. You then continue encoding by calling the encode method again (e.g. EncodeInit or rsslEncodeFieldEntry()). If the old buffer (the one that was too small) came from rsslGetBuffer, you need to call rsslReleaseBuffer() to ensure it goes back to the pool.
Here is a brief sample, you may have to change this to suit your needs. In this sample, rsslEncodeFieldEntry fails with BUFFER_TOO_SMALL, we get a new transport buffer, realign the iterator, then release the old buffer, and then reencode the field entry.ret = rsslEncodeFieldEntry(&eIter, &field, &uint);
if (ret == RSSL_RET_BUFFER_TOO_SMALL)
{
RsslBuffer *pNewBuffer = rsslGetBuffer(&channel, newSize, RSSL_FALSE, &error);
if (RSSL_RET_SUCCESS == rsslRealignEncodeIteratorBuffer(&eIter, pNewBuffer))
{
rsslReleaseBuffer(pOriginalBuffer, &error);
ret = rsslEncodeFieldEntry(&eIter, &field, &uint));
// Check return codes and continue on with the rest of encoding
}
else
{
//realign didn’t work. Handle failure0
Categories
- All Categories
- 6 AHS
- 37 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 59 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛