- protobuf_segment_convert(+Form1, ?Form2) is multi[private]
- A convenience predicate for dealing with the situation where
protobuf_segment_message/2 interprets a segment of the wire stream
as a form that you don't want (e.g., as a message but it should have
been a UTF8 string).
Form1
is converted back to the original wire stream, then the predicate non-deterimisticly attempts to convert the wire stream to astring
orlength_delimited
term (or both: the lattter always succeeds).The possible conversions are:
message(Tag,Segments)
=>string(Tag,String)
message(Tag,Segments)
=>length_delimited(Tag,Codes)
string(Tag,String)
=>length_delimited(Tag,Codes)
length_delimited(Tag,Codes)
=>length_delimited(Tag,Codes)
Note that for fixed32, fixed64, only the signed integer forms are given; if you want the floating point forms, then you need to do use int64_float64_when/2 and int32_float32_when/2.
For example: ~~~{.pl} ?-
protobuf_segment_convert( message(10,[fixed64(13,7309475598860382318)]), string(10,"inputType"))
. ?-protobuf_segment_convert( message(10,[fixed64(13,7309475598860382318)]), length_delimited(10,[105,110,112,117,116,84,121,112,101]))
. ?-protobuf_segment_convert( string(10, "inputType"), length_delimited(10,[105,110,112,117,116,84,121,112,101]))
. ?-forall(protobuf_segment_convert(string(1999,"\x1\\x0\\x0\\x0\\x2\\x0\\x0\\x0\"),Z), writeln(Z))
. string(1999,