Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

gdp / gdp / gdp_md.h @ master

History | View | Annotate | Download (3.38 KB)

1 5c6e2b40 Eric Allman
/* vim: set ai sw=4 sts=4 ts=4 :*/
2
3
/*
4 eae1d3ec Eric Allman
**  GDP_MD.H --- headers for GDP metadata
5 5c6e2b40 Eric Allman
**
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 055d3009 Eric Allman
**
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 c87dd166 Eric Allman
**        Copyright (c) 2015-2019, Regents of the University of California.
24 6bd5476b Eric Allman
**        All rights reserved.
25 055d3009 Eric Allman
**
26 6bd5476b Eric Allman
**        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 055d3009 Eric Allman
**
32 6bd5476b Eric Allman
**        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 055d3009 Eric Allman
**
37 6bd5476b Eric Allman
**        REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
38 055d3009 Eric Allman
**        LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
39 6bd5476b Eric Allman
**        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 055d3009 Eric Allman
**        ----- END LICENSE BLOCK -----
44 5c6e2b40 Eric Allman
*/
45
46
47
struct metadatum
48
{
49 eae1d3ec Eric Allman
        gdp_md_id_t                        md_id;                        // identifier (uint32_t)
50 51bc567e Eric Allman
        uint32_t                        md_len;                        // data length (only 24 bits!)
51 5c6e2b40 Eric Allman
        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 eae1d3ec Eric Allman
struct gdp_md
59 5c6e2b40 Eric Allman
{
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 eae1d3ec Eric Allman
#define GDP_MDF_READONLY        0x00000001        // metadata list cannot be modified
68 5c6e2b40 Eric Allman
69
70
//XXX this doesn't belong here
71 eae1d3ec Eric Allman
#define GDP_MD_EOLIST        0                                // id: end of metadata list
72 3ddd2ed9 Eric Allman
73 80da996e Eric Allman
// make a copy of metadata
74
gdp_md_t                *_gdp_md_clone(
75
                                        gdp_md_t *gmd);                                // metadata to clone
76
77 3ddd2ed9 Eric Allman
// serialize an internal data structure to a network buffer
78 eae1d3ec Eric Allman
size_t                        _gdp_md_serialize(
79 80da996e Eric Allman
                                        const gdp_md_t *gmd,                // metadata to serialize
80 d65c01e2 Eric Allman
                                        uint8_t **obufp);                        // dynamically allocated output
81 3ddd2ed9 Eric Allman
82
// deserialize a network buffer to an internal data structure
83 eae1d3ec Eric Allman
gdp_md_t                *_gdp_md_deserialize(
84 92243bf4 Eric Allman
                                        const uint8_t *smd,                        // serialized metadata
85 d65c01e2 Eric Allman
                                        size_t smd_len);                        // length of smd
86 9a47c6c7 Eric Allman
87
// bulk load data into a metadata structure using existing names & lengths
88 eae1d3ec Eric Allman
void                        _gdp_md_adddata(
89
                                        gdp_md_t *gmd,
90 9a47c6c7 Eric Allman
                                        void *data);
91 80da996e Eric Allman
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