Symbian3/SDK/Source/GUID-A7D95E53-67DA-54C7-B093-995CA9CC39B5.dita
author Dominic Pinkman <dominic.pinkman@nokia.com>
Tue, 20 Jul 2010 12:00:49 +0100
changeset 13 48780e181b38
parent 0 89d6a7a84779
permissions -rw-r--r--
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE concept
  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept id="GUID-A7D95E53-67DA-54C7-B093-995CA9CC39B5" xml:lang="en"><title>How to
represent general binary data</title><shortdesc>Construct an 8 bit variant descriptor to represent general binary
data.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
<p>The kind of data represented or contained by descriptors is not restricted
to text. Descriptors can also handle general binary data.</p>
<p>Binary data should always be treated as 8 bit data regardless of the build.</p>
<p>For example, starting with an area in memory initialised with binary data
as follows:</p>
<codeblock id="GUID-2541B451-E008-5AD7-A8F7-4A19B76AB2A2" xml:space="preserve">TUint8 data[6] = {0x00,0x01,0x02,0xAD,0xAE,0xAF};</codeblock>
<p>construct a modifiable buffer descriptor using the default constructor
as follows:</p>
<codeblock id="GUID-DDAF1F08-29EC-572F-83B0-0A4437EF1DB9" xml:space="preserve">TBuf8&lt;32&gt; buffer;</codeblock>
<p>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.</p>
<codeblock id="GUID-B9AB3D57-1EFB-5A10-882E-E29301FF8759" xml:space="preserve">TInt index;
TInt counter;</codeblock>
<p>Text and general binary data can be freely mixed and the following code
is acceptable:</p>
<codeblock id="GUID-2D7B1A85-82F6-5B67-8A49-5E79745602A3" xml:space="preserve">buffer.Append('A');
buffer.Append('B');
buffer.Append(0x11);</codeblock>
<p>Note that fixed length C++ arrays such as <codeph>data</codeph> above can
be packaged inside a thin wrapper class, a <codeph>TFixedArray&lt;class T,TInt
S&gt;</codeph> type, to guarantee that all array accesses are safe.</p>
<section id="GUID-A0922DAD-0D96-4758-8ABA-4C33DC6FE01B"><title>See also</title> <p><xref href="GUID-E41C4E77-C48B-548E-A2F5-14FA5CC68982.dita">Using
wrappers</xref> </p> </section>
</conbody></concept>