Beispiel #1
0
 private static unsafe void BrotliInitMemoryManager(
     ref MemoryManager m, brotli_alloc_func alloc_func, brotli_free_func free_func,
     void *opaque)
 {
     if (alloc_func == null)
     {
         m.alloc_func = DefaultAllocFunc;
         m.free_func  = DefaultFreeFunc;
         m.opaque     = null;
     }
     else
     {
         m.alloc_func = alloc_func;
         m.free_func  = free_func;
         m.opaque     = opaque;
     }
 }
Beispiel #2
0
        private static unsafe void BrotliDecoderStateInitWithCustomAllocators(
            ref BrotliDecoderState s, brotli_alloc_func alloc_func, brotli_free_func free_func,
            void *opaque)
        {
            if (alloc_func == null)
            {
                s.alloc_func            = DefaultAllocFunc;
                s.free_func             = DefaultFreeFunc;
                s.memory_manager_opaque = null;
            }
            else
            {
                s.alloc_func            = alloc_func;
                s.free_func             = free_func;
                s.memory_manager_opaque = opaque;
            }

            fixed(BrotliBitReader *br = &s.br)
            BrotliInitBitReader(br);

            s.state = BrotliRunningState.BROTLI_STATE_UNINITED;
            s.substate_metablock_header  = BrotliRunningMetablockHeaderState.BROTLI_STATE_METABLOCK_HEADER_NONE;
            s.substate_tree_group        = BrotliRunningTreeGroupState.BROTLI_STATE_TREE_GROUP_NONE;
            s.substate_context_map       = BrotliRunningContextMapState.BROTLI_STATE_CONTEXT_MAP_NONE;
            s.substate_uncompressed      = BrotliRunningUncompressedState.BROTLI_STATE_UNCOMPRESSED_NONE;
            s.substate_huffman           = BrotliRunningHuffmanState.BROTLI_STATE_HUFFMAN_NONE;
            s.substate_decode_uint8      = BrotliRunningDecodeUint8State.BROTLI_STATE_DECODE_UINT8_NONE;
            s.substate_read_block_length = BrotliRunningReadBlockLengthState.BROTLI_STATE_READ_BLOCK_LENGTH_NONE;

            s.buffer_length   = 0;
            s.loop_counter    = 0;
            s.pos             = 0;
            s.rb_roundtrips   = 0;
            s.partial_pos_out = 0;

            s.block_type_trees    = null;
            s.block_len_trees     = null;
            s.ringbuffer          = null;
            s.ringbuffer_size     = 0;
            s.new_ringbuffer_size = 0;
            s.ringbuffer_mask     = 0;

            s.context_map            = null;
            s.context_modes          = null;
            s.dist_context_map       = null;
            s.context_map_slice      = null;
            s.dist_context_map_slice = null;

            s.sub_loop_counter = 0;

            s.literal_hgroup.codes      = null;
            s.literal_hgroup.htrees     = null;
            s.insert_copy_hgroup.codes  = null;
            s.insert_copy_hgroup.htrees = null;
            s.distance_hgroup.codes     = null;
            s.distance_hgroup.htrees    = null;

            s.custom_dict      = null;
            s.custom_dict_size = 0;

            s.is_last_metablock      = false;
            s.should_wrap_ringbuffer = false;
            s.window_bits            = 0;
            s.max_distance           = 0;
            fixed(int *rb = s.dist_rb)
            {
                rb[0] = 16;
                rb[1] = 15;
                rb[2] = 11;
                rb[3] = 4;
            }

            s.dist_rb_idx      = 0;
            s.block_type_trees = null;
            s.block_len_trees  = null;

            s.mtf_upper_bound = 63;
        }