2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
8 /* pack/unpack functions for key data */
10 #ifndef SATSOLVER_REPOPACK_H
11 #define SATSOLVER_REPOPACK_H
13 static inline unsigned char *
14 data_read_id(unsigned char *dp, Id *idp)
26 x = (x << 7) ^ c ^ 128;
30 static inline unsigned char *
31 data_read_ideof(unsigned char *dp, Id *idp, int *eof)
50 x = (x << 7) ^ c ^ 128;
54 static inline unsigned char *
55 data_read_u32(unsigned char *dp, unsigned int *nump)
57 *nump = (dp[0] << 24) | (dp[1] << 16) | (dp[2] << 8) | dp[3];
61 static inline unsigned char *
62 data_fetch(unsigned char *dp, KeyValue *kv, Repokey *key)
69 case REPOKEY_TYPE_VOID:
71 case REPOKEY_TYPE_CONSTANT:
74 case REPOKEY_TYPE_CONSTANTID:
77 case REPOKEY_TYPE_STR:
78 kv->str = (const char *)dp;
79 return dp + strlen(kv->str) + 1;
81 case REPOKEY_TYPE_DIR:
82 return data_read_id(dp, &kv->id);
83 case REPOKEY_TYPE_NUM:
84 return data_read_id(dp, &kv->num);
85 case REPOKEY_TYPE_U32:
86 return data_read_u32(dp, (unsigned int *)&kv->num);
87 case REPOKEY_TYPE_IDARRAY:
88 return data_read_ideof(dp, &kv->id, &kv->eof);
89 case REPOKEY_TYPE_DIRSTRARRAY:
90 dp = data_read_ideof(dp, &kv->id, &kv->eof);
91 kv->str = (const char *)dp;
92 return dp + strlen(kv->str) + 1;
93 case REPOKEY_TYPE_DIRNUMNUMARRAY:
94 dp = data_read_id(dp, &kv->id);
95 dp = data_read_id(dp, &kv->num);
96 return data_read_ideof(dp, &kv->num2, &kv->eof);
102 static inline unsigned char *
103 data_skip(unsigned char *dp, int type)
108 case REPOKEY_TYPE_VOID:
109 case REPOKEY_TYPE_CONSTANT:
110 case REPOKEY_TYPE_CONSTANTID:
112 case REPOKEY_TYPE_ID:
113 case REPOKEY_TYPE_NUM:
114 case REPOKEY_TYPE_DIR:
115 while ((*dp & 0x80) != 0)
118 case REPOKEY_TYPE_U32:
120 case REPOKEY_TYPE_IDARRAY:
121 case REPOKEY_TYPE_REL_IDARRAY:
122 while ((*dp & 0xc0) != 0)
125 case REPOKEY_TYPE_STR:
129 case REPOKEY_TYPE_DIRSTRARRAY:
132 while ((*dp & 0x80) != 0)
141 case REPOKEY_TYPE_DIRNUMNUMARRAY:
144 while ((*dp & 0x80) != 0)
147 while ((*dp & 0x80) != 0)
150 while ((*dp & 0x80) != 0)
161 static inline unsigned char *
162 data_skip_verify(unsigned char *dp, int type, int maxid, int maxdir)
169 case REPOKEY_TYPE_VOID:
170 case REPOKEY_TYPE_CONSTANT:
171 case REPOKEY_TYPE_CONSTANTID:
173 case REPOKEY_TYPE_NUM:
174 while ((*dp & 0x80) != 0)
177 case REPOKEY_TYPE_U32:
179 case REPOKEY_TYPE_ID:
180 dp = data_read_id(dp, &id);
184 case REPOKEY_TYPE_DIR:
185 dp = data_read_id(dp, &id);
189 case REPOKEY_TYPE_IDARRAY:
192 dp = data_read_ideof(dp, &id, &eof);
198 case REPOKEY_TYPE_STR:
202 case REPOKEY_TYPE_DIRSTRARRAY:
205 dp = data_read_ideof(dp, &id, &eof);
214 case REPOKEY_TYPE_DIRNUMNUMARRAY:
217 dp = data_read_id(dp, &id);
220 while ((*dp & 0x80) != 0)
223 while ((*dp & 0x80) != 0)
234 #endif /* SATSOLVER_REPOPACK */