aboutsummaryrefslogtreecommitdiffstats
path: root/transcode.c
diff options
context:
space:
mode:
Diffstat (limited to 'transcode.c')
-rw-r--r--transcode.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/transcode.c b/transcode.c
index ca772ce844..aa605f8302 100644
--- a/transcode.c
+++ b/transcode.c
@@ -31,6 +31,48 @@ static VALUE sym_finished;
static VALUE sym_output_followed_by_input;
static VALUE sym_incomplete_input;
+/* dynamic structure, one per conversion (similar to iconv_t) */
+/* may carry conversion state (e.g. for iso-2022-jp) */
+typedef struct rb_transcoding {
+ const rb_transcoder *transcoder;
+
+ int flags;
+
+ int resume_position;
+ unsigned int next_table;
+ VALUE next_info;
+ unsigned char next_byte;
+
+ int recognized_len; /* already interpreted */
+ int readagain_len; /* not yet interpreted */
+ union {
+ unsigned char ary[8]; /* max_input <= sizeof(ary) */
+ unsigned char *ptr; /* length: max_input */
+ } readbuf; /* recognized_len + readagain_len used */
+
+ int writebuf_off;
+ int writebuf_len;
+ union {
+ unsigned char ary[8]; /* max_output <= sizeof(ary) */
+ unsigned char *ptr; /* length: max_output */
+ } writebuf;
+
+ void *state; /* opaque data for stateful encoding */
+} rb_transcoding;
+#define TRANSCODING_READBUF(tc) \
+ ((tc)->transcoder->max_input <= sizeof((tc)->readbuf.ary) ? \
+ (tc)->readbuf.ary : \
+ (tc)->readbuf.ptr)
+#define TRANSCODING_WRITEBUF(tc) \
+ ((tc)->transcoder->max_output <= sizeof((tc)->writebuf.ary) ? \
+ (tc)->writebuf.ary : \
+ (tc)->writebuf.ptr)
+#define TRANSCODING_STATE_EMBED_MAX sizeof(void *)
+#define TRANSCODING_STATE(tc) \
+ ((tc)->transcoder->state_size <= sizeof((tc)->state) ? \
+ (void *)&(tc)->state : \
+ (tc)->state)
+
typedef struct {
struct rb_transcoding *tc;
unsigned char *out_buf_start;