Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

gdp / gdp / gdp_md.h @ master

History | View | Annotate | Download (3.38 KB)

1
/* vim: set ai sw=4 sts=4 ts=4 :*/
2

    
3
/*
4
**  GDP_MD.H --- headers for GDP metadata
5
**
6
**                THESE DEFINITIONS ARE PRIVATE!
7
**
8
**                Although the md_len field is (at least) 32 bits, only the
9
**                bottom 24 bits are used for the length.  The top eight bits
10
**                are reserved for future use (probably for tagging or typing).
11
**                Those bits must be zero on send and ignored on receive.
12
**
13
**                This data structure contains the data in two representations.
14
**                One is the on-wire format in network byte order.  The other
15
**                is an internal array of name/len/value triplets.  The value
16
**                part of the triplet is actually a pointer into the on-wire
17
**                format.
18
**
19
**        ----- BEGIN LICENSE BLOCK -----
20
**        GDP: Global Data Plane Support Library
21
**        From the Ubiquitous Swarm Lab, 490 Cory Hall, U.C. Berkeley.
22
**
23
**        Copyright (c) 2015-2019, Regents of the University of California.
24
**        All rights reserved.
25
**
26
**        Permission is hereby granted, without written agreement and without
27
**        license or royalty fees, to use, copy, modify, and distribute this
28
**        software and its documentation for any purpose, provided that the above
29
**        copyright notice and the following two paragraphs appear in all copies
30
**        of this software.
31
**
32
**        IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
33
**        SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST
34
**        PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
35
**        EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
**
37
**        REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
38
**        LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
39
**        FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION,
40
**        IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO
41
**        OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
42
**        OR MODIFICATIONS.
43
**        ----- END LICENSE BLOCK -----
44
*/
45

    
46

    
47
struct metadatum
48
{
49
        gdp_md_id_t                        md_id;                        // identifier (uint32_t)
50
        uint32_t                        md_len;                        // data length (only 24 bits!)
51
        void                                *md_data;                // pointer to data
52
        uint32_t                        md_flags;                // see below
53
};
54

    
55
#define MDF_OWNDATA                0x00000001                // we own the data field
56

    
57

    
58
struct gdp_md
59
{
60
        int                                        nalloc;                        // number of datums allocated
61
        int                                        nused;                        // number of datums in use
62
        struct metadatum        *mds;                        // array of metadata items
63
        void                                *databuf;                // data buffer space (optional)
64
        uint32_t                        flags;                        // see below
65
};
66

    
67
#define GDP_MDF_READONLY        0x00000001        // metadata list cannot be modified
68

    
69

    
70
//XXX this doesn't belong here
71
#define GDP_MD_EOLIST        0                                // id: end of metadata list
72

    
73
// make a copy of metadata
74
gdp_md_t                *_gdp_md_clone(
75
                                        gdp_md_t *gmd);                                // metadata to clone
76

    
77
// serialize an internal data structure to a network buffer
78
size_t                        _gdp_md_serialize(
79
                                        const gdp_md_t *gmd,                // metadata to serialize
80
                                        uint8_t **obufp);                        // dynamically allocated output
81

    
82
// deserialize a network buffer to an internal data structure
83
gdp_md_t                *_gdp_md_deserialize(
84
                                        const uint8_t *smd,                        // serialized metadata
85
                                        size_t smd_len);                        // length of smd
86

    
87
// bulk load data into a metadata structure using existing names & lengths
88
void                        _gdp_md_adddata(
89
                                        gdp_md_t *gmd,
90
                                        void *data);
91

    
92
// compute a GDPname from metadata, optionally returning serialized version
93
EP_STAT                        _gdp_md_to_gdpname(
94
                                        const gdp_md_t *gmd,                // in-memory metadata
95
                                        gdp_name_t *gname_p,                // GDPname result buffer
96
                                        uint8_t **serialized_md_p);        // serialized MD output