-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(vrl): Add documentation for parse_proto and encode_proto (#20139)
* docs(vrl): Add documentation for parse_proto and encode_proto (vectordotdev/vrl#739) * Add spellcheck exception Signed-off-by: Jesse Szwedko <[email protected]> * Add ignore pattern for base64 Signed-off-by: Jesse Szwedko <[email protected]> * Update pattern Signed-off-by: Jesse Szwedko <[email protected]> * Fix pattern Signed-off-by: Jesse Szwedko <[email protected]> * another try Signed-off-by: Jesse Szwedko <[email protected]> * cue formatting Signed-off-by: Jesse Szwedko <[email protected]> * update tests Signed-off-by: Jesse Szwedko <[email protected]> * Ignore desc files in syntax check Signed-off-by: Jesse Szwedko <[email protected]> --------- Signed-off-by: Jesse Szwedko <[email protected]> Co-authored-by: Jesse Szwedko <[email protected]>
- Loading branch information
Showing
5 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Binary file not shown.
This file contains 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 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,52 @@ | ||
package metadata | ||
|
||
remap: functions: encode_proto: { | ||
category: "Codec" | ||
description: """ | ||
Encodes the `value` into a protocol buffer payload. | ||
""" | ||
|
||
arguments: [ | ||
{ | ||
name: "value" | ||
description: "The object to convert to a protocol buffer payload." | ||
required: true | ||
type: ["object"] | ||
}, | ||
{ | ||
name: "desc_file" | ||
description: """ | ||
The path to the protobuf descriptor set file. Must be a literal string. | ||
This file is the output of protoc -o <path> ... | ||
""" | ||
required: true | ||
type: ["string"] | ||
}, | ||
{ | ||
name: "message_type" | ||
description: """ | ||
The name of the message type to use for serializing. | ||
Must be a literal string. | ||
""" | ||
required: true | ||
type: ["string"] | ||
}, | ||
] | ||
internal_failure_reasons: [ | ||
"`desc_file` file does not exist.", | ||
"`message_type` message type does not exist in the descriptor file.", | ||
] | ||
return: types: ["string"] | ||
|
||
examples: [ | ||
{ | ||
title: "Encode to proto" | ||
source: #""" | ||
.payload = encode_base64(encode_proto!({"name": "someone", "phones": [{"number": "123456"}]}, "resources/protobuf_descriptor_set.desc", "test_protobuf.Person")) | ||
"""# | ||
return: #"Cgdzb21lb25lIggKBjEyMzQ1Ng=="# | ||
}, | ||
] | ||
} |
This file contains 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,65 @@ | ||
package metadata | ||
|
||
remap: functions: parse_proto: { | ||
category: "Parse" | ||
description: """ | ||
Parses the `value` as a protocol buffer payload. | ||
""" | ||
notices: [ | ||
""" | ||
Only proto messages are parsed and returned. | ||
""", | ||
] | ||
|
||
arguments: [ | ||
{ | ||
name: "value" | ||
description: "The protocol buffer payload to parse." | ||
required: true | ||
type: ["string"] | ||
}, | ||
{ | ||
name: "desc_file" | ||
description: """ | ||
The path to the protobuf descriptor set file. Must be a literal string. | ||
This file is the output of protoc -o <path> ... | ||
""" | ||
required: true | ||
type: ["string"] | ||
}, | ||
{ | ||
name: "message_type" | ||
description: """ | ||
The name of the message type to use for serializing. | ||
Must be a literal string. | ||
""" | ||
required: true | ||
type: ["string"] | ||
}, | ||
] | ||
internal_failure_reasons: [ | ||
"`value` is not a valid proto payload.", | ||
"`desc_file` file does not exist.", | ||
"`message_type` message type does not exist in the descriptor file.", | ||
] | ||
return: types: ["object"] | ||
|
||
examples: [ | ||
{ | ||
title: "Parse proto" | ||
source: #""" | ||
parse_proto!(decode_base64!("Cgdzb21lb25lIggKBjEyMzQ1Ng=="), "resources/protobuf_descriptor_set.desc", "test_protobuf.Person") | ||
"""# | ||
return: { | ||
name: "someone" | ||
phones: [ | ||
{ | ||
number: "123456" | ||
}, | ||
] | ||
} | ||
}, | ||
] | ||
} |