Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
How to unpack unusual binary structure?
Leo --
12/7/2006 10:00:00 AM
Hello everyone
I try to read binary file and it has section in following format:
(I suspect this comes from .h file)
...
then the bars array (one-byte justification) follows
pragma pack(push,1)
//---- Standard representation of a quote in the base
struct RateInfo {
time_t ctm; // current time in seconds
double open;
double low;
double high;
double close;
double vol;
};
pragma pack(pop)
...
I don't know what to do with pragma pack. I googled and found that this
is some weird bit-level alignment for records. But I can't figure out,
how do I read and .unpack such records.
Can I just do .read(4 + 5 * 8) and get a record?
How do I decode it if its packed with this pragma pack?
Need help...
--
Posted via
http://www.ruby-...
.
3 Answers
Farrel Lifson
12/7/2006 10:04:00 AM
0
On 07/12/06, Leo -- <leopardus.vulgaris@gmail.com> wrote:
> Hello everyone
>
> I try to read binary file and it has section in following format:
> (I suspect this comes from .h file)
>
> ...
> then the bars array (one-byte justification) follows
>
> pragma pack(push,1)
> //---- Standard representation of a quote in the base
> struct RateInfo {
> time_t ctm; // current time in seconds
> double open;
> double low;
> double high;
> double close;
> double vol;
> };
> pragma pack(pop)
> ...
>
> I don't know what to do with pragma pack. I googled and found that this
> is some weird bit-level alignment for records. But I can't figure out,
> how do I read and .unpack such records.
>
> Can I just do .read(4 + 5 * 8) and get a record?
> How do I decode it if its packed with this pragma pack?
>
> Need help...
>
> --
> Posted via
http://www.ruby-...
.
>
>
Have you looked at String#unpack ?
Farrel
Leo --
12/7/2006 12:38:00 PM
0
Farrel Lifson wrote:
> Have you looked at String#unpack ?
Yes, but I do not know how to apply it in the case of packed data
structure. I'm not much into CS, so if this is possible with
String#unpack I will be very happy if you can help me with format string
to unpack this "pragma pack(1)" data structure.
--
Posted via
http://www.ruby-...
.
Farrel Lifson
12/7/2006 12:45:00 PM
0
On 07/12/06, Leo -- <leopardus.vulgaris@gmail.com> wrote:
> Farrel Lifson wrote:
> > Have you looked at String#unpack ?
>
> Yes, but I do not know how to apply it in the case of packed data
> structure. I'm not much into CS, so if this is possible with
> String#unpack I will be very happy if you can help me with format string
> to unpack this "pragma pack(1)" data structure.
>
> --
> Posted via
http://www.ruby-...
.
>
>
This is just a guess and I'm not sure what time_t is but if we assuume
it's an unsigned int then you could say:
ctm,open,low,high,close,vol = packedData.unpack("Iddddd")
Farrel
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
How to unpack unusual binary structure?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password