xref: /qemu/include/migration/qemu-file-types.h (revision ac06724a)
1 /*
2  * QEMU System Emulator
3  *
4  * Copyright (c) 2003-2008 Fabrice Bellard
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 #ifndef QEMU_FILE_H
26 #define QEMU_FILE_H
27 
28 void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, size_t size);
29 void qemu_put_byte(QEMUFile *f, int v);
30 
31 #define qemu_put_sbyte qemu_put_byte
32 
33 void qemu_put_be16(QEMUFile *f, unsigned int v);
34 void qemu_put_be32(QEMUFile *f, unsigned int v);
35 void qemu_put_be64(QEMUFile *f, uint64_t v);
36 size_t qemu_get_buffer(QEMUFile *f, uint8_t *buf, size_t size);
37 
38 int qemu_get_byte(QEMUFile *f);
39 
40 static inline unsigned int qemu_get_ubyte(QEMUFile *f)
41 {
42     return (unsigned int)qemu_get_byte(f);
43 }
44 
45 #define qemu_get_sbyte qemu_get_byte
46 
47 unsigned int qemu_get_be16(QEMUFile *f);
48 unsigned int qemu_get_be32(QEMUFile *f);
49 uint64_t qemu_get_be64(QEMUFile *f);
50 
51 static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
52 {
53     qemu_put_be64(f, *pv);
54 }
55 
56 static inline void qemu_put_be32s(QEMUFile *f, const uint32_t *pv)
57 {
58     qemu_put_be32(f, *pv);
59 }
60 
61 static inline void qemu_put_be16s(QEMUFile *f, const uint16_t *pv)
62 {
63     qemu_put_be16(f, *pv);
64 }
65 
66 static inline void qemu_put_8s(QEMUFile *f, const uint8_t *pv)
67 {
68     qemu_put_byte(f, *pv);
69 }
70 
71 static inline void qemu_get_be64s(QEMUFile *f, uint64_t *pv)
72 {
73     *pv = qemu_get_be64(f);
74 }
75 
76 static inline void qemu_get_be32s(QEMUFile *f, uint32_t *pv)
77 {
78     *pv = qemu_get_be32(f);
79 }
80 
81 static inline void qemu_get_be16s(QEMUFile *f, uint16_t *pv)
82 {
83     *pv = qemu_get_be16(f);
84 }
85 
86 static inline void qemu_get_8s(QEMUFile *f, uint8_t *pv)
87 {
88     *pv = qemu_get_byte(f);
89 }
90 
91 /* Signed versions for type safety */
92 static inline void qemu_put_sbe16(QEMUFile *f, int v)
93 {
94     qemu_put_be16(f, (unsigned int)v);
95 }
96 
97 static inline void qemu_put_sbe32(QEMUFile *f, int v)
98 {
99     qemu_put_be32(f, (unsigned int)v);
100 }
101 
102 static inline void qemu_put_sbe64(QEMUFile *f, int64_t v)
103 {
104     qemu_put_be64(f, (uint64_t)v);
105 }
106 
107 static inline int qemu_get_sbe16(QEMUFile *f)
108 {
109     return (int)qemu_get_be16(f);
110 }
111 
112 static inline int qemu_get_sbe32(QEMUFile *f)
113 {
114     return (int)qemu_get_be32(f);
115 }
116 
117 static inline int64_t qemu_get_sbe64(QEMUFile *f)
118 {
119     return (int64_t)qemu_get_be64(f);
120 }
121 
122 static inline void qemu_put_s8s(QEMUFile *f, const int8_t *pv)
123 {
124     qemu_put_8s(f, (const uint8_t *)pv);
125 }
126 
127 static inline void qemu_put_sbe16s(QEMUFile *f, const int16_t *pv)
128 {
129     qemu_put_be16s(f, (const uint16_t *)pv);
130 }
131 
132 static inline void qemu_put_sbe32s(QEMUFile *f, const int32_t *pv)
133 {
134     qemu_put_be32s(f, (const uint32_t *)pv);
135 }
136 
137 static inline void qemu_put_sbe64s(QEMUFile *f, const int64_t *pv)
138 {
139     qemu_put_be64s(f, (const uint64_t *)pv);
140 }
141 
142 static inline void qemu_get_s8s(QEMUFile *f, int8_t *pv)
143 {
144     qemu_get_8s(f, (uint8_t *)pv);
145 }
146 
147 static inline void qemu_get_sbe16s(QEMUFile *f, int16_t *pv)
148 {
149     qemu_get_be16s(f, (uint16_t *)pv);
150 }
151 
152 static inline void qemu_get_sbe32s(QEMUFile *f, int32_t *pv)
153 {
154     qemu_get_be32s(f, (uint32_t *)pv);
155 }
156 
157 static inline void qemu_get_sbe64s(QEMUFile *f, int64_t *pv)
158 {
159     qemu_get_be64s(f, (uint64_t *)pv);
160 }
161 
162 int qemu_file_rate_limit(QEMUFile *f);
163 
164 #endif
165