Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dCache
cta
Commits
14f87d50
Commit
14f87d50
authored
Sep 07, 2015
by
Steven Murray
Browse files
Added constructor cta::ByteArray::ByteArray(const uint32_t value)
parent
ced96bfb
Changes
3
Hide whitespace changes
Inline
Side-by-side
common/checksum/ByteArray.cpp
View file @
14f87d50
...
...
@@ -19,6 +19,7 @@
#include
"common/checksum/ByteArray.hpp"
#include
<ostream>
#include
<strings.h>
//------------------------------------------------------------------------------
// constructor
...
...
@@ -51,7 +52,21 @@ cta::ByteArray::ByteArray(const std::string &bytes) {
}
//------------------------------------------------------------------------------
// constructor
// copy constructor
//------------------------------------------------------------------------------
cta
::
ByteArray
::
ByteArray
(
const
uint32_t
value
)
{
m_size
=
sizeof
value
;
m_bytes
=
new
uint8_t
[
sizeof
value
];
bzero
(
m_bytes
,
sizeof
m_bytes
);
m_bytes
[
0
]
=
value
&
0xFF
;
m_bytes
[
1
]
=
value
>>
8
&
0xFF
;
m_bytes
[
2
]
=
value
>>
16
&
0xFF
;
m_bytes
[
3
]
=
value
>>
24
&
0xFF
;
}
//------------------------------------------------------------------------------
// copy constructor
//------------------------------------------------------------------------------
cta
::
ByteArray
::
ByteArray
(
const
ByteArray
&
other
)
{
m_size
=
other
.
m_size
;
...
...
common/checksum/ByteArray.hpp
View file @
14f87d50
...
...
@@ -69,6 +69,15 @@ public:
*/
ByteArray
(
const
std
::
string
&
bytes
);
/**
* Constructor.
*
* Copies the specified uint32_t into this object in little endian byte order.
*
* @param value The value.
*/
explicit
ByteArray
(
const
uint32_t
value
);
/**
* Copy constructor.
*/
...
...
common/checksum/ByteArrayTest.cpp
View file @
14f87d50
...
...
@@ -81,6 +81,20 @@ TEST_F(cta_ByteArrayTest, string_constructor) {
ASSERT_EQ
((
uint8_t
)
'o'
,
byteArray
.
getBytes
()[
4
]);
}
TEST_F
(
cta_ByteArrayTest
,
uint32_t_constructor
)
{
using
namespace
cta
;
const
uint32_t
value
=
0x10203040
;
const
ByteArray
byteArray
(
value
);
// uint32_t should be stored in little endian byte order
ASSERT_EQ
((
uint32_t
)
4
,
byteArray
.
getSize
());
ASSERT_EQ
((
uint8_t
)
0x40
,
byteArray
.
getBytes
()[
0
]);
ASSERT_EQ
((
uint8_t
)
0x30
,
byteArray
.
getBytes
()[
1
]);
ASSERT_EQ
((
uint8_t
)
0x20
,
byteArray
.
getBytes
()[
2
]);
ASSERT_EQ
((
uint8_t
)
0x10
,
byteArray
.
getBytes
()[
3
]);
}
TEST_F
(
cta_ByteArrayTest
,
copy_constructor
)
{
using
namespace
cta
;
...
...
Write
Preview
Supports
Markdown
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