core_foundation_sys/
data.rs

1// Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution.
3//
4// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7// option. This file may not be copied, modified, or distributed
8// except according to those terms.
9
10use crate::base::{CFAllocatorRef, CFIndex, CFOptionFlags, CFRange, CFTypeID};
11use std::os::raw::c_void;
12
13#[repr(C)]
14pub struct __CFData(c_void);
15
16pub type CFDataRef = *const __CFData;
17pub type CFMutableDataRef = *mut __CFData;
18pub type CFDataSearchFlags = CFOptionFlags;
19
20// typedef CF_OPTIONS(CFOptionFlags, CFDataSearchFlags)
21pub const kCFDataSearchBackwards: CFDataSearchFlags = 1usize << 0;
22pub const kCFDataSearchAnchored: CFDataSearchFlags = 1usize << 1;
23
24extern "C" {
25    /*
26     * CFData.h
27     */
28
29    /* CFData */
30    /* Creating a CFData Object */
31    pub fn CFDataCreate(allocator: CFAllocatorRef, bytes: *const u8, length: CFIndex) -> CFDataRef;
32    pub fn CFDataCreateCopy(allocator: CFAllocatorRef, theData: CFDataRef) -> CFDataRef;
33    pub fn CFDataCreateWithBytesNoCopy(
34        allocator: CFAllocatorRef,
35        bytes: *const u8,
36        length: CFIndex,
37        bytesDeallocator: CFAllocatorRef,
38    ) -> CFDataRef;
39
40    /* Examining a CFData Object */
41    pub fn CFDataGetBytePtr(theData: CFDataRef) -> *const u8;
42    pub fn CFDataGetBytes(theData: CFDataRef, range: CFRange, buffer: *mut u8);
43    pub fn CFDataGetLength(theData: CFDataRef) -> CFIndex;
44    pub fn CFDataFind(
45        theData: CFDataRef,
46        dataToFind: CFDataRef,
47        searchRange: CFRange,
48        compareOptions: CFDataSearchFlags,
49    ) -> CFRange;
50
51    /* Getting the CFData Type ID */
52    pub fn CFDataGetTypeID() -> CFTypeID;
53
54    /* CFMutableData */
55    /* Creating a Mutable Data Object */
56    pub fn CFDataCreateMutable(allocator: CFAllocatorRef, capacity: CFIndex) -> CFMutableDataRef;
57    pub fn CFDataCreateMutableCopy(
58        allocator: CFAllocatorRef,
59        capacity: CFIndex,
60        theData: CFDataRef,
61    ) -> CFMutableDataRef;
62
63    /* Accessing Data */
64    pub fn CFDataGetMutableBytePtr(theData: CFMutableDataRef) -> *mut u8;
65
66    /* Modifying a Mutable Data Object */
67    pub fn CFDataAppendBytes(theData: CFMutableDataRef, bytes: *const u8, length: CFIndex);
68    pub fn CFDataDeleteBytes(theData: CFMutableDataRef, range: CFRange);
69    pub fn CFDataReplaceBytes(
70        theData: CFMutableDataRef,
71        range: CFRange,
72        newBytes: *const u8,
73        newLength: CFIndex,
74    );
75    pub fn CFDataIncreaseLength(theData: CFMutableDataRef, extraLength: CFIndex);
76    pub fn CFDataSetLength(theData: CFMutableDataRef, length: CFIndex);
77}