Class Encoding

  • All Implemented Interfaces:

    
    public final class Encoding
    
                        

    Default encoding values used by Zenoh.

    An encoding has a similar role to Content-type in HTTP: it indicates, when present, how data should be interpreted by the application.

    Please note the Zenoh protocol does not impose any encoding value, nor it operates on it. It can be seen as some optional metadata that is carried over by Zenoh in such a way the application may perform different operations depending on the encoding value.

    A set of associated constants are provided to cover the most common encodings for user convenience.

    An encoding is its decomposed pair (id, schema) — Zenoh's own representation. This class is a plain immutable value; all conversion logic (the id↔name table and Zenoh's parse/render rules) lives in the shared bindings tier (EncodingCodec), verified against the native implementation by EncodingCorrespondenceTest. Nothing to close: identity, equality and rendering never touch the native side.

    Sends are shaped to MINIMIZE JNI CROSSINGS. The predefined constants stay value-only: a send carries just their id inside the send call itself — no native handle ever exists for them. An encoding that already owns a native handle sends it as a bare jlong instead (the native side borrows and clones it, so the handle is reusable forever). Handles are born ONLY at construction of a custom (schema-carrying) encoding — construction is the one crossing. Received encodings (sample/query/reply) are always value-only (id, schema): delivering a handle with each message measurably cost more than the schema re-decode it saved when one was re-sent, so a re-sent received encoding crosses through the (id, schema) value arm instead. Handle release is GC-managed (the JNI Encoding class is gc_managed — a shared Cleaner frees the native box once the handle is unreachable) — the value stays non-closeable either way.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      public class Encoding.Companion
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Constructor Detail

    • Method Detail

      • withSchema

         final Encoding withSchema(String schema)

        Set a schema to this encoding. Zenoh does not define what a schema is and its semantics is left to the implementer. E.g. a common schema for text/plain encoding is utf-8.

        The result is a custom encoding, so its native handle is created here — construction is the one crossing, every send after is a bare jlong.