Thread overview
What is Base64 part in Base64.encode
May 14, 2017
zabruk70
May 14, 2017
Moritz Maxeiner
May 14, 2017
zabruk70
May 14, 2017
Moritz Maxeiner
May 14, 2017
I look to std.base64 module source.
And dont unerstand what is the "Base64" part in "Base64.encode(data)" example.
I see std.base64 module use template Base64Impl.
I see alias Base64 = Base64Impl!...
But down understand.
Base64 not module, not structure, not class?
Template Base64Impl shoud produce function?

I want create base32 encoder/decoder for example.
But i dont need template.
So how i can write Base32.encode()?
By creating class Base32 with encode() member.
By creating structute Base32 with encode() member.
Any other options?

Thanx.
May 14, 2017
On Sunday, 14 May 2017 at 20:04:07 UTC, zabruk70 wrote:
> I look to std.base64 module source.
> And dont unerstand what is the "Base64" part in "Base64.encode(data)" example.
> I see std.base64 module use template Base64Impl.
> I see alias Base64 = Base64Impl!...
> But down understand.
> Base64 not module, not structure, not class?

The full line is `alias Base64 = Base64Impl!('+', '/');`, which reads as (refer to [1][2]):
The symbol Base64 refers to the Base64Impl template instantiated with the template parameters '+' and '/'.

> Template Base64Impl shoud produce function?

I don't understand what you're trying to express here.
As Base64Impl's documentation states[3], it contains a generic Base64 implementation for which you can customize some of the encoding characters at compile time via template parameters.

>
> I want create base32 encoder/decoder for example.
> But i dont need template.
> So how i can write Base32.encode()?
> By creating class Base32 with encode() member.
> By creating structute Base32 with encode() member.
> Any other options?

You can create a base32 encoder however you like, D has lots of different ways you could approach this; you can even do it in a C way with two functions base32_encode / base32_decode. Just pick whatever you like.

PS: Please spellcheck.

[1] https://dlang.org/spec/declaration.html#alias
[2] https://dlang.org/spec/template.html
[3] https://github.com/dlang/phobos/blob/master/std/base64.d#L108
May 14, 2017
On Sunday, 14 May 2017 at 21:22:20 UTC, Moritz Maxeiner wrote:
> The full line is `alias Base64 = Base64Impl!('+', '/');`

Yes. When we use it like this:

  const(char)[] encoded = Base64.encode(data);

then template instantiated and produce ... what?

> I don't understand what you're trying to express here.

What kind of symbols (class name, structure name, type)
can be used with dot in D language?

What produced by template instantiation `Base64Impl!('+', '/')`
then i use alias `Base64`?

> You can create a base32 encoder however you like, D has lots of different ways you could approach this; you can even do it in a

But i want mimic std.base64 syntax.
I want to write something like

  string encoded = Base32.encode(data);

And i don't want to use template.
May 14, 2017
On Sunday, 14 May 2017 at 21:34:35 UTC, zabruk70 wrote:
> On Sunday, 14 May 2017 at 21:22:20 UTC, Moritz Maxeiner wrote:
>> The full line is `alias Base64 = Base64Impl!('+', '/');`
>
> Yes. When we use it like this:
>
>   const(char)[] encoded = Base64.encode(data);
>
> then template instantiated and produce ... what?

Have you read the language specification I linked to?
Base64 refers to a (fully) parametrized template. If you use the symbol Base64, you will access its instantiation; '.encode' then accesses the member "encode" in the scope of that template instance, which happens to be a function. That function then gets called with "data" as its argument and returns the encoded data.

>
>> I don't understand what you're trying to express here.
>
> What kind of symbols (class name, structure name, type)
> can be used with dot in D language?

Pretty much any symbol. Any type (or alias to one) will at least have properties[1] and any variable will be open to UFCS[2].

>
> What produced by template instantiation `Base64Impl!('+', '/')`
> then i use alias `Base64`?

I'm sorry, but I have no idea what you're trying to convey here.

>
>> You can create a base32 encoder however you like, D has lots of different ways you could approach this; you can even do it in a
>
> But i want mimic std.base64 syntax.
> I want to write something like
>
>   string encoded = Base32.encode(data);
>
> And i don't want to use template.

Then use a struct with static member functions:

struct Base32
{
    static [...] encode([...]) { [...] }
    static [...] decode([...]) { [...] }
}

[1] https://dlang.org/spec/property.html
[2] https://tour.dlang.org/tour/en/gems/uniform-function-call-syntax-ufcs