Unable to use Protobuf primitive wrapper types #2543
-
I am trying to deserialize Protobuf messages that use the Any type, and uses some of the wrapper types for compatibility with primitive types. Particularly those found here. Here is a minimal example that demonstrates the issue I am running into. The following works:
syntax = "proto3";
import "google/protobuf/any.proto";
message PersonWorks {
string name = 1;
bool is_tall = 2;
}
message PersonBroken {
google.protobuf.Any name = 1;
google.protobuf.Any is_tall = 2;
}
input:
generate:
mapping: |
root.name = fake("name")
root.isTall = random_int(max:1) == 1
interval: 1s
count: 10
pipeline:
processors:
- protobuf:
operator: from_json
message: "PersonWorks"
import_paths: [.]
- protobuf:
operator: to_json
message: "PersonWorks"
import_paths: [.] (worth noting that the round trip maps But this does not: input:
generate:
mapping: |
root.name = fake("name")
root.isTall = random_int(max:1) == 1
interval: 1s
count: 10
pipeline:
processors:
- mapping: |
root.name = {
"@type": "type.googleapis.com/google.protobuf.StringValue",
"value": this.name
}
root.isTall = {
"@type": "type.googleapis.com/google.protobuf.BoolValue",
"value": this.isTall
}
- protobuf:
operator: from_json
message: "PersonBroken"
import_paths: [.]
- catch:
- log:
level: ERROR
message: "Error: ${!error()}"
- mapping: |
root = deleted()
# - protobuf:
# operator: to_json
# message: "PersonBroken"
# import_paths: [.] It fails with the following log:
If I remove the import (
// ...
_ "google.golang.org/protobuf/types/wrapperspb"
) xor import (
// ...
_ "github.com/golang/protobuf/ptypes/wrappers"
) to |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Surprisingly though this actually works:
syntax = "proto3";
import "google/protobuf/wrappers.proto";
message PersonWorks {
string name = 1;
bool is_tall = 2;
}
message PersonBroken {
google.protobuf.StringValue name = 1;
google.protobuf.BoolValue is_tall = 2;
}
input:
generate:
mapping: |
root.name = fake("name")
root.isTall = random_int(max:1) == 1
interval: 1s
count: 10
pipeline:
processors:
- protobuf:
operator: from_json
message: "PersonBroken"
import_paths: [.]
- catch:
- log:
level: ERROR
message: "Error: ${!error()}"
- mapping: |
root = deleted()
- protobuf:
operator: to_json
message: "PersonBroken"
import_paths: [.] This is with the latest on |
Beta Was this translation helpful? Give feedback.
-
Hey @Zambito1 I think you'll have to configure PS: Converting to a discussion as mentioned in #2026. |
Beta Was this translation helpful? Give feedback.
Hey @Zambito1 I think you'll have to configure
import_paths
and add in there the path to wherever you installprotoc
on your platform (guess the platform doesn't really matter much in this case, since you only need the.proto
files). You can get the latest release here: https://github.com/protocolbuffers/protobuf/releases/latest. It should contain aninclude
folder which has the files you need.PS: Converting to a discussion as mentioned in #2026.