2f1e53f4f9ff6746766cc22ad9de7f925183cb8f
[platform/upstream/iotjs.git] / tools / src / module / iotjs_module_buffer.h
1 /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #ifndef IOTJS_MODULE_BUFFER_H
17 #define IOTJS_MODULE_BUFFER_H
18
19
20 #include "iotjs_objectwrap.h"
21
22
23 typedef struct {
24   iotjs_jobjectwrap_t jobjectwrap;
25   char* buffer;
26   size_t length;
27 } IOTJS_VALIDATED_STRUCT(iotjs_bufferwrap_t);
28
29
30 iotjs_bufferwrap_t* iotjs_bufferwrap_create(const iotjs_jval_t* jbuiltin,
31                                             size_t length);
32
33 iotjs_bufferwrap_t* iotjs_bufferwrap_from_jbuiltin(
34     const iotjs_jval_t* jbuiltin);
35 iotjs_bufferwrap_t* iotjs_bufferwrap_from_jbuffer(const iotjs_jval_t* jbuffer);
36
37 iotjs_jval_t* iotjs_bufferwrap_jbuiltin(iotjs_bufferwrap_t* bufferwrap);
38 iotjs_jval_t iotjs_bufferwrap_jbuffer(iotjs_bufferwrap_t* bufferwrap);
39
40 char* iotjs_bufferwrap_buffer(iotjs_bufferwrap_t* bufferwrap);
41 size_t iotjs_bufferwrap_length(iotjs_bufferwrap_t* bufferwrap);
42
43 int iotjs_bufferwrap_compare(const iotjs_bufferwrap_t* bufferwrap,
44                              const iotjs_bufferwrap_t* other);
45
46 size_t iotjs_bufferwrap_copy(iotjs_bufferwrap_t* bufferwrap, const char* src,
47                              size_t len);
48
49 // Create buffer object.
50 iotjs_jval_t iotjs_bufferwrap_create_buffer(size_t len);
51
52
53 #endif /* IOTJS_MODULE_BUFFER_H */