Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PacketLib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andrea Bulgarelli
PacketLib
Commits
25b5e3f9
Commit
25b5e3f9
authored
10 years ago
by
Andrea Zoli
Browse files
Options
Downloads
Patches
Plain Diff
Add ByteStream functions getPaddedCopy() and getUnpaddedCopy().
parent
98f2ff57
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/ByteStream.h
+14
-0
14 additions, 0 deletions
include/ByteStream.h
src/ByteStream.cpp
+36
-0
36 additions, 0 deletions
src/ByteStream.cpp
with
50 additions
and
0 deletions
include/ByteStream.h
+
14
−
0
View file @
25b5e3f9
...
...
@@ -107,6 +107,20 @@ public:
/// Gets the dimension of the stream
dword
size
();
/// Create a copy of the stream with some additional padding. The stream is divided into chunks
/// with numberOfChunks = size() / chunkSize.
/// \param chunkSize the size of a chunk without padding.
/// \param padSize Size of the padding.
/// \return The padded copy of this byte stream.
ByteStreamPtr
getPaddedCopy
(
dword
chunkSize
,
dword
padSize
);
/// Create a copy of the stream removing some padding. The stream is divided into chunks
/// with numberOfChunks = size() / chunkSize.
/// \param chunkSize the size of a chunk with padding.
/// \param padSize Size of the padding.
/// \return The unpadded copy of this byte stream.
ByteStreamPtr
getUnpaddedCopy
(
dword
chunkSize
,
dword
padSize
);
char
*
printStreamInHexadecimal
();
/// Get type of allocations.
...
...
This diff is collapsed.
Click to expand it.
src/ByteStream.cpp
+
36
−
0
View file @
25b5e3f9
...
...
@@ -496,6 +496,42 @@ void PacketLib::ByteStream::deleteStreamMemory()
delete
[]
stream
;
}
ByteStreamPtr
PacketLib
::
ByteStream
::
getPaddedCopy
(
dword
chunkSize
,
dword
padSize
)
{
if
(
byteInTheStream
%
chunkSize
!=
0
)
throw
new
PacketException
(
"getPadCopy() error. Chunk size must be a divisor of ByteStream::size()."
);
dword
nChunks
=
byteInTheStream
/
chunkSize
;
dword
newChunkSize
=
chunkSize
+
padSize
;
ByteStreamPtr
sPtr
=
ByteStreamPtr
(
new
ByteStream
(
nChunks
*
(
newChunkSize
),
bigendian
));
byte
*
raw
=
sPtr
->
getStream
();
for
(
dword
i
=
0
;
i
<
nChunks
;
i
++
)
memcpy
(
raw
+
i
*
newChunkSize
,
stream
+
i
*
chunkSize
,
chunkSize
);
return
sPtr
;
}
ByteStreamPtr
PacketLib
::
ByteStream
::
getUnpaddedCopy
(
dword
chunkSize
,
dword
padSize
)
{
if
(
byteInTheStream
%
chunkSize
!=
0
)
throw
new
PacketException
(
"getUnpadCopy() error. Chunk size must be a divisor of ByteStream::size()."
);
if
(
chunkSize
-
padSize
<=
0
)
throw
new
PacketException
(
"getUnpadCopy() error. Chunk size - pad size gives a value <= 0."
);
dword
nChunks
=
byteInTheStream
/
chunkSize
;
dword
newChunkSize
=
chunkSize
-
padSize
;
ByteStreamPtr
sPtr
=
ByteStreamPtr
(
new
ByteStream
(
nChunks
*
(
newChunkSize
),
bigendian
));
byte
*
raw
=
sPtr
->
getStream
();
for
(
dword
i
=
0
;
i
<
nChunks
;
i
++
)
memcpy
(
raw
+
i
*
newChunkSize
,
stream
+
i
*
chunkSize
,
newChunkSize
);
return
sPtr
;
}
void
PacketLib
::
ByteStream
::
swapWord
()
{
dword
dim
=
byteInTheStream
;
for
(
dword
i
=
0
;
i
<
dim
;
i
+=
2
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment