• Places
    • Home
    • Graphs
    • Prefixes
  • Admin
    • Users
    • Settings
    • Plugins
    • Statistics
  • CPACK
    • Home
    • List packs
    • Submit pack
  • Repository
    • Load local file
    • Load from HTTP
    • Load from library
    • Remove triples
    • Clear repository
  • Query
    • YASGUI SPARQL Editor
    • Simple Form
    • SWISH Prolog shell
  • Help
    • Documentation
    • Tutorial
    • Roadmap
    • HTTP Services
  • Login

1.4 The low-level SWI-Prolog Implementation
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • Google's Protocol Buffers Library
        • Google's Protocol Buffers
          • The low-level SWI-Prolog Implementation
            • Wiretypes
            • Tags (field numbers)
            • Basic Usage
            • Alternation, Aggregation, Encapsulation, and Enumeration
            • Groups (deprecated)
            • Advanced Topics

1.4.1 Wiretypes

The wire-stream consists of six primitive payload types, two of which have been deprecated. A primitive in the wire-stream is a multi-byte string that provides three pieces of information: a wire-type, a user-specified tag (field number), and the raw payload. Except for the tag and its wire-type, protobuf payloads are not instantaneously recognizable because the wire-stream contains no payload type information. The interpreter uses the tag to associate the raw payload with a local host type specified by the template. Hence, the message can only be properly decoded using the template that was used to encode it. Note also that the primitive is interpreted according to the needs of a local host. Local word-size and endianness are dealt with at this level.

The following table shows the association between the types in the .proto file and the primitives used in the wire-stream. For how these correspond to other programming languages, such as C++, Java, etc. see Protocol Buffers Scalar Value Types, which also has advice on how to choose between the various integer types. (Python3 types are also given here, because Python is used in some of the interoperability tests.)

Prolog Wirestream .proto file C++ Python3 Notes
doublefixed64doubledoublefloat
unsigned64fixed64fixed64uint64int
integer64fixed64sfixed64int64
floatfixed32floatfloatfloat
unsigned32fixed32fixed32uint32int
integer32fixed32sfixed32int32
integervarintsint32int32int1, 2, 9
integervarintsint64int64int1, 2, 9
signed32varintint32int32int2, 3, 10
signed64varintint64int64int2, 3, 10
unsignedvarintuint32uint32int2, 3
unsignedvarintuint64uint64int2, 3
booleanvarintboolboolbool2, 8
enumvarint(enum)(enum)(enum)
atomlength delimitedstringstr (unicode)
codeslength delimitedbytesbytes
utf8_codeslength delimitedstringstr (unicode)
stringlength delimitedstringstringstr (unicode)
embeddedlength delimitedmessage(class)5
repeatedlength delimitedrepeated(list)6
repeated_embeddedlength delimitedrepeated(list)11
packedlength delimitedpacked repeated(list)

Notes:

  1. Encoded using a compression technique known as zig-zagging, which is more efficient for negative values, but which is slightly less efficient if you know the values will always be non-negative.
  2. Encoded as a modulo 128 string. Its length is proportional to its magnitude. The intrinsic word length is decoupled between parties. If zig-zagging is not used (see note 1), negative numbers become maximum length.
  3. SWI-Prolog has unbounded integers, so an unsigned integer isn't a special case (it is range-checked and an exception thrown if its representation would require more than 32 or 64 bits).
  4. Encoded as UTF8 in the wire-stream.
  5. Specified as embedded(Tag,protobuf([...])).
  6. Specified as repeated(Tag,Type([...,...])), where Type is =unsigned, integer, string, etc.
  7. repeated ... [packed=true] in proto2. Can not contain "length delimited" types.
  8. Prolog boolean(Tag,false) maps to 0 and boolean(Tag,true) maps to 1.
  9. Uses "zig-zag" encoding, which is more space-efficient for negative numbers.
  10. The documentation says that this doesn't use "zig-zag" encoding, so it's less space-efficient for negative numbers. In particular, both C++ and Python encode negative numbers as 10 bytes, and this implementation does the same for wire-stream compatibility (note that SWI-Prolog typically uses 64-bit integers anyway). Therefore, signed64 is used for both .proto types int32 and int64.
  11. Specified as repeated_embedded(Tag,protobuf([...]),Fields)

ClioPatria (version V3.1.1-51-ga0b30a5)