How to represent general binary data

下面的内容摘自Symbian S60 3rd Edition SDK,先把英文原版贴在这里,等时间充足的时候我再把它翻译出来。How to represent general binary data《如何表示普通的二进制数据》

How to represent general binary data

The kind of data represented or contained by descriptors is not restricted to text. Descriptors can also handle general binary data.

To deal with general binary data, always explicitly construct an 8 bit variant descriptor. Binary data should always be treated as 8 bit data regardless of the build.

For example, starting with an area in memory initialised with binary data as follows:

TUint8 data[6] = {0x00,0x01,0x02,0xAD,0xAE,0xAF};

construct a modifiable buffer descriptor using the default constructor as follows:

TBuf8<32> buffer;

The following code fragment puts the binary data into the descriptor and appends a number of single byte values. The length of the buffer is 9, the maximum length is 32 and the size is 9 regardless of the build.

TInt index;
TInt counter;

Text and general binary data can be freely mixed and the following code is acceptable:

buffer.Append('A');
buffer.Append('B');
buffer.Append(0x11);

Note that fixed length C++ arrays such as data above can be packaged inside a thin wrapper class, a TFixedArray<class T,TInt S> type, to guarantee that all array accesses are safe.

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值