I’m trying to send what is originally a string of "pub fun main(): Int { return 1 }"
to a gRPC server as :bytes
. :bytes
is a protobuf data type. See the struct below for the generated Elixir module for the particular protobuf I’m working with.
Problem: How do you convert a binary into this expected format?
Easy enough if it’s a hex value like "F8D6E0586B0A20C7"
. I’d be able to do
Base.decode16!("F8D6E0586B0A20C7")
. But with a complex string that has more than just hex-accepted values?
Generated protobuf module
defmodule Flow.Access.ExecuteScriptAtLatestBlockRequest do
@moduledoc false
use Protobuf, syntax: :proto3
@type t :: %__MODULE__{
script: binary,
arguments: [binary]
}
defstruct [:script, :arguments]
field :script, 1, type: :bytes
field :arguments, 2, repeated: true, type: :bytes
end