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
1fd7d8a7
Commit
1fd7d8a7
authored
Jul 26, 2019
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make streams to accept any uint types
parent
d6dc6169
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
13 deletions
+19
-13
BitStreamWriter.hpp
src/kyut/BitStreamWriter.hpp
+4
-2
CircularBitStreamReader.hpp
src/kyut/CircularBitStreamReader.hpp
+6
-2
FunctionOrderingWatermarker.cpp
src/kyut/watermarker/FunctionOrderingWatermarker.cpp
+3
-3
test_BitStreamWriter.cpp
test/kyut/test_BitStreamWriter.cpp
+1
-1
test_CircularBitStreamReader.cpp
test/kyut/test_CircularBitStreamReader.cpp
+5
-5
No files found.
src/kyut/BitStreamWriter.hpp
View file @
1fd7d8a7
...
@@ -45,8 +45,10 @@ namespace kyut {
...
@@ -45,8 +45,10 @@ namespace kyut {
pos_write_
++
;
pos_write_
++
;
}
}
void
write
(
std
::
uint64_t
value
,
std
::
size_t
length
)
{
template
<
typename
UInt
>
assert
(
length
<=
64
);
void
write
(
UInt
value
,
std
::
size_t
length
)
{
static_assert
(
std
::
is_unsigned_v
<
UInt
>
);
assert
(
length
<=
sizeof
(
UInt
)
*
8
);
for
(
std
::
size_t
i
=
0
;
i
<
length
;
i
++
)
{
for
(
std
::
size_t
i
=
0
;
i
<
length
;
i
++
)
{
writeBit
((
value
&
(
1
<<
(
length
-
i
-
1
)))
!=
0
);
writeBit
((
value
&
(
1
<<
(
length
-
i
-
1
)))
!=
0
);
...
...
src/kyut/CircularBitStreamReader.hpp
View file @
1fd7d8a7
...
@@ -48,8 +48,12 @@ namespace kyut {
...
@@ -48,8 +48,12 @@ namespace kyut {
return
((
data_
[
pos
/
8
%
data_
.
size
()]
<<
(
pos
%
8
))
&
0x80
)
!=
0
;
return
((
data_
[
pos
/
8
%
data_
.
size
()]
<<
(
pos
%
8
))
&
0x80
)
!=
0
;
}
}
std
::
uint64_t
read
(
std
::
size_t
countBits
)
{
template
<
typename
UInt
>
std
::
uint64_t
value
=
0
;
UInt
read
(
std
::
size_t
countBits
)
{
static_assert
(
std
::
is_unsigned_v
<
UInt
>
);
assert
(
countBits
<=
sizeof
(
UInt
)
*
8
);
UInt
value
=
0
;
for
(
std
::
size_t
i
=
0
;
i
<
countBits
;
i
++
)
{
for
(
std
::
size_t
i
=
0
;
i
<
countBits
;
i
++
)
{
value
<<=
1
;
value
<<=
1
;
...
...
src/kyut/watermarker/FunctionOrderingWatermarker.cpp
View file @
1fd7d8a7
...
@@ -61,7 +61,7 @@ namespace kyut::watermarker {
...
@@ -61,7 +61,7 @@ namespace kyut::watermarker {
std
::
sort
(
chunkBegin
,
chunkEnd
,
[](
const
auto
&
a
,
const
auto
&
b
)
{
return
a
->
name
<
b
->
name
;
});
std
::
sort
(
chunkBegin
,
chunkEnd
,
[](
const
auto
&
a
,
const
auto
&
b
)
{
return
a
->
name
<
b
->
name
;
});
// A watermark to embed in the chunk
// A watermark to embed in the chunk
auto
watermark
=
stream
.
read
(
numBitsEmbeddedInChunk
);
auto
watermark
=
stream
.
read
<
std
::
uint64_t
>
(
numBitsEmbeddedInChunk
);
// Reorder the functions
// Reorder the functions
for
(
auto
it
=
chunkBegin
;
it
!=
chunkEnd
;
++
it
)
{
for
(
auto
it
=
chunkBegin
;
it
!=
chunkEnd
;
++
it
)
{
...
@@ -109,8 +109,8 @@ namespace kyut::watermarker {
...
@@ -109,8 +109,8 @@ namespace kyut::watermarker {
return
a
->
name
<
b
->
name
;
return
a
->
name
<
b
->
name
;
});
});
std
::
int64_t
watermark
=
0
;
std
::
u
int64_t
watermark
=
0
;
std
::
int64_t
base
=
1
;
std
::
u
int64_t
base
=
1
;
for
(
auto
it
=
chunkBegin
;
it
!=
chunkEnd
;
++
it
)
{
for
(
auto
it
=
chunkBegin
;
it
!=
chunkEnd
;
++
it
)
{
// Get index of the function `*it`
// Get index of the function `*it`
...
...
test/kyut/test_BitStreamWriter.cpp
View file @
1fd7d8a7
...
@@ -42,7 +42,7 @@ BOOST_AUTO_TEST_CASE(write) {
...
@@ -42,7 +42,7 @@ BOOST_AUTO_TEST_CASE(write) {
BOOST_REQUIRE_EQUAL
(
s
.
data
().
size
(),
std
::
size_t
{
0
});
BOOST_REQUIRE_EQUAL
(
s
.
data
().
size
(),
std
::
size_t
{
0
});
BOOST_REQUIRE_EQUAL
(
s
.
tell
(),
std
::
size_t
{
0
});
BOOST_REQUIRE_EQUAL
(
s
.
tell
(),
std
::
size_t
{
0
});
s
.
write
(
0xabcd
,
16
);
s
.
write
(
std
::
uint16_t
{
0xabcd
}
,
16
);
BOOST_REQUIRE_EQUAL
(
s
.
data
().
size
(),
std
::
size_t
{
2
});
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
()[
0
],
std
::
uint8_t
{
0xab
});
BOOST_REQUIRE_EQUAL
(
s
.
data
()[
1
],
std
::
uint8_t
{
0xcd
});
BOOST_REQUIRE_EQUAL
(
s
.
data
()[
1
],
std
::
uint8_t
{
0xcd
});
...
...
test/kyut/test_CircularBitStreamReader.cpp
View file @
1fd7d8a7
...
@@ -43,18 +43,18 @@ BOOST_AUTO_TEST_CASE(read) {
...
@@ -43,18 +43,18 @@ BOOST_AUTO_TEST_CASE(read) {
CircularBitStreamReader
reader
{
std
::
begin
(
data
),
std
::
end
(
data
)};
CircularBitStreamReader
reader
{
std
::
begin
(
data
),
std
::
end
(
data
)};
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
0
});
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
0
});
BOOST_REQUIRE_EQUAL
(
reader
.
read
(
4
),
std
::
uint64
_t
{
0x8
});
BOOST_REQUIRE_EQUAL
(
reader
.
read
<
std
::
uint32_t
>
(
4
),
std
::
uint32
_t
{
0x8
});
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
4
});
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
4
});
BOOST_REQUIRE_EQUAL
(
reader
.
read
(
4
),
std
::
uint64
_t
{
0x9
});
BOOST_REQUIRE_EQUAL
(
reader
.
read
<
std
::
uint32_t
>
(
4
),
std
::
uint32
_t
{
0x9
});
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
8
});
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
8
});
BOOST_REQUIRE_EQUAL
(
reader
.
read
(
8
),
std
::
uint64
_t
{
0xab
});
BOOST_REQUIRE_EQUAL
(
reader
.
read
<
std
::
uint32_t
>
(
8
),
std
::
uint32
_t
{
0xab
});
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
16
});
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
16
});
BOOST_REQUIRE_EQUAL
(
reader
.
read
(
16
),
std
::
uint64
_t
{
0xcdef
});
BOOST_REQUIRE_EQUAL
(
reader
.
read
<
std
::
uint32_t
>
(
16
),
std
::
uint32
_t
{
0xcdef
});
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
32
});
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
32
});
BOOST_REQUIRE_EQUAL
(
reader
.
read
(
24
),
std
::
uint64
_t
{
0x89abcd
});
BOOST_REQUIRE_EQUAL
(
reader
.
read
<
std
::
uint32_t
>
(
24
),
std
::
uint32
_t
{
0x89abcd
});
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
56
});
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
std
::
size_t
{
56
});
}
}
...
...
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