Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(msg): cbor support on publisher #1563

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/MsgPublish.vue
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export default class MsgPublish extends Vue {
}
private payloadLang = 'json'
private payloadType: PayloadType = 'JSON'
private payloadOptions: PayloadType[] = ['Plaintext', 'JSON', 'Base64', 'Hex']
private payloadOptions: PayloadType[] = ['Plaintext', 'JSON', 'Base64', 'Hex', 'CBOR']

@Watch('editorHeight')
private handleHeightChanged() {
Expand Down
18 changes: 16 additions & 2 deletions src/views/connections/ConnectionsDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ export default class ConnectionsDetail extends Vue {
this.updateMeta(receivedMessage, 'function', 'received')
this.updateMeta(receivedMessage, 'schema', 'received')
this.updateMetaMsgType(receivedMessage, this.receivedMsgType)
if (this.receivedMsgType === 'JSON' && jsonMsgError) {
if (['JSON', 'CBOR'].includes(this.receivedMsgType) && jsonMsgError) {
this.updateMetaError(receivedMessage, jsonMsgError)
}

Expand Down Expand Up @@ -1641,6 +1641,16 @@ export default class ConnectionsDetail extends Vue {
return undefined
}
}
if (publishType === 'CBOR') {
try {
return cbor.encodeOne(JSON.parse(publishValue))
} catch (error) {
const err = error as Error
let errorMessage = `${this.$t('connections.publishMsg')} ${err.toString()}`
this.$message.error(errorMessage)
return undefined
}
}
return publishValue
}
const genReceivePayload = (receiveType: PayloadType, receiveValue: Buffer) => {
Expand All @@ -1662,7 +1672,11 @@ export default class ConnectionsDetail extends Vue {
}
}
if (receiveType === 'CBOR') {
return jsonStringify(cbor.decodeFirstSync(receiveValue), null, 2)
try {
return jsonStringify(cbor.decodeFirstSync(receiveValue), null, 2)
} catch (error) {
throw error
}
}
return receiveValue.toString()
}
Expand Down