Package biopb.image

Class ArgCodec

java.lang.Object
biopb.image.ArgCodec

public final class ArgCodec extends Object
Ops arguments and results: values and pixels to and from Arg.

An Arg is pixels (inline, or a reference to a tensor on a plane) or anything else as a protobuf Value. Both sides of the wire use these: a client encodes what it sends and decodes what comes back, a server the reverse. The Java twin of Python's biopb.image._arg.

JSON values are null, Boolean, Number, String, a Map with string keys, and a Iterable or array of these. A pixel array is a RandomAccessibleInterval.

  • Field Details

    • NDIM_LABELS

      public static final Map<Integer,List<String>> NDIM_LABELS
      The axes an unlabelled array of each rank is taken to have, as Python's row-major arrays have them: an interval's dimension 0 is the first label. An interval whose dimension 0 is X (imglib2's usual order) must pass its own labels to encodeArg(Object, List).
  • Method Details

    • jsonArg

      public static Arg jsonArg(Object value)
      value as a JSON Arg.
      Throws:
      IllegalArgumentException - a value of a type with no JSON form
    • jsonValue

      public static Object jsonValue(com.google.protobuf.Value value, boolean ints)
      A Value as plain Java: null, Boolean, Double or Long, String, Map<String, Object> and List<Object>.

      A protobuf number is always a double. With ints, an integral one comes back as a Long, so a count the sender wrote as 6 reads as 6, not 6.0.

    • encodeArg

      public static Arg encodeArg(Object value)
      value as an Arg: a RandomAccessibleInterval as inline pixels, anything else as JSON. The array's axes are labelled by NDIM_LABELS for its rank.
    • encodeArg

      public static Arg encodeArg(Object value, List<String> dimLabels)
      encodeArg(Object) with dimLabels naming an array's axes (one per dimension); null takes NDIM_LABELS. Ignored for a value that is not an array.
    • decodeArg

      public static Object decodeArg(Arg arg)
      decodeArg(Arg, boolean) reading integral numbers as Long.
    • decodeArg

      public static Object decodeArg(Arg arg, boolean ints)
      An Arg as Java: JSON as plain values (see jsonValue(com.google.protobuf.Value, boolean) for ints), inline pixels as a RandomAccessibleInterval, and a reference as the lazy interval it names, read from its plane on demand.
      Throws:
      IllegalArgumentException - an empty Arg