Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
f88fc0ca
Commit
f88fc0ca
authored
Apr 26, 2022
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/ByteOrder: add class PackedBE32
parent
fb8d8242
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
+54
-0
ByteOrder.hxx
src/util/ByteOrder.hxx
+54
-0
No files found.
src/util/ByteOrder.hxx
View file @
f88fc0ca
...
@@ -298,6 +298,60 @@ static_assert(sizeof(PackedBE16) == sizeof(uint16_t), "Wrong size");
...
@@ -298,6 +298,60 @@ static_assert(sizeof(PackedBE16) == sizeof(uint16_t), "Wrong size");
static_assert
(
alignof
(
PackedBE16
)
==
1
,
"Wrong alignment"
);
static_assert
(
alignof
(
PackedBE16
)
==
1
,
"Wrong alignment"
);
/**
/**
* A packed big-endian 32 bit integer.
*/
class
PackedBE32
{
uint8_t
a
,
b
,
c
,
d
;
public
:
PackedBE32
()
=
default
;
constexpr
PackedBE32
(
uint32_t
src
)
noexcept
:
a
(
uint8_t
(
src
>>
24
)),
b
(
uint8_t
(
src
>>
16
)),
c
(
uint8_t
(
src
>>
8
)),
d
(
uint8_t
(
src
))
{}
/**
* Construct an instance from an integer which is already
* big-endian.
*/
static
constexpr
auto
FromBE
(
uint32_t
src
)
noexcept
{
union
{
uint32_t
in
;
PackedBE32
out
;
}
u
{
src
};
return
u
.
out
;
}
constexpr
operator
uint32_t
()
const
noexcept
{
return
(
uint32_t
(
a
)
<<
24
)
|
(
uint32_t
(
b
)
<<
16
)
|
(
uint32_t
(
c
)
<<
8
)
|
uint32_t
(
d
);
}
PackedBE32
&
operator
=
(
uint32_t
new_value
)
noexcept
{
d
=
uint8_t
(
new_value
);
c
=
uint8_t
(
new_value
>>
8
);
b
=
uint8_t
(
new_value
>>
16
);
a
=
uint8_t
(
new_value
>>
24
);
return
*
this
;
}
/**
* Reads the raw, big-endian value.
*/
constexpr
uint32_t
raw
()
const
noexcept
{
uint32_t
x
=
*
this
;
if
(
IsLittleEndian
())
x
=
ByteSwap32
(
x
);
return
x
;
}
};
static_assert
(
sizeof
(
PackedBE32
)
==
sizeof
(
uint32_t
),
"Wrong size"
);
static_assert
(
alignof
(
PackedBE32
)
==
1
,
"Wrong alignment"
);
/**
* A packed little-endian 16 bit integer.
* A packed little-endian 16 bit integer.
*/
*/
class
PackedLE16
{
class
PackedLE16
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment