Bump version, write README and update Changes
[convert-base91.git] / Base91.xs
CommitLineData
1a1c8cd6
MG
1#define PERL_NO_GET_CONTEXT
2#include "EXTERN.h"
3#include "perl.h"
4#include "XSUB.h"
5
6#include "ppport.h"
7
8#include <base91.c>
9
10typedef struct base91 {
11 struct basE91 b91;
12 SV* output;
13}* Convert__Base91;
14
22bf75b3 15Convert__Base91 new(pTHX_ SV* class) {
1a1c8cd6
MG
16 Convert__Base91 self;
17 Newxc(self, 1, struct base91, struct base91);
18 basE91_init(&self->b91);
19 self->output = newSVpvs("");
20 return self;
21}
22
22bf75b3 23void encode(pTHX_ Convert__Base91 self, SV* input) {
1a1c8cd6
MG
24 void *o;
25 char* i;
26 size_t len, max_out_len, ret;
27
28 i = SvPVbyte(input, len);
29 max_out_len = len + (len / 4) + 1; /* technically ceil(len * 16 / 13) */
30 Newx(o, max_out_len, char);
31
32 ret = basE91_encode(&self->b91, i, len, o);
33 sv_catpvn_nomg(self->output, o, ret);
34 Safefree(o);
35}
36
22bf75b3 37SV* encode_end(pTHX_ Convert__Base91 self) {
1a1c8cd6
MG
38 char o[2];
39 size_t ret;
40 SV* out;
41 ret = basE91_encode_end(&self->b91, o);
42 sv_catpvn_nomg(self->output, o, ret);
43
44 out = self->output;
45 self->output = newSVpvs("");
46 return out;
47}
48
22bf75b3 49void decode(pTHX_ Convert__Base91 self, SV* input) {
1a1c8cd6
MG
50 void *o;
51 char* i;
52 size_t len, max_out_len, ret;
53
54 i = SvPVbyte(input, len);
55 Newx(o, len, char);
56
57 ret = basE91_decode(&self->b91, i, len, o);
58 sv_catpvn_nomg(self->output, o, ret);
59 Safefree(o);
60}
61
22bf75b3 62SV* decode_end(pTHX_ Convert__Base91 self) {
1a1c8cd6
MG
63 char o;
64 size_t ret;
65 SV* out;
66 ret = basE91_decode_end(&self->b91, &o);
67 sv_catpvn_nomg(self->output, &o, ret);
68
69 out = self->output;
70 self->output = newSVpvs("");
71 return out;
72}
73
22bf75b3 74void DESTROY(pTHX_ Convert__Base91 self) {
1a1c8cd6
MG
75 sv_2mortal(self->output);
76 Safefree(self);
77}
78
79MODULE = Convert::Base91 PACKAGE = Convert::Base91
80PROTOTYPES: ENABLE
81
82Convert::Base91 new(SV* class)
22bf75b3 83C_ARGS: aTHX_ class
1a1c8cd6
MG
84
85void encode(Convert::Base91 self, SV* input)
22bf75b3 86C_ARGS: aTHX_ self, input
1a1c8cd6
MG
87
88SV* encode_end(Convert::Base91 self)
22bf75b3 89C_ARGS: aTHX_ self
1a1c8cd6
MG
90
91void decode(Convert::Base91 self, SV* input)
22bf75b3 92C_ARGS: aTHX_ self, input
1a1c8cd6
MG
93
94SV* decode_end(Convert::Base91 self)
22bf75b3 95C_ARGS: aTHX_ self
1a1c8cd6
MG
96
97void DESTROY(Convert::Base91 self)
22bf75b3 98C_ARGS: aTHX_ self
This page took 0.015546 seconds and 4 git commands to generate.