- 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:
?- 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, ) packed(1999,fixed64([8589934593])) packed(1999,fixed32([1,2])) packed(1999,varint([1,0,0,0,2,0,0,0])) length_delimited(1999,[1,0,0,0,2,0,0,0])
These come from:
Codes = [82,9,105,110,112,117,116,84,121,112,101], protobuf_message(protobuf([embedded(T1, protobuf([integer64(T2, I)]))]), Codes), protobuf_message(protobuf([string(T,S)]), Codes). T = 10, T1 = 10, T2 = 13, I = 7309475598860382318, S = "inputType".