-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
trivial: Split out XbSiloNode to a new source file
Add some accessors for XbSiloNode so that we can easily experiment with silo format changes without changing dozens of source files. Also, rename some internal symbols for consistency.
- Loading branch information
Showing
10 changed files
with
216 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (C) 2021 Richard Hughes <richard@hughsie.com> | ||
* | ||
* SPDX-License-Identifier: LGPL-2.1+ | ||
*/ | ||
|
||
#define G_LOG_DOMAIN "XbSilo" | ||
|
||
#include <string.h> | ||
|
||
#include "xb-silo-node.h" | ||
|
||
/* private */ | ||
guint32 | ||
xb_silo_node_get_size (XbSiloNode *self) | ||
{ | ||
/* sentinel */ | ||
if ((self->flags & XB_SILO_NODE_FLAG_IS_ELEMENT) == 0) | ||
return sizeof(guint8); | ||
|
||
/* element */ | ||
return sizeof(XbSiloNode) + sizeof(XbSiloNodeAttr) * self->attr_count; | ||
} | ||
|
||
/* private */ | ||
guint8 | ||
xb_silo_node_get_flags (XbSiloNode *self) | ||
{ | ||
return self->flags; | ||
} | ||
|
||
/* private */ | ||
gboolean | ||
xb_silo_node_has_flag (XbSiloNode *self, XbSiloNodeFlag flag) | ||
{ | ||
return (self->flags & flag) > 0; | ||
} | ||
|
||
/* private */ | ||
guint32 | ||
xb_silo_node_get_text_idx (XbSiloNode *self) | ||
{ | ||
return self->text; | ||
} | ||
|
||
/* private */ | ||
guint32 | ||
xb_silo_node_get_tail_idx (XbSiloNode *self) | ||
{ | ||
return self->tail; | ||
} | ||
|
||
/* private */ | ||
guint8 | ||
xb_silo_node_get_attr_count (XbSiloNode *self) | ||
{ | ||
return self->attr_count; | ||
} | ||
|
||
/* private */ | ||
XbSiloNodeAttr * | ||
xb_silo_node_get_attr (XbSiloNode *self, guint8 idx) | ||
{ | ||
guint32 off = sizeof(XbSiloNode); | ||
off += sizeof(XbSiloNodeAttr) * idx; | ||
return (XbSiloNodeAttr *) (((guint8 *) self) + off); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (C) 2021 Richard Hughes <richard@hughsie.com> | ||
* | ||
* SPDX-License-Identifier: LGPL-2.1+ | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <glib-object.h> | ||
|
||
#define XB_SILO_UNSET 0xffffffff | ||
|
||
typedef enum { | ||
XB_SILO_NODE_FLAG_NONE = 0, | ||
XB_SILO_NODE_FLAG_IS_ELEMENT = 1 << 0, | ||
} XbSiloNodeFlag; | ||
|
||
typedef struct __attribute__ ((packed)) { | ||
guint8 flags:1; | ||
guint8 attr_count:7; | ||
guint32 element_name; /* ONLY when is_node: from strtab */ | ||
guint32 parent; /* ONLY when is_node: from 0 */ | ||
guint32 next; /* ONLY when is_node: from 0 */ | ||
guint32 text; /* ONLY when is_node: from strtab */ | ||
guint32 tail; /* ONLY when is_node: from strtab */ | ||
} XbSiloNode; | ||
|
||
typedef struct __attribute__ ((packed)) { | ||
guint32 attr_name; /* from strtab */ | ||
guint32 attr_value; /* from strtab */ | ||
} XbSiloNodeAttr; | ||
|
||
guint32 xb_silo_node_get_size (XbSiloNode *self); | ||
guint32 xb_silo_node_get_text_idx (XbSiloNode *self); | ||
guint32 xb_silo_node_get_tail_idx (XbSiloNode *self); | ||
guint8 xb_silo_node_get_flags (XbSiloNode *self); | ||
gboolean xb_silo_node_has_flag (XbSiloNode *self, | ||
XbSiloNodeFlag flags); | ||
guint8 xb_silo_node_get_attr_count (XbSiloNode *self); | ||
XbSiloNodeAttr *xb_silo_node_get_attr (XbSiloNode *self, | ||
guint8 idx); |
Oops, something went wrong.