1 // Copyright 2018 The Fuchsia 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 #pragma once
6 
7 #include <zircon/types.h>
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 typedef struct {
14     uint32_t stream_id;
15     size_t total_length;
16 } xdc_packet_header_t;
17 
18 typedef struct {
19     xdc_packet_header_t header;
20     // Number of bytes received for this packet so far.
21     // Once this equals header.total_length, the packet has been fully received.
22     size_t bytes_received;
23 } xdc_packet_state_t;
24 
25 // Updates the packet state with the read data buffer.
26 // If out_new_packet is not NULL, it will be populated with whether this
27 // data buffer starts a new xdc packet and hence contains a header.
28 //
29 // Returns ZX_OK if successful, or an error if the data buffer was malformed.
30 zx_status_t xdc_update_packet_state(xdc_packet_state_t* packet_state,
31                                     void* data, size_t data_len, bool* out_new_packet);
32 
33 #ifdef __cplusplus
34 } // extern "C"
35 #endif
36