How to grab byte array after serialization? - c++

I'm using Google's Flatbuffer. I've created a simple schema for C++ that just takes a name and ID as the fields. After creating the auto generated code and running the fields through the CreateDetails() function, how would I get the bytearray to pass into ActiveMQ? I've searched around but couldn't find much about the byte array.
My schema:
table details {
name:string;
id: int;
};
root_type details;
My .cpp application:
auto name = builder.CreateString("some text here");
auto id = 25;
auto detail = CreateDetails(builder, name, id);
builder.Finish(detail);
Now, from my understanding, the sample message should be serialized, but I'm not sure how to grab the serialized data as a byte array. I was able to access the root and just go down the tree and look at the data, but I want to grab the entire message as a bytearray.
Please and thank you!

builder.GetBufferPointer()
builder.GetSize()

Related

APEX: Assigning a Map without a Key to a List

Sorry for the newbie question. Learning Apex here. Been working on an issue for several hours and can't seem to needle it out.
I have a JSON that I need converted to a List... the JSON is retrieved via an API. The code is pretty simple, it is only a couple of lines.
The JSON looks like this:
{"id":1,"abbreviation":"ATL","city":"Atlanta","conference":"East","division":"Southeast","full_name":"Atlanta Hawks","name":"Hawks"}
And the code I am told to use to retrieve it looks like this:
Map<String, Object> resultsMap = (Map<String, Object>) JSON.deserializeUntyped(results.getBody());
Based on the JSON provided, there does not appear to be a MAP key being assigned, so I have no idea how to get it so that I may assign it to a List...
I've already tried assigning it directly to a List, but I didn't get much success there either.
I've tried this already:
List<Object> other = (List<Object>) results.get('');
I've also tried this:
List<Object> other = (List<Object>) results.keySet()[0];
I'm sure it is something simple. Any help would be appreciated.
Thanks
You cant convert the map to a list without an id. Alternatively why to convert it to List. Use the map itself. Below is a code example of how you can use it using your JSON response. For example, I want to insert this JSON response into the contact record, so I can map it using the MAP itself.:
#RestResource(urlMapping='/URIId/*')
global class OwneriCRM {
#HttpPut
global static String UpdateOwnerinfo(){
RestRequest req= RestContext.request;
RestResponse res= RestContext.response;
res.addHeader('Content-type','application/JSON');
Map<String,Object> responseresult=new Map<String,Object>();
Map<String,Object> results= (Map<String,Object>)JSON.deserializeUntyped(req.requestBody.toString());
List<contact> insertList = new List<contact>();
for (String key : results.keySet()){
System.debug(results.get(key));
contact c= new contact();
c.ContactField__C = results.get(id);
c.ContactField1__C = results.get(city);
c.ContactField2__C = results.get(conference);
c.ContactField3__C = results.get(division);
c.ContactField3__C = results.get(full_name);
c.ContactField3__C = results.get(name);
insertList.add(c);
}
if(!insertList.Isempty()){
update insertList;
}
Question can be disregarded. Not sure if there is a way to withdraw the question.
Question was based on the fact that previous APIs had been sent in the following format:
{"data": {"more stuff": "stuff"} }
And the map key was 'data' with a list. In this scenario, the whole API was a list and the keys to the map were set in place with the actual values instead.

How do we retrieve values of Custom Lists(dropdown) in Netsuite

I have record type "XYZ" which has field called "award area" which is of type list/record. "award area" is of type custom list and is a drop down control.
Using Suitetalk how can I retrieve those values from that drop down?
Thank you
I think something like this should work. It's for translating the results from the internalId's returned into the actual text type, you maybe be able to leverage it in another way. Maybe you could create a lookup list with something like this(C#):
public Dictionary<string, Dictionary<long, string>> getCustomFieldLists()
{
return
nsService.search(new CustomListSearch())
.recordList.Select(a => (CustomList) a)
.ToDictionary(a => a.name,
a => a.customValueList.customValue
.ToDictionary(b => b.valueId, c => c.value));
}
var valueLookup = getCustomFieldLists()["award area"];
Here's how I did it for myself, because I was irritated with the fact the NetSuite doesn't just provide us an easy way to access these. And I wanted the following data for reference:
The Internal ID of the Custom List
The Name of the Custom List
The Internal ID of the Custom List Item
The name Value of the Custom List Item
I wanted/needed access to all of those things, and I wanted to be able to obtain the name Value of the Custom List Item by just providing the Internal ID of the Custom List and the Internal ID of the Custom List Item. So, in my homemade integration client, similar to David Rogers' answer, but without all the fancy Linq, I figured out that the best solution was a Dictionary>>.
This way, for the outer Dictionary, I could set the key to the internal IDs of the Custom Lists, and for the inner Dictionary I could set the key to the internal IDs of the Custom List Items themselves. Then, I would get the name of the Custom List for "free" as the beginning part of the Tuple, and the actual name Value for "free" as the value of the internal Dictionary.
Below is my method code to generate this object:
/// <summary>
/// Gets the collection of all custom lists, and places it in the public CustomListEntries object
/// </summary>
/// <returns></returns>
private Dictionary<string, Tuple<string, Dictionary<long, string>>> GetCustomLists()
{
Dictionary<string, Tuple<string, Dictionary<long, string>>> customListEntries = new Dictionary<string, Tuple<string, Dictionary<long, string>>>();
SearchPreferences sp = SuiteTalkService.searchPreferences; //Store search preferences to reset back later, just need body fields this one time
SuiteTalkService.searchPreferences = new SearchPreferences() { bodyFieldsOnly = false };
SearchResult sr = SuiteTalkService.search(new CustomListSearch());
SuiteTalkService.searchPreferences = sp; //Restore search preferences
foreach (CustomList cl in sr.recordList)
{
Dictionary<long, string> customListItems = new Dictionary<long, string>();
if (cl.customValueList == null) continue;
foreach (CustomListCustomValue clcv in cl.customValueList.customValue)
{
customListItems.Add(clcv.valueId, clcv.value);
}
customListEntries.Add(cl.internalId, new Tuple<string, Dictionary<long, string>>(cl.name, customListItems));
}
return customListEntries;
}
Then, in the constructors of my Integration class, I can set my object to the return result:
public Dictionary<string, Tuple<string, Dictionary<long, string>>> CustomListEntries = GetCustomLists();
And finally, whenever I need access TO those values, since I set all of this up ahead of time, I can do the following:
dr[Class] = SuiteTalkIntegrator.CustomListEntries[lorr.typeId].Item2[long.Parse(lorr.internalId)];
In this case above, my "lorr" object is a ListOrRecordRef object that I obtained from the SearchColumnSelectCustomField.searchValue from the search results of a SavedSearch. I don't know if this will work for anyone else that finds this code, but since I was frustrated in finding an easy answer to this problem, I thought I'd share my solution with everyone.
Frankly, I'm most frustrated that this functionality isn't just given to us out of the box, but I've noticed that NetSuite has made a lot of bad design choices in their SuiteTalk API, like not making a custom class of "RecordField" for their record fields and not placing their record fields under an IEnumerable of RecordField so that programmers can loop through all values in a record in a generic way without having to EXPLICITLY name them and re-construct the same code logic over and over again... ugh...

c++ bloomberg api correlationId

I'm using the bloomberg api to code a cpp project.
When I need to send a request to the Bloomberg data feed, I must send the request with an ID. For example:
session->sendRequest(*request, CorrelationId(20));
The CorrelationId is provided by the bloomberg api to generate an ID.
The ID here is 20. The result coming from the bloomberg data feed contains the ID 20 so that I can identity the result and the request. Meaning that when I get the result from the data feed, there is something like this:
correlationId=[ valueType=INT classId=0 value=20 ]
Now I want to make a string ID, instead of the int ID. For example, I want to generate an ID like CorrelationId("US543119ES").
If I do this, I get no error but the ID in the result becomes:
correlationId=[ valueType=POINTER classId=0 value=00731378 ]
It seems that the ID becomes a pointer and it sends the value of the pointer, instead of the content of the pointer. Obviously value=00731378 is an address.
Is it impossible to generate a string ID?
If possible, what should I do?
I've found the documentation of CorrelationId.
There are two constructors of CorrelationId that I don't know how to use, I don't know if one of them is what I need:
CorrelationId (void *value, int classId=0);
template<typename TYPE >
CorrelationId (const TYPE &smartPtr, void *pointerValue, int classId=0);
If we want to generate a string ID, we can just send the address of the string. Then the bloomberg data feed will send us back the address, whose type is void *. So we just need to convert it into char *. Here is an example:
// sending
const char * id = "abc";
session->sendRequest(*request, CorrelationId(const_cast<char *>(id))); // it can't take "const char *"
// handling response
cout << (char *)message.correlationId().asPointer(); // it will show "abc".

TideSDK How to save a cookie's information to be accessed in different file?

I am trying to use TideSDK's Ti.Network to set the name and value of my cookie.
But how do I get this cookie's value from my other pages?
var httpcli;
httpcli = Ti.Network.createHTTPCookie();
httpcli.setName(cname); //cname is my cookie name
httpcli.setValue(cvalue); //cvalue is the value that I am going to give my cookie
alert("COOKIE value is: "+httpcli.getValue());
How would I retrieve this cookie value from my next page? Thank you in advance!
ok, there are a lot of ways to create storage content on tidesdk. cookies could be one of them, but not necessary mandatory.
In my personal oppinion, cookies are too limited to store information, so I suggest you to store user information in a JSON File, so you can store from single pieces of information to large structures (depending of the project). Supposing you have a project in which the client have to store the app configuration like 'preferred path' to store files or saving strings (such first name, last name) you can use Ti.FileSystem to store and read such information.:
in the following example, I use jQuery to read a stored json string in a file:
File Contents (conf.json):
{
"fname" : "erick",
"lname" : "rodriguez",
"customFolder" : "c:\\myApp\\userConfig\\"
}
Note : For some reason, Tidesdk cannot parse a json structure like because it interprets conf.json as a textfile, so the parsing will work if you remove all the tabs and spaces:
{"fname":"erick","lname":"rodriguez","customFolder":"c:\\myApp\\userConfig\\"}
now let's read it.... (myappfolder is the path of your storage folder)
readfi = Ti.Filesystem.getFile(myappfolder,"conf.json");
Stream = Ti.Filesystem.getFileStream(readfi);
Stream.open(Ti.Filesystem.MODE_READ);
contents = Stream.read();
contents = JSON.parse(contents.toString);
console.log(contents);
now let's store it....
function saveFile(pathToFile) {
var readfi,Stream,contents;
readfi = Ti.Filesystem.getFile(pathToFile);
Stream = Ti.Filesystem.getFileStream(readfi);
Stream.open(Ti.Filesystem.MODE_READ);
contents = Stream.read();
return contents.toString();
};
//if a JSON var is defined into js, there is no problem
var jsonObject = {
"fname":"joe",
"lname":"doe",
"customFolder" : "c:\\joe\\folder\\"
}
var file = pathToMyAppStorage + "\\" + "conf.json";
var saved = writeTextFile(file,JSON.stringify(jsonObject));
console.log(saved);

Word automation with C++ Builder 5

I'm trying to control Word through a c++ builder 5 application. I would like to
open a ".dot" model file created with Word and modify it. In the ".dot" model file
there are some fields. For example, Title, LastName, FirstName, Address
and so on, and I would like to modify these fields putting text into them and then
saving file with a new name, for example "Warning.doc" leaving the ".dot" file
unaltered.
I can open the file, count the number of fields it contains, but then
when it comes to replacing each field with a string I don't know how to do because
I don't have a complete documentation on OleFunction and OlePropertyGet methods. I attach my source code to this message, can anybody help me to solve this problem please?
try
{
my_word = Variant::CreateObject("word.application");
}
catch (...)
{
Application->MessageBox("Unable to obtain Word automation object",
"Error:",MB_OK | MB_ICONERROR);
}
my_word.OlePropertySet("Visible", (Variant)true);
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Variant this_doc;
Variant my_fields;
Variant test;
int k,field_count;
AnsiString test1;
AnsiString filename = "d:\\ProgrammaWord\\1-Avviso.dot";
my_docs = my_word.OlePropertyGet("Documents");
this_doc = my_docs.OleFunction("Open", filename);
my_fields = this_doc.OlePropertyGet("Fields");
field_count = my_fields.OlePropertyGet("Count");
for(k = 1; k <= field_count; k++)
{
test = my_fields.OleFunction("Item",(Variant)k);
test1 = test.OleFunction("Value"); //This instruction throws an exception
// "Value" is not a recognized parameter
// in this case
Memo1->Lines->Add(test1);
}
}
I never used word Ole but I used it for Outlook and Excel, I can't try it with word since I'm currently on OSX but you should try something similar as what I did.
The generic way of using Ole was to OleGetproperty() while you get the targeted field then OleSetProperty("action", ...).
for example when I wanted to change the color of the text in a particular cell of my excel document I used:
Variant _excel = Variant::CreateObject("Excel.Application");
Variant _workbook = _excel.OlePropertyGet("WorkBooks").OleFunction("Open", filename);
Variant _worksheet = _workbook.OlePropertyGet("WorkSheets", sheet);
_worksheet.OlePropertyGet("Cells", row, col).OlePropertyGet("Font").OlePropertySet("Color", color);
Here I instanciate an excel object, then I load a file into it (_workbook), then I select the _worksheet from the _workbook and I start my business.
Here comes the interesting part:
It concist of getting to a particular cell, getting the font object from it, and then setting the color of this font object.
Disclaimer: This is an example from my sources for excel, it's not directly related to your example, but maybe you can understand the principe with it. I can't try to figure out what you need because I have no windows right now.
Hope this can help you. Finding ressources for OLE can be fierce if you don't have the good patterns to look for.