OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef MOJO_PUBLIC_C_BINDINGS_BUFFER_H_ | |
6 #define MOJO_PUBLIC_C_BINDINGS_BUFFER_H_ | |
7 | |
8 #include <mojo/macros.h> | |
9 #include <mojo/system/handle.h> | |
10 #include <stdint.h> | |
11 | |
12 MOJO_BEGIN_EXTERN_C | |
13 | |
14 // |MojomBuffer| is used to track a buffer state for mojom serialization. The | |
15 // user must initialize this struct themselves. See the fields for details. | |
16 struct MojomBuffer { | |
17 char* buf; | |
18 // The number of bytes described by |buf|. | |
19 uint32_t buf_size; | |
20 // Must be initialized to 0. MojomBuffer_Allocate() will update it as it | |
21 // consumes |buf|. | |
22 uint32_t num_bytes_used; | |
23 }; | |
24 | |
25 // Allocates |num_bytes| (rounded up to 8 bytes) from |buf|. Returns NULL if | |
26 // there isn't enough space left to allocate. | |
27 void* MojomBuffer_Allocate(struct MojomBuffer* buf, uint32_t num_bytes); | |
28 | |
29 // |MojomHandleBuffer| is used to track handle offsets during serialization. | |
30 // Handles are moved into the |handles| array, and are referred to by index | |
31 // into the array. The user must initialize this struct themselves. See the | |
32 // fields for details. | |
33 struct MojomHandleBuffer { | |
34 // |handles| must contain enough space to store all the valid MojoHandles | |
35 // encountered during serialization. | |
36 MojoHandle* handles; | |
37 // Size of the |handles| array. | |
38 uint32_t num_handles; | |
39 // The number of handles used so far in |handles|. As handles are moved into | |
40 // |handles|, this counter is incremented. The caller can use it to determine | |
41 // how many handles were moved into |handles| after serialization. This | |
42 // counter must be initialized appropriately before the struct can be used. | |
43 uint32_t num_handles_used; | |
44 }; | |
45 | |
46 MOJO_END_EXTERN_C | |
47 | |
48 #endif // MOJO_PUBLIC_C_BINDINGS_BUFFER_H_ | |
OLD | NEW |