Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
controller
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TFS
controller
Commits
3b95df29
Commit
3b95df29
authored
3 years ago
by
Konstantin Munichev
Browse files
Options
Downloads
Patches
Plain Diff
Encode protobuf payloads as Base64 strings before to put them into Fabric
parent
16269696
No related branches found
Branches containing commit
Tags
v1.0.0-release
Tags containing commit
2 merge requests
!54
Release 2.0.0
,
!16
DLT component (and related) improvements
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/dlt/gateway/src/main/kotlin/Main.kt
+6
-1
6 additions, 1 deletion
src/dlt/gateway/src/main/kotlin/Main.kt
src/dlt/gateway/src/main/kotlin/fabric/FabricConnector.kt
+9
-8
9 additions, 8 deletions
src/dlt/gateway/src/main/kotlin/fabric/FabricConnector.kt
with
15 additions
and
9 deletions
src/dlt/gateway/src/main/kotlin/Main.kt
+
6
−
1
View file @
3b95df29
...
...
@@ -118,7 +118,12 @@ fun main() = runBlocking {
val
data
=
DltGateway
.
DltRecord
.
newBuilder
()
.
setRecordId
(
id
)
.
setOperation
(
DltGateway
.
DltRecordOperationEnum
.
DLTRECORDOPERATION_ADD
)
.
setDataJson
(
"{}"
)
.
setDataJson
(
"\"{\"device_config\": {\"config_rules\": []}, \"device_drivers\": [],"
+
"\"device_endpoints\": [], \"device_id\": {\"device_uuid\": {\"uuid\": \"dev-12345\"}},"
+
"\"device_operational_status\": \"DEVICEOPERATIONALSTATUS_ENABLED\","
+
"\"device_type\": \"packet-router\"}\", \"operation\": \"DLTRECORDOPERATION_ADD\","
+
"\"record_id\": {\"domain_uuid\": {\"uuid\": \"tfs-a\"}, \"record_uuid\": {\"uuid\": \"dev-12345\"},"
+
"\"type\": \"DLTRECORDTYPE_DEVICE\"}"
)
.
build
()
println
(
"sending new record"
)
...
...
This diff is collapsed.
Click to expand it.
src/dlt/gateway/src/main/kotlin/fabric/FabricConnector.kt
+
9
−
8
View file @
3b95df29
...
...
@@ -60,6 +60,9 @@ class FabricConnector(val config: Config.DltConfig) {
private
val
channels
:
MutableList
<
Channel
<
DltRecordEvent
>>
=
mutableListOf
()
private
val
encoder
:
Base64
.
Encoder
=
Base64
.
getEncoder
()
private
val
decoder
:
Base64
.
Decoder
=
Base64
.
getDecoder
()
init
{
// Create a CA client for interacting with the CA.
val
props
=
Properties
()
...
...
@@ -80,7 +83,7 @@ class FabricConnector(val config: Config.DltConfig) {
val
consumer
=
Consumer
{
event
:
ContractEvent
?
->
run
{
println
(
"new event detected"
)
val
record
=
DltRecord
.
parseFrom
(
event
?.
payload
?.
get
())
val
record
=
DltRecord
.
parseFrom
(
decoder
.
decode
(
event
?.
payload
?.
get
())
)
println
(
record
.
recordId
.
recordUuid
)
val
eventType
:
ContextOuterClass
.
EventTypeEnum
=
when
(
event
?.
name
)
{
"Add"
->
ContextOuterClass
.
EventTypeEnum
.
EVENTTYPE_CREATE
...
...
@@ -118,13 +121,12 @@ class FabricConnector(val config: Config.DltConfig) {
fun
putData
(
record
:
DltRecord
):
String
{
println
(
record
.
toString
())
println
(
"Put: ${record.toByteArray().decodeToString().length}"
)
try
{
contract
.
submitTransaction
(
"AddRecord"
,
record
.
recordId
.
recordUuid
.
uuid
,
record
.
toByteArray
()
.
decodeToString
(
)
encoder
.
encodeToString
(
record
.
toByteArray
())
)
}
catch
(
e
:
Exception
)
{
println
(
e
.
toString
())
...
...
@@ -134,13 +136,12 @@ class FabricConnector(val config: Config.DltConfig) {
}
fun
getData
(
uuid
:
String
):
DltRecord
{
try
{
return
try
{
val
result
=
contract
.
evaluateTransaction
(
"GetRecord"
,
uuid
)
println
(
"Get: ${result.size}"
)
return
DltRecord
.
parseFrom
(
result
)
DltRecord
.
parseFrom
(
decoder
.
decode
(
result
))
}
catch
(
e
:
Exception
)
{
println
(
e
.
toString
())
return
DltRecord
.
getDefaultInstance
()
DltRecord
.
getDefaultInstance
()
}
}
...
...
@@ -149,7 +150,7 @@ class FabricConnector(val config: Config.DltConfig) {
contract
.
submitTransaction
(
"UpdateRecord"
,
record
.
recordId
.
recordUuid
.
uuid
,
record
.
toByteArray
()
.
decodeToString
(
)
encoder
.
encodeToString
(
record
.
toByteArray
())
)
}
catch
(
e
:
Exception
)
{
return
e
.
toString
()
...
...
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