Hey folks, is there an example on how to specify `...
# protobufs
s
Hey folks, is there an example on how to specify
bytes
fields for request/repsonse pairs? Since both request and response are specified via json, you have to pass it as string, but I remember running into issues with such conversion before, where if the bytes is not a valid utf-8 string it would fail. Could be wrong?
When I'm passing raw bytes as a json string I'm currently getting this error:
Copy code
pact_ffi::plugins: Contents is not a valid JSON - control character (\u0000-\u001F) found while parsing a string at line 8 column 27
so it seems like we need to escape this somehow, but I'm not sure how
r
How is the proto message defined?
The reason I ask, as I recall that
bytes
is an alias for the
google.protobuf.BytesValue
message type.
Looks like it does detect a
google.protobuf.BytesValue
type, but expects a string as input. I guess there would be 2 ways to do it. Easiest is to try escape the input string using JSON string escape codes. The other is to update the plugin to support an array of byte values as input, or a BASE64 encoded string.
Oh, looks like a byte array was planned, but the implementation was missed facepalm https://github.com/pactflow/pact-protobuf-plugin/blob/47aa5c78216253a8d0634fd57932a274f1672c4d/tests/basic_values_test.rs#L32
Can you raise a GitHub issue? Pretty please?
s
sure thing, I'll do it tomorrow. Thanks for looking into this!
one of our more special cases is support for Any message type (which internally is just a binary representation anyway), idk if that's helpful
r
Support for Any would require special handling to pack/unpack the concrete type. At the moment it would only support comparing the actual byte arrays.
s
fair enough, let me create separate tickets for byte arrays and Any type. Any type support might actually be somewhat easier to do, because in your config json would look like just another message, rather than a byte array, so you can use the same matchers. The only step (not saying it's easy though) is to unpack the concrete type before running it through matchers, but it might be possible to integrate cleanly. In the input json it might not even need any special handling, just put a matcher for the concrete type as a value of an Any field.