LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-28-2013, 09:24 PM   #1
Shashaa
LQ Newbie
 
Registered: Nov 2012
Posts: 11

Rep: Reputation: Disabled
creating a binary blob in linux


Hello Everyone,

I have a requirement to create a binary blob of a structure in my program. Let me describe the problem;

Process(P1) <-------> Process(P2)
{Connect_REQ}
{Connect_Resp}
.....
.....
.....
I need to send a structure struct XX {.name="abc",.value=1, //etc} in the form of binary blob format to process-P2, in connect request.

Can any one of you shed your knowledge on binary blob format and how can we encode a structure into that format.

Any help/pointers is highly appreciated!!
 
Old 05-29-2013, 10:21 AM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
It's not going to work if you have strings because the structure will contain a pointer. You'll therefore probably need to serialize and deserialize the data structure, which can be a nightmare unless you take advantage of an existing IPC protocol. JSON might be a good place to start.

Kevin Barry
 
Old 05-30-2013, 10:11 AM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
I second ta0kira's point about structures (assuming this is C language structs) and pointers. String data is by nature a variable length data type, so your data must contain either a length descriptor for string fields, or use unique delimiter tokens to mark beginnings &/or endings of fields. JSON is probably as good as any serialization mechanism, but there are others. Certainly this is a problem that has been solved numerous times, so I do suggest availing yourself of an existing solution rather than crafting yet another one of your own contrivance.

--- rod.
 
Old 05-30-2013, 01:56 PM   #4
Shashaa
LQ Newbie
 
Registered: Nov 2012
Posts: 11

Original Poster
Rep: Reputation: Disabled
Thanks for the suggestions guys!!
Anyways my struct doesn't include any strings now and I'm using sockets to communicate between these processes and simply passing the struct in a buffer and then forming a binary blob by writing it to a file at process P2.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Ubuntu 12.10 To Further Binary Blob Handling LXer Syndicated Linux News 0 05-12-2012 05:40 AM
Packing a binary blob as a *deb Alexvader Linux - General 10 02-14-2011 05:03 PM
LXer: This week at LWN: Resisting the binary blob LXer Syndicated Linux News 0 11-19-2006 07:54 PM
Creating/Distributing Linux Binary Files Sava Programming 3 08-29-2006 09:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration