dl_error_t dl_internal_convert_no_header( dl_ctx_t dl_ctx, unsigned char* packed_instance, unsigned char* packed_instance_base, unsigned char* out_instance, size_t out_instance_size, size_t* needed_size, dl_endian_t src_endian, dl_endian_t out_endian, dl_ptr_size_t src_ptr_size, dl_ptr_size_t out_ptr_size, const SDLType* root_type, size_t base_offset ) { dl_binary_writer writer; dl_binary_writer_init( &writer, out_instance, out_instance_size, out_instance == 0x0, src_endian, out_endian, out_ptr_size ); SConvertContext ConvCtx( src_endian, out_endian, src_ptr_size, out_ptr_size ); ConvCtx.m_lInstances.Add(SInstance(packed_instance, root_type, 0x0, dl_type_t(DL_TYPE_ATOM_POD | DL_TYPE_STORAGE_STRUCT))); dl_error_t err = dl_internal_convert_collect_instances(dl_ctx, root_type, packed_instance, packed_instance_base, ConvCtx); // TODO: we need to sort the instances here after their offset! SInstance* insts = ConvCtx.m_lInstances.GetBasePtr(); std::sort( insts, insts + ConvCtx.m_lInstances.Len(), dl_internal_sort_pred ); for(unsigned int i = 0; i < ConvCtx.m_lInstances.Len(); ++i) { err = dl_internal_convert_write_instance( dl_ctx, ConvCtx.m_lInstances[i], &ConvCtx.m_lInstances[i].m_OffsetAfterPatch, ConvCtx, &writer ); if(err != DL_ERROR_OK) return err; } if(out_instance != 0x0) // no need to patch data if we are only calculating size { for(unsigned int i = 0; i < ConvCtx.m_lPatchOffset.Len(); ++i) { SConvertContext::PatchPos& PP = ConvCtx.m_lPatchOffset[i]; // find new offset pint NewOffset = pint(-1); for(unsigned int j = 0; j < ConvCtx.m_lInstances.Len(); ++j ) { pint OldOffset = ConvCtx.m_lInstances[j].m_pAddress - packed_instance_base; if(OldOffset == PP.m_OldOffset) { NewOffset = ConvCtx.m_lInstances[j].m_OffsetAfterPatch; break; } } DL_ASSERT(NewOffset != pint(-1) && "We should have found the instance!"); dl_binary_writer_seek_set( &writer, PP.m_Pos ); dl_binary_writer_write_ptr( &writer, NewOffset + base_offset ); } } dl_binary_writer_seek_end( &writer ); *needed_size = (unsigned int)dl_binary_writer_tell( &writer ); return err; }
dl_error_t dl_txt_unpack( dl_ctx_t dl_ctx, dl_typeid_t type, const unsigned char* packed_instance, size_t packed_instance_size, char* out_txt_instance, size_t out_txt_instance_size, size_t* produced_bytes ) { dl_data_header* header = (dl_data_header*)packed_instance; if( packed_instance_size < sizeof(dl_data_header) ) return DL_ERROR_MALFORMED_DATA; if( header->id == DL_INSTANCE_ID_SWAPED ) return DL_ERROR_ENDIAN_MISMATCH; if( header->id != DL_INSTANCE_ID ) return DL_ERROR_MALFORMED_DATA; if( header->version != DL_INSTANCE_VERSION) return DL_ERROR_VERSION_MISMATCH; if( header->root_instance_type != type ) return DL_ERROR_TYPE_MISMATCH; dl_binary_writer writer; dl_binary_writer_init( &writer, (uint8_t*)out_txt_instance, out_txt_instance_size, false, DL_ENDIAN_HOST, DL_ENDIAN_HOST, DL_PTR_SIZE_HOST ); dl_txt_unpack_ctx unpackctx; unpackctx.packed_instance = packed_instance + sizeof(dl_data_header); unpackctx.indent = 0; unpackctx.ptrs_count = 0; unpackctx.has_ptrs = false; dl_txt_unpack_root( dl_ctx, &unpackctx, &writer, header->root_instance_type ); if( produced_bytes ) *produced_bytes = writer.needed_size; return DL_ERROR_OK; };
CDLBinStoreContext( uint8* out_data, pint out_data_size, bool is_dummy ) { dl_binary_writer_init( &writer, out_data, out_data_size, is_dummy, DL_ENDIAN_HOST, DL_ENDIAN_HOST, DL_PTR_SIZE_HOST ); }
CDLBinStoreContext( uint8_t* out_data, size_t out_data_size, bool is_dummy ) { dl_binary_writer_init( &writer, out_data, out_data_size, is_dummy, DL_ENDIAN_HOST, DL_ENDIAN_HOST, DL_PTR_SIZE_HOST ); num_written_ptrs = 0; }