Is there a way to help convert a binary to a specified record in Delphi 5? And this binary is in little-endian.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Windows on Intel/AMD is little-endian too, so no endianness conversion is required.
Now if you can show the specific record and where you get the binary data from, it will be easier to answer.
You can read any kind of record from a file. If your record is declared thus that it has exactly the same layout as the binary data, you can read an entire record at once. If not, you’ll have to read each field separately.
Generally, you can read records, or individual fields of a record, from a stream using
If your data comes from a TCP socket, you can, for instance, write it into a TMemoryStream, as bytes. Then you can reset the pointer of the stream to the beginning and read the data as shown.
Update
As David commented, if the bytes come over the TCP connection in network byte order, then it makes sense to run each field through one of the WinSock functions ntohs() or ntohl(), after all the above, but before the items in the record are used. ntohs() converts 2 byte types, while ntohl() converts 4 byte types. To send items, use the reverse functions htons() and htonl() on each item in the record before sending them (separately).
FWIW, it is quite easy, in Win32, to change endianness using: