Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
谢明辉
/
recv_data_longhua
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit d50e9720
authored
Sep 23, 2020
by
zhangxk
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
事件、流量增加CRC校验
1 parent
d54a7a66
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
4 deletions
src/main/java/com/viontech/model/BehaviorModel.java
src/main/java/com/viontech/model/FlowModel.java
src/main/java/com/viontech/model/BehaviorModel.java
View file @
d50e972
...
...
@@ -9,6 +9,8 @@ import io.netty.buffer.ByteBufUtil;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.util.zip.CRC32
;
/**
* .
*
...
...
@@ -100,8 +102,24 @@ public class BehaviorModel extends BaseModel {
buffer
.
writeBytes
(
reservedField2
);
buffer
.
writeBytes
(
picture
);
this
.
data
=
new
byte
[
buffer
.
readableBytes
()];
buffer
.
readBytes
(
this
.
data
);
byte
[]
bytes
=
new
byte
[
buffer
.
readableBytes
()];
buffer
.
readBytes
(
bytes
);
buffer
.
release
();
int
count
=
bytes
.
length
;
// crc32
CRC32
crc32
=
new
CRC32
();
crc32
.
update
(
bytes
);
int
value
=
(
int
)
crc32
.
getValue
();
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
bytes
[
i
]
=
(
byte
)
(
bytes
[
i
]
^
0x94
);
}
this
.
data
=
new
byte
[
count
+
4
];
System
.
arraycopy
(
bytes
,
0
,
data
,
0
,
count
);
this
.
data
[
count
++]
=
(
byte
)
value
;
this
.
data
[
count
++]
=
(
byte
)
(
value
>>
8
);
this
.
data
[
count
++]
=
(
byte
)
(
value
>>
16
);
this
.
data
[
count
]
=
(
byte
)
(
value
>>
24
);
}
}
src/main/java/com/viontech/model/FlowModel.java
View file @
d50e972
...
...
@@ -6,6 +6,8 @@ import io.netty.buffer.ByteBufAllocator;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.util.zip.CRC32
;
/**
* .
*
...
...
@@ -62,8 +64,24 @@ public class FlowModel extends BaseModel {
buffer
.
writeIntLE
(
i
);
}
buffer
.
writeBytes
(
reservedField
);
this
.
data
=
new
byte
[
buffer
.
readableBytes
()];
buffer
.
readBytes
(
this
.
data
);
byte
[]
bytes
=
new
byte
[
buffer
.
readableBytes
()];
buffer
.
readBytes
(
bytes
);
buffer
.
release
();
int
count
=
bytes
.
length
;
// crc32
CRC32
crc32
=
new
CRC32
();
crc32
.
update
(
bytes
);
int
value
=
(
int
)
crc32
.
getValue
();
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
bytes
[
i
]
=
(
byte
)
(
bytes
[
i
]
^
0x94
);
}
this
.
data
=
new
byte
[
count
+
4
];
System
.
arraycopy
(
bytes
,
0
,
data
,
0
,
count
);
this
.
data
[
count
++]
=
(
byte
)
value
;
this
.
data
[
count
++]
=
(
byte
)
(
value
>>
8
);
this
.
data
[
count
++]
=
(
byte
)
(
value
>>
16
);
this
.
data
[
count
]
=
(
byte
)
(
value
>>
24
);
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment