-
Notifications
You must be signed in to change notification settings - Fork 5
feat: support Protocol Buffers payload inspection #81
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fa93af7
feat: protobuf 페이로드 검사 지원
easyhooon 68e38bf
feat(sample): protobuf 왕복 예시 추가
easyhooon 8adf2a8
fix: Room 3에서 4로 데이터 보존 마이그레이션 추가
easyhooon c323fa6
fix: protobuf decoder 누락 시 안전하게 기록
easyhooon 10c238c
feat: protobuf raw payload 미리보기 추가
easyhooon e1f6199
docs: protobuf 검사 화면 추가
easyhooon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
dari-core/src/main/kotlin/com/easyhooon/dari/MessagePayloadMetadata.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.easyhooon.dari | ||
|
|
||
| /** Metadata retained when a binary payload is rendered as text for inspection. */ | ||
| data class MessagePayloadMetadata( | ||
| val contentType: PayloadContentType, | ||
| val originalSizeBytes: Int, | ||
| val decodeStatus: PayloadDecodeStatus, | ||
| val rawPreview: RawPayloadPreview? = null, | ||
| ) | ||
|
|
||
| /** Bounded binary preview retained for raw payload inspection. */ | ||
| data class RawPayloadPreview( | ||
| val base64: String, | ||
| val previewSizeBytes: Int, | ||
| val truncated: Boolean, | ||
| ) | ||
|
|
||
| enum class PayloadContentType { | ||
| PROTOBUF, | ||
| } | ||
|
|
||
| /** Result of converting a binary payload into inspectable display text. */ | ||
| enum class PayloadDecodeStatus { | ||
| DECODED, | ||
| DECODER_UNAVAILABLE, | ||
| FAILED, | ||
| } |
54 changes: 54 additions & 0 deletions
54
dari-core/src/main/kotlin/com/easyhooon/dari/interceptor/ProtobufDariInterceptor.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package com.easyhooon.dari.interceptor | ||
|
|
||
| import com.easyhooon.dari.MessageDirection | ||
|
|
||
| /** Identifies which side of a bridge exchange a protobuf payload belongs to. */ | ||
| enum class PayloadPart { | ||
| REQUEST, | ||
| RESPONSE, | ||
| } | ||
|
|
||
| data class ProtobufDecodeContext( | ||
| val handlerName: String, | ||
| val direction: MessageDirection, | ||
| val part: PayloadPart, | ||
| ) | ||
|
|
||
| /** | ||
| * Converts protobuf bytes into display text without coupling Dari to a protobuf runtime. | ||
| * Return `null` when the decoder does not recognize the supplied context. | ||
| * Decoding runs synchronously on the interceptor caller's thread. | ||
| */ | ||
| fun interface ProtobufPayloadDecoder { | ||
| fun decode(payload: ByteArray, context: ProtobufDecodeContext): String? | ||
| } | ||
|
|
||
| /** Optional protobuf extension of the existing string-based [DariInterceptor]. */ | ||
| interface ProtobufDariInterceptor : DariInterceptor { | ||
| fun onWebToAppProtobufRequest( | ||
| handlerName: String, | ||
| requestId: String?, | ||
| requestData: ByteArray, | ||
| fireAndForget: Boolean? = null, | ||
| ) | ||
|
|
||
| fun onWebToAppProtobufResponse( | ||
| handlerName: String, | ||
| requestId: String?, | ||
| responseData: ByteArray, | ||
| isSuccess: Boolean, | ||
| ) | ||
|
|
||
| fun onAppToWebProtobufRequest( | ||
| handlerName: String, | ||
| requestId: String?, | ||
| requestData: ByteArray, | ||
| fireAndForget: Boolean? = null, | ||
| ) | ||
|
|
||
| fun onAppToWebProtobufResponse( | ||
| requestId: String?, | ||
| isSuccess: Boolean, | ||
| responseData: ByteArray, | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
dari/src/main/kotlin/com/easyhooon/dari/RawPayloadFormatter.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.easyhooon.dari | ||
|
|
||
| import java.util.Base64 | ||
|
|
||
| internal object RawPayloadFormatter { | ||
| fun formatHex(preview: RawPayloadPreview): String { | ||
| val bytes = runCatching { | ||
| Base64.getDecoder().decode(preview.base64) | ||
| }.getOrElse { | ||
| return "(raw preview unavailable)" | ||
| } | ||
| if (bytes.isEmpty()) return "(empty)" | ||
|
|
||
| return bytes.asIterable() | ||
| .chunked(16) | ||
| .joinToString("\n") { line -> | ||
| line.joinToString(" ") { byte -> "%02X".format(byte.toInt() and 0xFF) } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Add alternative text to both screenshots.
The
<img>elements on Lines 176 and 177 have noaltattributes. Add concise descriptions for screen-reader users.Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 markdownlint-cli2 (0.23.1)
[warning] 176-176: Images should have alternate text (alt text)
(MD045, no-alt-text)
[warning] 177-177: Images should have alternate text (alt text)
(MD045, no-alt-text)
🤖 Prompt for AI Agents
Source: Linters/SAST tools