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
2363ea59
Verified
Commit
2363ea59
authored
Oct 03, 2020
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(stream): add BitStreamWriter
parent
bdf62cf6
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
104 additions
and
10 deletions
+104
-10
CMakeLists.txt
CMakeLists.txt
+1
-0
CMakeLists.txt
lib/CMakeLists.txt
+10
-0
BitStreamWriter.hpp
lib/kyut/BitStreamWriter.hpp
+64
-0
CMakeLists.txt
src/CMakeLists.txt
+2
-4
CMakeLists.txt
test/CMakeLists.txt
+2
-2
test_BitStreamWriter.cpp
test/test_BitStreamWriter.cpp
+25
-0
test_kyut.cpp
test/test_kyut.cpp
+0
-4
No files found.
CMakeLists.txt
View file @
2363ea59
...
...
@@ -26,5 +26,6 @@ include(cmake/cmdline.cmake)
include
(
cmake/fmt.cmake
)
include
(
cmake/googletest.cmake
)
add_subdirectory
(
lib
)
add_subdirectory
(
src
)
add_subdirectory
(
test
)
lib/CMakeLists.txt
0 → 100644
View file @
2363ea59
add_library
(
kyut INTERFACE
)
target_include_directories
(
kyut INTERFACE
"."
)
target_link_libraries
(
kyut INTERFACE
binaryen::binaryen
fmtlib::fmt
)
lib/kyut/BitStreamWriter.hpp
0 → 100644
View file @
2363ea59
#ifndef INCLUDE_kyut_BitStreamWriter_hpp
#define INCLUDE_kyut_BitStreamWriter_hpp
#include <cassert>
#include <string_view>
#include <vector>
namespace
kyut
{
class
BitStreamWriter
{
public
:
BitStreamWriter
()
:
data_
()
,
pos_bits_
(
0
)
{
}
// Uncopyable and unmovable
BitStreamWriter
(
const
BitStreamWriter
&
)
=
delete
;
BitStreamWriter
(
BitStreamWriter
&&
)
=
delete
;
BitStreamWriter
&
operator
=
(
const
BitStreamWriter
&
)
=
delete
;
BitStreamWriter
&
operator
=
(
BitStreamWriter
&&
)
=
delete
;
~
BitStreamWriter
()
noexcept
=
default
;
void
write
(
std
::
uint64_t
x
,
std
::
size_t
size_bits
)
{
assert
(
size_bits
<=
64
);
for
(
std
::
size_t
i
=
0
;
i
<
size_bits
;
i
++
)
{
const
auto
bit
=
(
x
>>
(
size_bits
-
i
-
1
))
&
1
;
write_bit
(
bit
!=
0
);
}
}
void
write_bit
(
bool
x
)
{
const
auto
n
=
pos_bits_
>>
3
;
const
auto
k
=
pos_bits_
&
7
;
if
(
k
==
0
)
{
data_
.
emplace_back
(
0
);
}
data_
[
n
]
|=
(
x
?
1
:
0
)
<<
(
7
-
k
);
pos_bits_
++
;
}
std
::
size_t
position_bits
()
const
noexcept
{
return
pos_bits_
;
}
const
std
::
vector
<
std
::
uint8_t
>&
data
()
const
noexcept
{
return
data_
;
}
std
::
string_view
data_as_str
()
const
noexcept
{
return
std
::
string_view
(
reinterpret_cast
<
const
char
*>
(
data_
.
data
()),
data_
.
size
());
}
private
:
std
::
vector
<
std
::
uint8_t
>
data_
;
std
::
size_t
pos_bits_
;
};
}
// namespace kyut
#endif // INCLUDE_kyut_BitStreamWriter_hpp
src/CMakeLists.txt
View file @
2363ea59
...
...
@@ -3,9 +3,8 @@ add_executable(snpi
)
target_link_libraries
(
snpi
kyut
cmdline::cmdline
binaryen::binaryen
fmtlib::fmt
)
add_executable
(
pisn
...
...
@@ -13,7 +12,6 @@ add_executable(pisn
)
target_link_libraries
(
pisn
kyut
cmdline::cmdline
binaryen::binaryen
fmtlib::fmt
)
test/CMakeLists.txt
View file @
2363ea59
set
(
CMAKE_RUNTIME_OUTPUT_DIRECTORY
"
${
CMAKE_BINARY_DIR
}
/test"
)
add_executable
(
test_kyut
test_
kyut
.cpp
test_
BitStreamWriter
.cpp
)
target_link_libraries
(
test_kyut
kyut
Threads::Threads
fmtlib::fmt
googletest::gtest
googletest::gtest_main
)
...
...
test/test_BitStreamWriter.cpp
0 → 100644
View file @
2363ea59
#include "kyut/BitStreamWriter.hpp"
#include <gtest/gtest.h>
TEST
(
kyut
,
BitStreamWriter
)
{
kyut
::
BitStreamWriter
w
{};
EXPECT_EQ
(
w
.
position_bits
(),
0
);
EXPECT_EQ
(
w
.
data_as_str
(),
""
);
w
.
write
(
0x0A
,
4
);
EXPECT_EQ
(
w
.
position_bits
(),
4
);
EXPECT_EQ
(
w
.
data_as_str
(),
"
\xA0
"
);
w
.
write
(
0xBC
,
8
);
EXPECT_EQ
(
w
.
position_bits
(),
12
);
EXPECT_EQ
(
w
.
data_as_str
(),
"
\xAB\xC0
"
);
w
.
write
(
0xDEF
,
12
);
EXPECT_EQ
(
w
.
position_bits
(),
24
);
EXPECT_EQ
(
w
.
data_as_str
(),
"
\xAB\xCD\xEF
"
);
}
test/test_kyut.cpp
deleted
100644 → 0
View file @
bdf62cf6
#include <gtest/gtest.h>
TEST
(
kyut
,
dummy
)
{
}
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