Re: [Wing-007-technical] Making wing modules platform-independent ---- much tougher than I expected
Status: Pre-Alpha
Brought to you by:
renqilin
From: 任麒麟 <ren...@gm...> - 2009-04-07 15:35:42
|
Hi Stein, #1 I suggest using big endian in file, because the data in network protocol uses big endian format. But I'm ok with little-endian format. Here is a list of endianness of different platforms: Network Protocol: Big-Endian Java Application: Big-Endian Motorola PowerPC: Big-Endian x86: Little-Endian ARM: Support both Big-Endian and Little-Endian. Usually Little-Endian #2 I have some old code to do conversion between big-endian and little-endian. It is defined at WingSDK/Include/Framework/ByteOrder.h. #3 There are some old code reusable. I have the binary buffer class (or binaryString in your mail). Basicly it equals to std::stream_buf. See: WingSDK/Include/Framework/IStreamBufferBase.h WingSDK/Include/Framework/IBinaryBuffer.h Based on the virtual binary buffer. I added some functionalities in WingSDK/Include/Framework/StreamUtility.h. They are: transform a binary stream to a cached binary stream, aggregate two buffers into one buffer, copy data from one buffer to another, compare two buffers, create sub/child buffers. Those functionalities are implemtented at: Source/Framework/CBinBufAggregater.h Source/Framework/CBinBufAggregater.cpp Source/Framework/CCacheReadSeqStream.h Source/Framework/CCacheReadSeqStream.cpp Source/Framework/CCacheWriteSeqStream.h Source/Framework/CCacheWriteSeqStream.cpp Source/Framework/CChildBuffer.h Source/Framework/CChildBuffer.cpp There are two derived classes of IBinaryBuffer: One for file in disk, and the other for memory: WingSDK/Include/Framework/CFileStream.h WingSDK/Include/Framework/CMemoryFile.h Source/Framework/CFileStream.cpp Source/Framework/CMemoryFile.cpp I should rename "CFileStream" to "FileBuffer", and rename "CMemoryFile" to "MemoryBuffer". In my humble opinion: The binary buffer (or binary string) will not know how binary data is formatted. It cares about byte series only. A binary stream will be responsible for converting binary data to correct format. This class contains a IBinaryBuffer. It may have operators like << or >> to transform a basic type to big endian and write it to the underlying IBinaryBuffer. Any class that wants to be serializable must implement their own functions of handling the << and >> operator. The idea is not new. I just borrow the design of std::iostream and std::stream_buf. How do you think about this? Qilin 2009/4/7 Stein Gunnar Grastveit <gra...@pv...> > Hi, > I been reading a little bit about binary files, and binary data. > I thin we need: > binaryString > biofstream > > The binaryString will hold a string containing binary data ( big endian > or little endian based on system, detected in configuration.h ). And > sizeof( int, float ... ) is defined in types.h? > To put 50 bytes in a struct I think it should be done through a > binaryString to be sure the data is encoded for the current system. > > > And for read/write I guess we are going to use the types defined in > types.h ? And always store files as little endian? > > -steini > > > |