1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2014 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci// EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL
9cb93a386Sopenharmony_ci// DO NOT USE -- FOR INTERNAL TESTING ONLY
10cb93a386Sopenharmony_ci
11cb93a386Sopenharmony_ci#ifndef sk_data_DEFINED
12cb93a386Sopenharmony_ci#define sk_data_DEFINED
13cb93a386Sopenharmony_ci
14cb93a386Sopenharmony_ci#include "include/c/sk_types.h"
15cb93a386Sopenharmony_ci
16cb93a386Sopenharmony_ciSK_C_PLUS_PLUS_BEGIN_GUARD
17cb93a386Sopenharmony_ci
18cb93a386Sopenharmony_ci/**
19cb93a386Sopenharmony_ci    Returns a new sk_data_t by copying the specified source data.
20cb93a386Sopenharmony_ci    This call must be balanced with a call to sk_data_unref().
21cb93a386Sopenharmony_ci*/
22cb93a386Sopenharmony_ciSK_API sk_data_t* sk_data_new_with_copy(const void* src, size_t length);
23cb93a386Sopenharmony_ci/**
24cb93a386Sopenharmony_ci    Pass ownership of the given memory to a new sk_data_t, which will
25cb93a386Sopenharmony_ci    call free() when the refernce count of the data goes to zero.  For
26cb93a386Sopenharmony_ci    example:
27cb93a386Sopenharmony_ci        size_t length = 1024;
28cb93a386Sopenharmony_ci        void* buffer = malloc(length);
29cb93a386Sopenharmony_ci        memset(buffer, 'X', length);
30cb93a386Sopenharmony_ci        sk_data_t* data = sk_data_new_from_malloc(buffer, length);
31cb93a386Sopenharmony_ci    This call must be balanced with a call to sk_data_unref().
32cb93a386Sopenharmony_ci*/
33cb93a386Sopenharmony_ciSK_API sk_data_t* sk_data_new_from_malloc(const void* memory, size_t length);
34cb93a386Sopenharmony_ci/**
35cb93a386Sopenharmony_ci    Returns a new sk_data_t using a subset of the data in the
36cb93a386Sopenharmony_ci    specified source sk_data_t.  This call must be balanced with a
37cb93a386Sopenharmony_ci    call to sk_data_unref().
38cb93a386Sopenharmony_ci*/
39cb93a386Sopenharmony_ciSK_API sk_data_t* sk_data_new_subset(const sk_data_t* src, size_t offset, size_t length);
40cb93a386Sopenharmony_ci
41cb93a386Sopenharmony_ci/**
42cb93a386Sopenharmony_ci    Increment the reference count on the given sk_data_t. Must be
43cb93a386Sopenharmony_ci    balanced by a call to sk_data_unref().
44cb93a386Sopenharmony_ci*/
45cb93a386Sopenharmony_ciSK_API void sk_data_ref(const sk_data_t*);
46cb93a386Sopenharmony_ci/**
47cb93a386Sopenharmony_ci    Decrement the reference count. If the reference count is 1 before
48cb93a386Sopenharmony_ci    the decrement, then release both the memory holding the sk_data_t
49cb93a386Sopenharmony_ci    and the memory it is managing.  New sk_data_t are created with a
50cb93a386Sopenharmony_ci    reference count of 1.
51cb93a386Sopenharmony_ci*/
52cb93a386Sopenharmony_ciSK_API void sk_data_unref(const sk_data_t*);
53cb93a386Sopenharmony_ci
54cb93a386Sopenharmony_ci/**
55cb93a386Sopenharmony_ci    Returns the number of bytes stored.
56cb93a386Sopenharmony_ci*/
57cb93a386Sopenharmony_ciSK_API size_t sk_data_get_size(const sk_data_t*);
58cb93a386Sopenharmony_ci/**
59cb93a386Sopenharmony_ci    Returns the pointer to the data.
60cb93a386Sopenharmony_ci */
61cb93a386Sopenharmony_ciSK_API const void* sk_data_get_data(const sk_data_t*);
62cb93a386Sopenharmony_ci
63cb93a386Sopenharmony_ciSK_C_PLUS_PLUS_END_GUARD
64cb93a386Sopenharmony_ci
65cb93a386Sopenharmony_ci#endif
66