LCOV - code coverage report
Current view: top level - src/core/surface - byte_buffer.c (source / functions) Hit Total Coverage
Test: tmp.zDYK9MVh93 Lines: 28 33 84.8 %
Date: 2015-10-10 Functions: 5 6 83.3 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  * Copyright 2015, Google Inc.
       4             :  * All rights reserved.
       5             :  *
       6             :  * Redistribution and use in source and binary forms, with or without
       7             :  * modification, are permitted provided that the following conditions are
       8             :  * met:
       9             :  *
      10             :  *     * Redistributions of source code must retain the above copyright
      11             :  * notice, this list of conditions and the following disclaimer.
      12             :  *     * Redistributions in binary form must reproduce the above
      13             :  * copyright notice, this list of conditions and the following disclaimer
      14             :  * in the documentation and/or other materials provided with the
      15             :  * distribution.
      16             :  *     * Neither the name of Google Inc. nor the names of its
      17             :  * contributors may be used to endorse or promote products derived from
      18             :  * this software without specific prior written permission.
      19             :  *
      20             :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
      21             :  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
      22             :  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
      23             :  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
      24             :  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      25             :  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
      26             :  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      27             :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      28             :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      29             :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
      30             :  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      31             :  *
      32             :  */
      33             : 
      34             : #include <grpc/byte_buffer.h>
      35             : #include <grpc/support/alloc.h>
      36             : #include <grpc/support/log.h>
      37             : 
      38     5785021 : grpc_byte_buffer *grpc_raw_byte_buffer_create(gpr_slice *slices,
      39             :                                               size_t nslices) {
      40     5785021 :   return grpc_raw_compressed_byte_buffer_create(slices, nslices,
      41             :                                                 GRPC_COMPRESS_NONE);
      42             : }
      43             : 
      44     5794305 : grpc_byte_buffer *grpc_raw_compressed_byte_buffer_create(
      45             :     gpr_slice *slices, size_t nslices, grpc_compression_algorithm compression) {
      46             :   size_t i;
      47     5794305 :   grpc_byte_buffer *bb = malloc(sizeof(grpc_byte_buffer));
      48     5794305 :   bb->type = GRPC_BB_RAW;
      49     5794305 :   bb->data.raw.compression = compression;
      50     5794305 :   gpr_slice_buffer_init(&bb->data.raw.slice_buffer);
      51    11884471 :   for (i = 0; i < nslices; i++) {
      52     6090878 :     gpr_slice_ref(slices[i]);
      53     6089933 :     gpr_slice_buffer_add(&bb->data.raw.slice_buffer, slices[i]);
      54             :   }
      55     5793593 :   return bb;
      56             : }
      57             : 
      58         841 : grpc_byte_buffer *grpc_raw_byte_buffer_from_reader(
      59             :     grpc_byte_buffer_reader *reader) {
      60         841 :   grpc_byte_buffer *bb = malloc(sizeof(grpc_byte_buffer));
      61             :   gpr_slice slice;
      62         841 :   bb->type = GRPC_BB_RAW;
      63         841 :   bb->data.raw.compression = GRPC_COMPRESS_NONE;
      64         841 :   gpr_slice_buffer_init(&bb->data.raw.slice_buffer);
      65             : 
      66        2931 :   while (grpc_byte_buffer_reader_next(reader, &slice)) {
      67        1249 :     gpr_slice_buffer_add(&bb->data.raw.slice_buffer, slice);
      68             :   }
      69         841 :   return bb;
      70             : }
      71             : 
      72           0 : grpc_byte_buffer *grpc_byte_buffer_copy(grpc_byte_buffer *bb) {
      73           0 :   switch (bb->type) {
      74             :     case GRPC_BB_RAW:
      75           0 :       return grpc_raw_byte_buffer_create(bb->data.raw.slice_buffer.slices,
      76             :                                          bb->data.raw.slice_buffer.count);
      77             :   }
      78           0 :   GPR_UNREACHABLE_CODE(return NULL);
      79             : }
      80             : 
      81     5795344 : void grpc_byte_buffer_destroy(grpc_byte_buffer *bb) {
      82    11594462 :   if (!bb) return;
      83     5794788 :   switch (bb->type) {
      84             :     case GRPC_BB_RAW:
      85     5789257 :       gpr_slice_buffer_destroy(&bb->data.raw.slice_buffer);
      86     5793031 :       break;
      87             :   }
      88     5798562 :   free(bb);
      89             : }
      90             : 
      91     8974802 : size_t grpc_byte_buffer_length(grpc_byte_buffer *bb) {
      92     8974802 :   switch (bb->type) {
      93             :     case GRPC_BB_RAW:
      94     8974802 :       return bb->data.raw.slice_buffer.length;
      95             :   }
      96           0 :   GPR_UNREACHABLE_CODE(return 0);
      97             : }

Generated by: LCOV version 1.10