static int mmf_write_header(AVFormatContext *s) { MMFContext *mmf = s->priv_data; ByteIOContext *pb = s->pb; int64_t pos; int rate; rate = mmf_rate_code(s->streams[0]->codec->sample_rate); if(rate < 0) { av_log(s, AV_LOG_ERROR, "Unsupported sample rate %d\n", s->streams[0]->codec->sample_rate); return -1; } put_tag(pb, "MMMD"); put_be32(pb, 0); pos = start_tag(pb, "CNTI"); put_byte(pb, 0); /* class */ put_byte(pb, 0); /* type */ put_byte(pb, 0); /* code type */ put_byte(pb, 0); /* status */ put_byte(pb, 0); /* counts */ put_tag(pb, "VN:libavcodec,"); /* metadata ("ST:songtitle,VN:version,...") */ end_tag_be(pb, pos); put_buffer(pb, "ATR\x00", 4); put_be32(pb, 0); mmf->atrpos = url_ftell(pb); put_byte(pb, 0); /* format type */ put_byte(pb, 0); /* sequence type */ put_byte(pb, (0 << 7) | (1 << 4) | rate); /* (channel << 7) | (format << 4) | rate */ put_byte(pb, 0); /* wave base bit */ put_byte(pb, 2); /* time base d */ put_byte(pb, 2); /* time base g */ put_tag(pb, "Atsq"); put_be32(pb, 16); mmf->atsqpos = url_ftell(pb); /* Will be filled on close */ put_buffer(pb, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16); mmf->awapos = start_tag(pb, "Awa\x01"); av_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate); put_flush_packet(pb); return 0; }
static void writeText( ByteStream & str_out, const GUTF8String &textUTF8, const DjVuTXT::Zone &zone, const int WindowHeight ) { // DEBUG_MSG( "--zonetype=" << zone.ztype << "\n" ); const GUTF8String xindent(indent( 2 * zone.ztype + 2 )); GPosition pos=zone.children; // Build attribute string if( ! pos ) { GUTF8String coords; coords.format("coords=\"%d,%d,%d,%d\"", zone.rect.xmin, WindowHeight - 1 - zone.rect.ymin, zone.rect.xmax, WindowHeight - 1 - zone.rect.ymax); const int start=zone.text_start; const int end=textUTF8.firstEndSpace(start,zone.text_length); str_out.writestring(start_tag(zone.ztype,coords)); str_out.writestring(textUTF8.substr(start,end-start).toEscaped()); str_out.writestring(end_tag(zone.ztype)); } else { writeText(str_out,textUTF8,zone.ztype,zone.children,WindowHeight); } }
void tag_update( void ) { char buf[MAX_STRING_LENGTH]; if ( tag_game.next > 0 && tag_game.status == TAG_OFF ) { } else if ( tag_game.status == TAG_ISWAIT ) { tag_game.timer--; if ( tag_game.timer > 0 ) { sprintf( buf, "&R[&WEvento de congelación&R] &C%d minuto%s para comenzar.", tag_game.timer, tag_game.timer == 1 ? "" : "s" ); tag_channel( NULL, buf ); } else { if ( tag_game.playing < 2 ) { end_tag( ); sprintf( buf, "&R[&WEvento de congelación&R] &Cno hay suficientes personas para jugar. Juego cancelado." ); tag_channel( NULL, buf ); return; } else start_tag( ); } } else if ( tag_game.status == TAG_ISPLAY ) { if ( tag_game.playing == 0 ) { end_tag( ); sprintf( buf, "&R[&WEvento de congelación&R] &CNo Nadie juega esta partida, siguiente juego en %d minutos.", tag_game.next ); tag_channel( NULL, buf ); return; } switch ( tag_game.timer ) { case 0: end_tag( ); sprintf( buf, "&R[&WEvento de congelación&R] &Ctiempo para el próximo juego: %d minutos.", tag_game.next ); tag_channel( NULL, buf ); return; case 1: case 2: case 3: case 4: case 5: case 10: case 15: sprintf( buf, "&R[&WEvento de congelación&R]&Y %d &C minuto%s restantes.", tag_game.timer, tag_game.timer > 1 ? "s" : "" ); tag_channel( NULL, buf ); default: tag_game.timer--; break; } } }
static offset_t avi_start_new_riff(AVIContext *avi, ByteIOContext *pb, const char* riff_tag, const char* list_tag) { offset_t loff; int i; avi->riff_id++; for (i=0; i<MAX_STREAMS; i++) avi->indexes[i].entry = 0; avi->riff_start = start_tag(pb, "RIFF"); put_tag(pb, riff_tag); loff = start_tag(pb, "LIST"); put_tag(pb, list_tag); return loff; }
void inline parse_collection(FILE *collection) { char *buffer = new char[BUF_SIZE]; int size = 0; begin_indexing(); char c = getc(collection); while (c != EOF) { size = 0; // Token if (c == '<') { c = getc(collection); // End Tag if (c == '/') { c = getc(collection); while (c != '>' && isalnum(c)) { buffer[size++] = c; c = getc(collection); } if (c == '>') { buffer[size] = '\0'; end_tag(buffer); } else { printf("End tag error\n"); } // Start Tag } else { while (c != '>' && isalnum(c)) { buffer[size++] = c; c = getc(collection); } if (c == '>') { buffer[size] = '\0'; start_tag(buffer); } else { printf("End tag error\n"); } } } // Words // This is lazy, I know; but ambiguous cases are a nearly bottomless rabbit hole. // Furthermore, the WSJ doesn't escape & properly, so nither do I. if (isalpha(c)) { do { buffer[size++] = tolower(c); c = getc(collection); } while(isalpha(c)); buffer[size] = '\0'; word(buffer); continue; } c = getc(collection); } end_indexing(); }
void config_write_start_tag(struct writeconfig *wc, const char *entity, GHashTable *attr) { GString *outstr = g_string_sized_new(128); start_tag(outstr, entity, attr); g_string_append(outstr, "\n"); config_write(wc, outstr->str); g_string_free(outstr, TRUE); }
void DjVuTXT::writeText(ByteStream &str_out,const int height) const { if(has_valid_zones()) { ::writeText(str_out,textUTF8,DjVuTXT::PAGE,page_zone.children,height); }else { str_out.writestring(start_tag(DjVuTXT::PAGE)); str_out.writestring(end_tag(DjVuTXT::PAGE)); } }
void config_write_int(struct writeconfig *wc, int value, const char *entity, GHashTable *attr) { GString *outstr = g_string_sized_new(128); start_tag(outstr, entity, attr); g_string_sprintfa(outstr, "%d", value); end_tag(outstr, entity); config_write(wc, outstr->str); g_string_free(outstr, TRUE); }
static int wav_write_header(AVFormatContext *s) { WAVContext *wav = s->priv_data; ByteIOContext *pb = s->pb; int64_t fmt, fact; put_tag(pb, "RIFF"); put_le32(pb, 0); /* file length */ put_tag(pb, "WAVE"); /* format header */ fmt = start_tag(pb, "fmt "); if (put_wav_header(pb, s->streams[0]->codec) < 0) { av_log(s, AV_LOG_ERROR, "%s codec not supported in WAVE format\n", s->streams[0]->codec->codec ? s->streams[0]->codec->codec->name : "NONE"); av_free(wav); return -1; } end_tag(pb, fmt); if(s->streams[0]->codec->codec_tag != 0x01 /* hence for all other than PCM */ && !url_is_streamed(s->pb)) { fact = start_tag(pb, "fact"); put_le32(pb, 0); end_tag(pb, fact); } av_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate); wav->maxpts = wav->last_duration = 0; wav->minpts = INT64_MAX; /* data header */ wav->data = start_tag(pb, "data"); put_flush_packet(pb); return 0; }
static GUTF8String tolayer(int &layer, const DjVuTXT::ZoneType next_layer) { GUTF8String retval; for( ;layer < (int)next_layer;layer++ ) { retval+=start_tag(layer); } while (layer > (int)next_layer ) { retval+=end_tag(--layer); } return retval; }
// xml_output_stream interface void write(xml_event const& ev) { switch( ev.type ) { case xml_event::START_ELEMENT: start_tag(ev.content, ev.attributes); break; case xml_event::END_ELEMENT: end_tag(ev.content); break; case xml_event::CDATA: char_data(ev.content); break; default: assert(false); } }
static int avi_write_idx1(AVFormatContext *s) { ByteIOContext *pb = &s->pb; AVIContext *avi = s->priv_data; offset_t idx_chunk; int i; char tag[5]; if (!url_is_streamed(pb)) { AVIIentry* ie = 0, *tie; int entry[MAX_STREAMS]; int empty, stream_id = -1; idx_chunk = start_tag(pb, "idx1"); memset(&entry[0], 0, sizeof(entry)); do { empty = 1; for (i=0; i<s->nb_streams; i++) { if (avi->indexes[i].entry <= entry[i]) continue; tie = avi_get_ientry(&avi->indexes[i], entry[i]); if (empty || tie->pos < ie->pos) { ie = tie; stream_id = i; } empty = 0; } if (!empty) { avi_stream2fourcc(&tag[0], stream_id, s->streams[stream_id]->codec->codec_type); put_tag(pb, &tag[0]); put_le32(pb, ie->flags); put_le32(pb, ie->pos); put_le32(pb, ie->len); entry[stream_id]++; } } while (!empty); end_tag(pb, idx_chunk); avi_write_counters(s, avi->riff_id); } return 0; }
void config_write_string(struct writeconfig *wc, const char *value, const char *entity, GHashTable *attr) { GString *outstr = g_string_sized_new(1024); gunichar c; start_tag(outstr, entity, attr); for(c = g_utf8_get_char(value); c ; value = g_utf8_next_char(value), c = g_utf8_get_char(value)) { switch(c) { case '<': g_string_append(outstr, "<"); break; case '>': g_string_append(outstr, ">"); break; case '&': g_string_append(outstr, "&"); break; case '\'': g_string_append(outstr, "'"); break; case '"': g_string_append(outstr, """); break; default: g_string_append_unichar(outstr, c); } } end_tag(outstr, entity); config_write(wc, outstr->str); g_string_free(outstr, TRUE); }
void parse(FILE *stream) { char buffer[MAX_WORD_LEN]; int c = 0, index = 0; while (EOF != (c = tolower(getc(stream)))) { switch (c) { case '<': /* Tags */ /* End the current word */ if (index) { buffer[index] = '\0'; clean_word(buffer); word(buffer); index = 0; } /* Get the next character and decide what to do next */ c = getc(stream); /* Case doesn't matter here */ switch (c) { case '/': /* End tags */ tag_section(buffer, stream); end_tag(buffer); break; default: /* Start tags */ c = ungetc(c, stream); if (EOF != c) { tag_section(buffer, stream); start_tag(buffer); } break; } break; case '&': /* Entity references */ entity_ref(stream); /*if (39 == entity_ref(stream)) ungetc(39, stream);*/ break; default: /* Plain text */ if (index == MAX_WORD_LEN) { fprintf(stderr, "Maximum word length exceeded!\n"); exit(EXIT_FAILURE); } if (isalnum(c) || c == 39) { if (c != 39 || index) { /* no ' allowed at the start */ buffer[index++] = c; } } else if (index) { buffer[index] = '\0'; clean_word(buffer); word(buffer); index = 0; } break; } } if (!feof(stream)) { /* Stop due to an error! */ perror("Parsing failure"); exit(EXIT_FAILURE); } }
static int avi_write_header(AVFormatContext *s) { AVIContext *avi = s->priv_data; ByteIOContext *pb = &s->pb; int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale; AVCodecContext *stream, *video_enc; offset_t list1, list2, strh, strf; /* header list */ avi->riff_id = 0; list1 = avi_start_new_riff(avi, pb, "AVI ", "hdrl"); /* avi header */ put_tag(pb, "avih"); put_le32(pb, 14 * 4); bitrate = 0; video_enc = NULL; for(n=0;n<s->nb_streams;n++) { stream = s->streams[n]->codec; bitrate += stream->bit_rate; if (stream->codec_type == CODEC_TYPE_VIDEO) video_enc = stream; } nb_frames = 0; if(video_enc){ put_le32(pb, (uint32_t)(INT64_C(1000000) * video_enc->time_base.num / video_enc->time_base.den)); } else { put_le32(pb, 0); } put_le32(pb, bitrate / 8); /* XXX: not quite exact */ put_le32(pb, 0); /* padding */ if (url_is_streamed(pb)) put_le32(pb, AVIF_TRUSTCKTYPE | AVIF_ISINTERLEAVED); /* flags */ else put_le32(pb, AVIF_TRUSTCKTYPE | AVIF_HASINDEX | AVIF_ISINTERLEAVED); /* flags */ avi->frames_hdr_all = url_ftell(pb); /* remember this offset to fill later */ put_le32(pb, nb_frames); /* nb frames, filled later */ put_le32(pb, 0); /* initial frame */ put_le32(pb, s->nb_streams); /* nb streams */ put_le32(pb, 1024 * 1024); /* suggested buffer size */ if(video_enc){ put_le32(pb, video_enc->width); put_le32(pb, video_enc->height); } else { put_le32(pb, 0); put_le32(pb, 0); } put_le32(pb, 0); /* reserved */ put_le32(pb, 0); /* reserved */ put_le32(pb, 0); /* reserved */ put_le32(pb, 0); /* reserved */ /* stream list */ for(i=0;i<n;i++) { list2 = start_tag(pb, "LIST"); put_tag(pb, "strl"); stream = s->streams[i]->codec; /* FourCC should really be set by the codec itself */ if (! stream->codec_tag) { stream->codec_tag = codec_get_bmp_tag(stream->codec_id); } /* stream generic header */ strh = start_tag(pb, "strh"); switch(stream->codec_type) { case CODEC_TYPE_VIDEO: put_tag(pb, "vids"); break; case CODEC_TYPE_AUDIO: put_tag(pb, "auds"); break; // case CODEC_TYPE_TEXT : put_tag(pb, "txts"); break; case CODEC_TYPE_DATA : put_tag(pb, "dats"); break; } if(stream->codec_type == CODEC_TYPE_VIDEO) put_le32(pb, stream->codec_tag); else put_le32(pb, 1); put_le32(pb, 0); /* flags */ put_le16(pb, 0); /* priority */ put_le16(pb, 0); /* language */ put_le32(pb, 0); /* initial frame */ ff_parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale); put_le32(pb, au_scale); /* scale */ put_le32(pb, au_byterate); /* rate */ av_set_pts_info(s->streams[i], 64, au_scale, au_byterate); put_le32(pb, 0); /* start */ avi->frames_hdr_strm[i] = url_ftell(pb); /* remember this offset to fill later */ if (url_is_streamed(pb)) put_le32(pb, AVI_MAX_RIFF_SIZE); /* FIXME: this may be broken, but who cares */ else put_le32(pb, 0); /* length, XXX: filled later */ /* suggested buffer size */ //FIXME set at the end to largest chunk if(stream->codec_type == CODEC_TYPE_VIDEO) put_le32(pb, 1024 * 1024); else if(stream->codec_type == CODEC_TYPE_AUDIO) put_le32(pb, 12 * 1024); else put_le32(pb, 0); put_le32(pb, -1); /* quality */ put_le32(pb, au_ssize); /* sample size */ put_le32(pb, 0); put_le16(pb, stream->width); put_le16(pb, stream->height); end_tag(pb, strh); if(stream->codec_type != CODEC_TYPE_DATA){ strf = start_tag(pb, "strf"); switch(stream->codec_type) { case CODEC_TYPE_VIDEO: put_bmp_header(pb, stream, codec_bmp_tags, 0); break; case CODEC_TYPE_AUDIO: if (put_wav_header(pb, stream) < 0) { av_free(avi); return -1; } break; default: return -1; } end_tag(pb, strf); } if (!url_is_streamed(pb)) { unsigned char tag[5]; int j; /* Starting to lay out AVI OpenDML master index. * We want to make it JUNK entry for now, since we'd * like to get away without making AVI an OpenDML one * for compatibility reasons. */ avi->indexes[i].entry = avi->indexes[i].ents_allocated = 0; avi->indexes[i].indx_start = start_tag(pb, "JUNK"); put_le16(pb, 4); /* wLongsPerEntry */ put_byte(pb, 0); /* bIndexSubType (0 == frame index) */ put_byte(pb, 0); /* bIndexType (0 == AVI_INDEX_OF_INDEXES) */ put_le32(pb, 0); /* nEntriesInUse (will fill out later on) */ put_tag(pb, avi_stream2fourcc(&tag[0], i, stream->codec_type)); /* dwChunkId */ put_le64(pb, 0); /* dwReserved[3] put_le32(pb, 0); Must be 0. */ for (j=0; j < AVI_MASTER_INDEX_SIZE * 2; j++) put_le64(pb, 0); end_tag(pb, avi->indexes[i].indx_start); } end_tag(pb, list2); } if (!url_is_streamed(pb)) { /* AVI could become an OpenDML one, if it grows beyond 2Gb range */ avi->odml_list = start_tag(pb, "JUNK"); put_tag(pb, "odml"); put_tag(pb, "dmlh"); put_le32(pb, 248); for (i = 0; i < 248; i+= 4) put_le32(pb, 0); end_tag(pb, avi->odml_list); } end_tag(pb, list1); list2 = start_tag(pb, "LIST"); put_tag(pb, "INFO"); avi_write_info_tag(pb, "INAM", s->title); avi_write_info_tag(pb, "IART", s->author); avi_write_info_tag(pb, "ICOP", s->copyright); avi_write_info_tag(pb, "ICMT", s->comment); avi_write_info_tag(pb, "IPRD", s->album); avi_write_info_tag(pb, "IGNR", s->genre); if (s->track) { char str_track[4]; snprintf(str_track, 4, "%d", s->track); avi_write_info_tag(pb, "IPRT", str_track); } if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) avi_write_info_tag(pb, "ISFT", LIBAVFORMAT_IDENT); end_tag(pb, list2); /* some padding for easier tag editing */ list2 = start_tag(pb, "JUNK"); for (i = 0; i < 1016; i += 4) put_le32(pb, 0); end_tag(pb, list2); avi->movi_list = start_tag(pb, "LIST"); put_tag(pb, "movi"); put_flush_packet(pb); return 0; }
static int avi_write_idx1(AVFormatContext *s) { ByteIOContext *pb = &s->pb; AVIContext *avi = s->priv_data; offset_t file_size, idx_chunk; int i, n, nb_frames, au_byterate, au_ssize, au_scale; AVCodecContext *stream; unsigned char tag[5]; if (!url_is_streamed(pb)) { AVIIentry* ie = 0, *tie; int entry[MAX_STREAMS]; int empty, stream_id = -1; idx_chunk = start_tag(pb, "idx1"); memset(&entry[0], 0, sizeof(entry)); do { empty = 1; for (i=0; i<s->nb_streams; i++) { if (avi->indexes[i].entry <= entry[i]) continue; tie = avi_get_ientry(&avi->indexes[i], entry[i]); if (empty || tie->pos < ie->pos) { ie = tie; stream_id = i; } empty = 0; } if (!empty) { avi_stream2fourcc(&tag[0], stream_id, s->streams[stream_id]->codec.codec_type); put_tag(pb, &tag[0]); put_le32(pb, ie->flags); put_le32(pb, ie->pos); put_le32(pb, ie->len); entry[stream_id]++; } } while (!empty); end_tag(pb, idx_chunk); /* Fill in frame/sample counters */ file_size = url_ftell(pb); nb_frames = 0; for(n=0;n<s->nb_streams;n++) { if (avi->frames_hdr_strm[n] != 0) { stream = &s->streams[n]->codec; url_fseek(pb, avi->frames_hdr_strm[n], SEEK_SET); if (stream->codec_type == CODEC_TYPE_VIDEO) { put_le32(pb, stream->frame_number); if (nb_frames < stream->frame_number) nb_frames = stream->frame_number; } else { if (stream->codec_id == CODEC_ID_MP2 || stream->codec_id == CODEC_ID_MP3) { put_le32(pb, stream->frame_number); nb_frames += stream->frame_number; } else { parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale); put_le32(pb, avi->audio_strm_length[n] / au_ssize); } } } } if (avi->frames_hdr_all != 0) { url_fseek(pb, avi->frames_hdr_all, SEEK_SET); put_le32(pb, nb_frames); } url_fseek(pb, file_size, SEEK_SET); } return 0; }
void xml_writer_impl::write_element(const variant& element) { try { if (element.is<variant::Collection>() && element.empty() && element.type() != variant::DataTable) { write_empty_element(); return; } switch(element.type()) { case variant::None: { write_empty_element(); break; } case variant::Any: case variant::String: { if (element.as<std::string>().empty()) { write_empty_element(); break; } } case variant::Float: case variant::Double: case variant::Int32: case variant::UInt32: case variant::Int64: case variant::UInt64: case variant::Boolean: case variant::Date: case variant::Time: case variant::DateTime: { m_os << start_tag(); write_text(element); m_os << end_tag(); break; } case variant::Dictionary: case variant::Bag: { if ((m_mode & xml_mode::Preserve)!=0) { if (element.has_key(xml_attributes)) { m_stack.top().m_attributes = element[xml_attributes]; if (element.size()==1) { write_empty_element(); break; } } m_os << start_tag(); bool prev_is_text = false; variant::const_iterator it, end(element.end()); for (it=element.begin(); it!=end; ++it) { if (it.key()==xml_attributes) { continue; } else if (it.key()==xml_text) { write_text(it.value()); prev_is_text = true; } else if (it.key()==xml_instruction) { push(it.key()); if (!prev_is_text) { m_os << indent(); } write_instruction(it.value()); prev_is_text = false; pop(); } else if (it.key()==xml_comment) { push(it.key()); if (!prev_is_text) { m_os << indent(); } write_comment(it.value()); prev_is_text = false; pop(); } else { push(it.key()); if (!prev_is_text) { m_os << indent(); } write_element(it.value()); prev_is_text = false; pop(); } } if (!prev_is_text) { m_os << indent(); } m_os << end_tag(); } else { m_os << start_tag(); variant::const_iterator it, end(element.end()); for (it=element.begin(); it!=end; ++it) { push(it.key()); m_os << indent(); write_variant(it.value()); pop(); } m_os << indent() << end_tag(); } break; } case variant::List: { m_os << start_tag(); BOOST_FOREACH(const variant& item, element) { push(); m_os << indent(); write_variant(item); pop(); } m_os << indent(); m_os << end_tag(); break; } case variant::Tuple: { m_stack.top().m_attributes.insert("size", variant(element.size())); m_os << start_tag(); BOOST_FOREACH(const variant& item, element) { push(); m_os << indent(); write_variant(item); pop(); } m_os << indent(); m_os << end_tag(); break; } case variant::TimeSeries: { m_os << start_tag(); variant::const_iterator it, end = element.end(); for (it=element.begin(); it!=end; ++it) { push().insert("time", variant(it.time())); m_os << indent(); write_variant(it.value()); pop(); } m_os << indent(); m_os << end_tag(); break; } case variant::DataTable: { const data_table& dt = element.m_value.get<variant::DataTable>(); m_stack.top().m_attributes .insert("rows", variant(dt.size())) .insert("columns", variant(dt.columns().size())); m_os << start_tag(); if (!dt.columns().empty()) { push("Columns"); m_os << indent() << start_tag(); for (data_table::column_container_type::const_iterator column_iter = dt.columns().begin() ; column_iter != dt.columns().end() ; ++column_iter) { push("Column") .insert("name", variant(column_iter->name())) .insert("type", variant(variant::enum_to_string(column_iter->type()))); m_os << indent(); write_empty_element(); pop(); } m_os << indent() << end_tag(); pop(); } for (data_table::column_container_type::const_iterator column_iter = dt.columns().begin() ; column_iter != dt.columns().end() ; ++column_iter) { push("Column").insert("name", variant(column_iter->name())); m_os << indent() << start_tag(); if (column_iter->type() & variant_base::Primitive) { boost::scoped_ptr<data_table_column_writer> column_writer( make_data_table_column_stream_writer(*column_iter, m_os) ); while (column_writer->has_next()) { push("V"); m_os << indent() << start_tag(); column_writer->write(); m_os << end_tag(); pop(); column_writer->advance(); } } else { variant::const_iterator iter(column_iter->begin()); variant::const_iterator end(column_iter->end()); while (iter != end) { push("V"); m_os << indent(); write_variant(*(iter++)); pop(); } } m_os << indent() << end_tag(); pop(); } m_os << indent(); m_os << end_tag(); break; } case variant::Buffer: { m_os << start_tag(); const void *data = element.as<void*>(); size_t size = element.size(); if (data!=nullptr && size>0) { unsigned int n = 0; boost::scoped_ptr<char> b64(detail::b64_encode((const char*)data, (unsigned int)size, &n)); if (!b64.get()) { boost::throw_exception(variant_error("Unable to base64 encode data")); } m_os << b64.get(); } m_os << end_tag(); break; } case variant::Object: { const object& obj(element.as<object>()); // write class name m_stack.top().m_attributes .insert("class", variant(obj.name())) .insert("version", variant(obj.version())); m_os << start_tag(); // write parameter dictionary variant params; obj.deflate(params); push("params"); m_os << indent(); write_variant(params); pop(); m_os << indent(); m_os << end_tag(); break; } case variant::Exception: { m_os << start_tag(); exception_data e(element.as<exception_data>()); push("type"); m_os << indent(); write_element(variant(e.type())); pop(); push("message"); m_os << indent(); write_element(variant(e.message())); pop(); if (!e.source().empty()) { push("source"); m_os << indent(); write_element(variant(e.source())); pop(); } if (!e.stack().empty()) { push("stack"); m_os << indent(); write_element(variant(e.stack())); pop(); } m_os << indent(); m_os << end_tag(); break; } case variant::Array: { const typed_array& a(element.as<typed_array>()); m_stack.top().m_attributes .insert("size", variant(a.size())) .insert("type", variant(variant::enum_to_string(a.type()))); m_os << start_tag(); for (size_t i=0; i<a.size(); ++i) { push(); m_os << indent(); write_element(variant(a[i])); pop(); } m_os << indent(); m_os << end_tag(); break; } default: boost::throw_exception(variant_error("Case exhaustion: " + variant::enum_to_string(element.type()))); }
static inline GUTF8String start_tag(const int layer) { return start_tag((const DjVuTXT::ZoneType)layer); }