View source code
Display the source code in std/base64.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
std.base64.base64_impl.decode - multiple declarations
- Function Base64Impl.decode
- Function Base64Impl.decode
- Function Base64Impl.decode
Function Base64Impl.decode
Decodes source into the given buffer.
Prototypes
ubyte[] decode(R1, R2)( R1 source, R2 buffer ) pure @trusted if (isArray!R1 && is(ElementType!R1 : dchar) && is(R2 == ubyte[]) && isOutputRange!(R2, ubyte)); ubyte[] decode(R1, R2)( R1 source, R2 buffer ) if (!isArray!R1 && isInputRange!R1 && is(ElementType!R1 : dchar) && hasLength!R1 && is(R2 == ubyte[]) && isOutputRange!(R2, ubyte));
Parameters
| Name | Description |
|---|---|
| source | The input range to decode. |
| buffer | The buffer to store decoded result. |
Returns
The slice of buffer containing the decoded result.
Throws
if Base64Exceptionsource contains characters outside the
base alphabet of the current Base64 encoding scheme.
Example
auto encoded = "Gis8TV1u"; ubyte[32] buffer; // much bigger than necessary // Just to be sure... auto decodedLength = Base64.decodeLength(encoded.length); assert(buffer.length >= decodedLength); // decode() returns a slice of the given buffer. auto decoded = Base64.decode(encoded, buffer[]); assert(decoded is buffer[0 .. decodedLength]); assert(decoded == [0x1a, 0x2b, 0x3c, 0x4d, 0x5d, 0x6e]);
Function Base64Impl.decode
Decodes source into a given
output range.
Prototypes
size_t decode(R1, R2)( R1 source, R2 range ) if (isArray!R1 && is(ElementType!R1 : dchar) && !is(R2 == ubyte[]) && isOutputRange!(R2, ubyte)); size_t decode(R1, R2)( R1 source, R2 range ) if (!isArray!R1 && isInputRange!R1 && is(ElementType!R1 : dchar) && hasLength!R1 && !is(R2 == ubyte[]) && isOutputRange!(R2, ubyte));
Parameters
| Name | Description |
|---|---|
| source | The input
range to decode. |
| range | The output
range to store the decoded result. |
Returns
The number of times the output range's put method was invoked.
Throws
if Base64Exceptionsource contains characters outside the
base alphabet of the current Base64 encoding scheme.
Example
struct OutputRange
{
ubyte[] result;
void put(ubyte b) { result ~= b; }
}
OutputRange output;
// This overload of decode() returns the number of calls to put().
assert(Base64.decode("Gis8TV1u", output) == 6);
assert(output.result == [0x1a, 0x2b, 0x3c, 0x4d, 0x5d, 0x6e]);
Function Base64Impl.decode
Decodes source into newly-allocated buffer.
This convenience method alleviates the need to manually manage decoding buffers.
Prototypes
ubyte[] decode(Range)( Range source ) pure @safe if (isArray!Range && is(ElementType!Range : dchar)); ubyte[] decode(Range)( Range source ) if (!isArray!Range && isInputRange!Range && is(ElementType!Range : dchar) && hasLength!Range);
Parameters
| Name | Description |
|---|---|
| source | The input range to decode. |
Returns
A newly-allocated ubyte[] buffer containing the decoded string.
Example
auto data = "Gis8TV1u"; assert(Base64.decode(data) == [0x1a, 0x2b, 0x3c, 0x4d, 0x5d, 0x6e]);
Authors
Masahiro Nakagawa, Daniel Murphy (Single value Encoder and Decoder)