https://wiki.dlang.org/?title=Converting_byte_arrays&feed=atom&action=historyConverting byte arrays - Revision history2024-03-29T09:03:11ZRevision history for this page on the wikiMediaWiki 1.31.2https://wiki.dlang.org/?title=Converting_byte_arrays&diff=8873&oldid=prevD user: fix typo2018-01-16T06:52:04Z<p>fix typo</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 06:52, 16 January 2018</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Many raw-data reading and decoding functions in D, such as std.base64.decode, std.file.read, and std.zlib.uncompress, return the data as ubyte[].</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Many raw-data reading and decoding functions in D, such as std.base64.decode, std.file.read, and std.zlib.uncompress, return the data as ubyte[].</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>Tip: If a data function returns void[], it is often actually a bug. void[] is fine for accepting data, but it should only be returned when the contents is really unknown and might include pointers. If it is just a byte stream, use ubyte[] instead. If you do have to use a function that <del class="diffchange diffchange-inline">turned </del>void[], first cast it to ubyte[] then follow the tips on this page from there.</div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>Tip: If a data function returns void[], it is often actually a bug. void[] is fine for accepting data, but it should only be returned when the contents is really unknown and might include pointers. If it is just a byte stream, use ubyte[] instead. If you do have to use a function that <ins class="diffchange diffchange-inline">returns </ins>void[], first cast it to ubyte[] then follow the tips on this page from there.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>If you are happy working with a stream of bytes, no other work is necessary. You can simply manipulate the array as-is.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>If you are happy working with a stream of bytes, no other work is necessary. You can simply manipulate the array as-is.</div></td></tr>
</table>D userhttps://wiki.dlang.org/?title=Converting_byte_arrays&diff=7125&oldid=prevAdamdruppe: Created page with "Many raw-data reading and decoding functions in D, such as std.base64.decode, std.file.read, and std.zlib.uncompress, return the data as ubyte[]. Tip: If a data function retu..."2015-12-21T18:15:55Z<p>Created page with "Many raw-data reading and decoding functions in D, such as std.base64.decode, std.file.read, and std.zlib.uncompress, return the data as ubyte[]. Tip: If a data function retu..."</p>
<p><b>New page</b></p><div>Many raw-data reading and decoding functions in D, such as std.base64.decode, std.file.read, and std.zlib.uncompress, return the data as ubyte[].<br />
<br />
Tip: If a data function returns void[], it is often actually a bug. void[] is fine for accepting data, but it should only be returned when the contents is really unknown and might include pointers. If it is just a byte stream, use ubyte[] instead. If you do have to use a function that turned void[], first cast it to ubyte[] then follow the tips on this page from there.<br />
<br />
If you are happy working with a stream of bytes, no other work is necessary. You can simply manipulate the array as-is.<br />
<br />
If you know it represents a UTF-encoded string, std.string.assumeUTF and std.utf.validate can be used to cast it to chars and verify your assumption is correct. validate throws an exception if it is not.<br />
<br />
If it is some other data type, like ints, you can cast, but be mindful of endianness and consider std.bitmanip to convert them.<br />
<br />
You may also be able to paint a struct over it, but be sure there's no indirection. A serialization lib might be right for you.</div>Adamdruppe