Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
wasm-watermarker
Project
Project
Details
Activity
Releases
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nagayama15
wasm-watermarker
Commits
25744852
Commit
25744852
authored
Jul 11, 2019
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add bit stream writer
parent
7dd3140d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
115 additions
and
1 deletion
+115
-1
BitStreamWriter.hpp
src/kyut/BitStreamWriter.hpp
+54
-0
CircularBitStreamReader.hpp
src/kyut/CircularBitStreamReader.hpp
+4
-0
CMakeLists.txt
test/CMakeLists.txt
+2
-1
test_BitStreamWriter.cpp
test/kyut/test_BitStreamWriter.cpp
+55
-0
test_CircularBitStreamReader.cpp
test/kyut/test_CircularBitStreamReader.cpp
+0
-0
No files found.
src/kyut/BitStreamWriter.hpp
0 → 100644
View file @
25744852
#ifndef INCLUDE_kyut_BitStreamWriter_hpp
#define INCLUDE_kyut_BitStreamWriter_hpp
#include <cassert>
#include <cstdint>
#include <vector>
namespace
kyut
{
class
BitStreamWriter
{
public
:
explicit
BitStreamWriter
()
:
data_
()
,
pos_write_
(
0
)
{}
BitStreamWriter
(
const
BitStreamWriter
&
)
=
delete
;
BitStreamWriter
(
BitStreamWriter
&&
)
=
delete
;
BitStreamWriter
&
operator
=
(
const
BitStreamWriter
&
)
=
delete
;
BitStreamWriter
&
operator
=
(
BitStreamWriter
&&
)
=
delete
;
~
BitStreamWriter
()
noexcept
=
default
;
[[
nodiscard
]]
const
std
::
vector
<
std
::
uint8_t
>
&
data
()
const
noexcept
{
return
data_
;
}
[[
nodiscard
]]
std
::
size_t
tell
()
const
noexcept
{
return
pos_write_
;
}
void
writeBit
(
bool
value
)
{
if
(
pos_write_
%
8
==
0
)
{
data_
.
emplace_back
(
0
);
}
data_
[
pos_write_
/
8
]
|=
(
value
?
1
:
0
)
<<
(
7
-
pos_write_
%
8
);
pos_write_
++
;
}
void
write
(
std
::
uint64_t
value
,
std
::
size_t
length
)
{
assert
(
length
<=
64
);
for
(
std
::
size_t
i
=
0
;
i
<
length
;
i
++
)
{
writeBit
((
value
&
(
1
<<
(
length
-
i
-
1
)))
!=
0
);
}
}
private
:
std
::
vector
<
std
::
uint8_t
>
data_
;
std
::
size_t
pos_write_
;
};
}
// namespace kyut
#endif // INCLUDE_kyut_BitStreamWriter_hpp
src/kyut/CircularBitStreamReader.hpp
View file @
25744852
...
...
@@ -31,6 +31,10 @@ namespace kyut {
reinterpret_cast
<
const
std
::
uint8_t
*>
(
s
.
data
()
+
s
.
size
()));
}
[[
nodiscard
]]
const
std
::
vector
<
std
::
uint8_t
>
&
data
()
const
noexcept
{
return
data_
;
}
[[
nodiscard
]]
std
::
size_t
tell
()
const
noexcept
{
return
pos_read_
;
}
...
...
test/CMakeLists.txt
View file @
25744852
add_executable
(
test_kyut
test_kyut.cpp
kyut/test_BitStreamReader.cpp
kyut/test_CircularBitStreamReader.cpp
kyut/test_BitStreamWriter.cpp
kyut/watermarker/test_FunctionOrderingWatermarker.cpp
)
...
...
test/kyut/test_BitStreamWriter.cpp
0 → 100644
View file @
25744852
#include <kyut/BitStreamWriter.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE
(
kyut
)
BOOST_AUTO_TEST_SUITE
(
bit_stream_writer
)
BOOST_AUTO_TEST_CASE
(
write_bit
)
{
BitStreamWriter
s
;
BOOST_REQUIRE_EQUAL
(
s
.
data
().
size
(),
std
::
size_t
{
0
});
BOOST_REQUIRE_EQUAL
(
s
.
tell
(),
std
::
size_t
{
0
});
s
.
writeBit
(
true
);
BOOST_REQUIRE_EQUAL
(
s
.
data
().
size
(),
std
::
size_t
{
1
});
BOOST_REQUIRE_EQUAL
(
s
.
data
()[
0
],
std
::
uint8_t
{
0
b1000
'
0000
});
BOOST_REQUIRE_EQUAL
(
s
.
tell
(),
std
::
size_t
{
1
});
s
.
writeBit
(
true
);
BOOST_REQUIRE_EQUAL
(
s
.
data
().
size
(),
std
::
size_t
{
1
});
BOOST_REQUIRE_EQUAL
(
s
.
data
()[
0
],
std
::
uint8_t
{
0
b1100
'
0000
});
BOOST_REQUIRE_EQUAL
(
s
.
tell
(),
std
::
size_t
{
2
});
s
.
writeBit
(
false
);
BOOST_REQUIRE_EQUAL
(
s
.
data
().
size
(),
std
::
size_t
{
1
});
BOOST_REQUIRE_EQUAL
(
s
.
data
()[
0
],
std
::
uint8_t
{
0
b1100
'
0000
});
BOOST_REQUIRE_EQUAL
(
s
.
tell
(),
std
::
size_t
{
3
});
s
.
writeBit
(
false
);
s
.
writeBit
(
true
);
s
.
writeBit
(
false
);
s
.
writeBit
(
true
);
s
.
writeBit
(
true
);
BOOST_REQUIRE_EQUAL
(
s
.
data
().
size
(),
std
::
size_t
{
1
});
BOOST_REQUIRE_EQUAL
(
s
.
data
()[
0
],
std
::
uint8_t
{
0
b1100
'
1011
});
BOOST_REQUIRE_EQUAL
(
s
.
tell
(),
std
::
size_t
{
8
});
}
BOOST_AUTO_TEST_CASE
(
write
)
{
BitStreamWriter
s
;
BOOST_REQUIRE_EQUAL
(
s
.
data
().
size
(),
std
::
size_t
{
0
});
BOOST_REQUIRE_EQUAL
(
s
.
tell
(),
std
::
size_t
{
0
});
s
.
write
(
0xabcd
,
16
);
BOOST_REQUIRE_EQUAL
(
s
.
data
().
size
(),
std
::
size_t
{
2
});
BOOST_REQUIRE_EQUAL
(
s
.
data
()[
0
],
std
::
uint8_t
{
0xab
});
BOOST_REQUIRE_EQUAL
(
s
.
data
()[
1
],
std
::
uint8_t
{
0xcd
});
BOOST_REQUIRE_EQUAL
(
s
.
tell
(),
std
::
size_t
{
16
});
}
BOOST_AUTO_TEST_SUITE_END
()
BOOST_AUTO_TEST_SUITE_END
()
test/kyut/test_BitStreamReader.cpp
→
test/kyut/test_
Circular
BitStreamReader.cpp
View file @
25744852
File moved
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