What's the right way to specify matching `[]byte` ...
# protobufs
s
What's the right way to specify matching
[]byte
fields in grpc requests/responses? I'm currently converting it to string, smth like:
Copy code
"bytes": "matching(type, '" + string(bytes) + "')",
is this the right way to go?
Seems to work, but there's one issue. Certain bytes get converted in the response, so the response I receive from the mock server is not the one I specify in the
response
field, so I was wondering if could be related to converting bytes back and forth to/from string
r
That's a good question, I need to investigate that
s
Specifically
0xc0
and
0x86
, maybe others too. Both are always replaced with the same set of bytes:
0xef, 0xbf, 0xbd
and then the test fails because you assert to receive
0xc0
and receive
0xef, 0xbf, 0xbd
instead:
Copy code
expected: []byte{0xc0}
actual  : []byte{0xef, 0xbf, 0xbd}
I wonder if it has something to do with trimming the string or empty characters or something, but they get replaced even when they're in the middle of the sequence. idk if there are some special bytes?
I don't particularly care for specific bytes in this particular test, so I can easily work around it, but was curious
r
It would be treated as UTF-8, which means the bytes are converted to UTF code points. They would have to be escaped correctly.
Better to have another mechanism to define the byte values
👍 1