S2OPC OPCUA Toolkit
sopc_buffer.h
Go to the documentation of this file.
1 /*
2  * Licensed to Systerel under one or more contributor license
3  * agreements. See the NOTICE file distributed with this work
4  * for additional information regarding copyright ownership.
5  * Systerel licenses this file to you under the Apache
6  * License, Version 2.0 (the "License"); you may not use this
7  * file except in compliance with the License. You may obtain
8  * a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
26 #ifndef SOPC_BUFFER_H_
27 #define SOPC_BUFFER_H_
28 
29 #include <stdbool.h>
30 #include <stdint.h>
31 
32 #include "sopc_enums.h"
33 
37 typedef struct
38 {
39  uint32_t initial_size;
40  uint32_t current_size;
41  uint32_t maximum_size;
42  uint32_t position;
43  uint32_t length;
44  uint8_t* data;
45 } SOPC_Buffer;
46 
54 
62 SOPC_Buffer* SOPC_Buffer_CreateResizable(uint32_t initial_size, uint32_t maximum_size);
63 
76 SOPC_Buffer* SOPC_Buffer_Attach(uint8_t* data, uint32_t size);
77 
84 
91 
99 
110 
121 
132 
143 
155 SOPC_ReturnStatus SOPC_Buffer_Write(SOPC_Buffer* buffer, const uint8_t* data_src, uint32_t count);
156 
169 SOPC_ReturnStatus SOPC_Buffer_Read(uint8_t* data_dest, SOPC_Buffer* buffer, uint32_t count);
170 
181 
196 
205 
215 int64_t SOPC_Buffer_ReadFrom(SOPC_Buffer* buffer, SOPC_Buffer* src, uint32_t n);
216 
227 
240 
254 
279 
280 #endif /* SOPC_BUFFER_H_ */
SOPC_Buffer::current_size
uint32_t current_size
Definition: sopc_buffer.h:40
SOPC_Buffer_Delete
void SOPC_Buffer_Delete(SOPC_Buffer *buffer)
Deallocate buffer and its data bytes content (Clear + deallocate pointer)
SOPC_Buffer_Reset
void SOPC_Buffer_Reset(SOPC_Buffer *buffer)
Reset length, position and data bytes to zero value of an allocated buffer.
SOPC_Buffer_GetPosition
SOPC_ReturnStatus SOPC_Buffer_GetPosition(SOPC_Buffer *buffer, uint32_t *position)
Get buffer current position.
SOPC_Buffer::length
uint32_t length
Definition: sopc_buffer.h:43
SOPC_Buffer_Copy
SOPC_ReturnStatus SOPC_Buffer_Copy(SOPC_Buffer *dest, SOPC_Buffer *src)
Copy the data bytes and properties from the source buffer to the destination buffer.
SOPC_Buffer_CopyWithLength
SOPC_ReturnStatus SOPC_Buffer_CopyWithLength(SOPC_Buffer *dest, SOPC_Buffer *src, uint32_t limitedLength)
Copy the data bytes and properties for the given length from the source buffer to the destination buf...
SOPC_Buffer::initial_size
uint32_t initial_size
Definition: sopc_buffer.h:39
SOPC_Buffer_SetPosition
SOPC_ReturnStatus SOPC_Buffer_SetPosition(SOPC_Buffer *buffer, uint32_t position)
Set buffer to the given position.
SOPC_Buffer_SetDataLength
SOPC_ReturnStatus SOPC_Buffer_SetDataLength(SOPC_Buffer *buffer, uint32_t length)
Set buffer to the given length.
SOPC_Buffer_PrintFloatDouble
SOPC_ReturnStatus SOPC_Buffer_PrintFloatDouble(SOPC_Buffer *buf, const double value)
Print the value into the buffer data bytes from the buffer position (adapting buffer position and len...
SOPC_Buffer_PrintI32
SOPC_ReturnStatus SOPC_Buffer_PrintI32(SOPC_Buffer *buf, const int32_t value)
Print the value into the buffer data bytes from the buffer position (adapting buffer position and len...
SOPC_Buffer
Bytes buffer structure.
Definition: sopc_buffer.h:38
sopc_enums.h
SOPC_Buffer::position
uint32_t position
Definition: sopc_buffer.h:42
SOPC_Buffer_Attach
SOPC_Buffer * SOPC_Buffer_Attach(uint8_t *data, uint32_t size)
Wraps a raw memory area into an SOPC_Buffer.
SOPC_Buffer_Remaining
uint32_t SOPC_Buffer_Remaining(SOPC_Buffer *buffer)
Returns the remaining number of unread bytes in the buffer.
SOPC_Buffer_ReadFile
SOPC_ReturnStatus SOPC_Buffer_ReadFile(const char *path, SOPC_Buffer **buf)
Reads the contents of a file into a SOPC_Buffer.
SOPC_Buffer_Clear
void SOPC_Buffer_Clear(SOPC_Buffer *buffer)
Deallocate buffer data bytes content.
SOPC_Buffer_Read
SOPC_ReturnStatus SOPC_Buffer_Read(uint8_t *data_dest, SOPC_Buffer *buffer, uint32_t count)
Read the given bytes of the buffer data bytes from the buffer position (adapting buffer position to n...
SOPC_Buffer_ReadFrom
int64_t SOPC_Buffer_ReadFrom(SOPC_Buffer *buffer, SOPC_Buffer *src, uint32_t n)
Reads n bytes from src into buffer.
SOPC_Buffer_ResetAfterPosition
SOPC_ReturnStatus SOPC_Buffer_ResetAfterPosition(SOPC_Buffer *buffer, uint32_t position)
reset data bytes after position (>=) to zero and set buffer position and length to given position
SOPC_Buffer_Write
SOPC_ReturnStatus SOPC_Buffer_Write(SOPC_Buffer *buffer, const uint8_t *data_src, uint32_t count)
Write the given bytes into the buffer data bytes from the buffer position (adapting buffer position a...
SOPC_Buffer_PrintU32
SOPC_ReturnStatus SOPC_Buffer_PrintU32(SOPC_Buffer *buf, const uint32_t value)
Print the value into the buffer data bytes from the buffer position (adapting buffer position and len...
SOPC_Buffer_CreateResizable
SOPC_Buffer * SOPC_Buffer_CreateResizable(uint32_t initial_size, uint32_t maximum_size)
Allocate a resizable buffer and its initial and maximum data bytes.
SOPC_Buffer::maximum_size
uint32_t maximum_size
Definition: sopc_buffer.h:41
SOPC_Buffer::data
uint8_t * data
Definition: sopc_buffer.h:44
SOPC_Buffer_Create
SOPC_Buffer * SOPC_Buffer_Create(uint32_t size)
Allocate a buffer and its data bytes of the given definitive size and returns it.
SOPC_ReturnStatus
SOPC_ReturnStatus
Definition: libs2opc_client.h:64