persolijn

an efficient router for busses
Log | Files | Refs

WireType.java (2503B)


      1 package protobuf;
      2 
      3 /**
      4  * Enum representing Protobuf wire types along with their associated possible
      5  * Protobuf types.
      6  */
      7 public enum WireType {
      8 
      9     /**
     10      * Wire type for variable-length integers.
     11      */
     12     VARINT(0, "int32", "int64", "uint32", "uint64", "sint32", "sint64", "bool", "enum"),
     13 
     14     /**
     15      * Wire type for 64-bit fixed-length values.
     16      */
     17     I64(1, "fixed64", "sfixed64", "double"),
     18 
     19     /**
     20      * Wire type for length-delimited data (strings, bytes, embedded messages, and
     21      * packed repeated fields).
     22      */
     23     LEN(2, "string", "bytes", "embedded messages", "packed repeated fields"),
     24 
     25     /**
     26      * Wire type for the start of a deprecated group.
     27      */
     28     SGROUP(3, "group start (deprecated)"),
     29 
     30     /**
     31      * Wire type for the end of a deprecated group.
     32      */
     33     EGROUP(4, "group end (deprecated)"),
     34 
     35     /**
     36      * Wire type for 32-bit fixed-length values.
     37      */
     38     I32(5, "fixed32", "sfixed32", "float");
     39 
     40     /**
     41      * The numeric value associated with the wire type.
     42      */
     43     public final int value;
     44 
     45     /**
     46      * An array of possible Protobuf types associated with this wire type.
     47      */
     48     private final String[] possibleTypes;
     49 
     50     /**
     51      * Constructs a WireType enum constant with the specified value and possible
     52      * types.
     53      *
     54      * @param value         The numeric value associated with the wire type.
     55      * @param possibleTypes An array of possible Protobuf types associated with this
     56      *                      wire type.
     57      */
     58     private WireType(int value, String... possibleTypes) {
     59         this.value = value;
     60         this.possibleTypes = possibleTypes;
     61     }
     62 
     63     /**
     64      * Gets the possible Protobuf types associated with this wire type.
     65      *
     66      * @return An array of possible Protobuf types.
     67      */
     68     public String[] getPossibleTypes() {
     69         return possibleTypes;
     70     }
     71 
     72     /**
     73      * Returns a string representation of this wire type, including its name and
     74      * possible types.
     75      *
     76      * @return A string representation of this wire type.
     77      */
     78     @Override
     79     public String toString() {
     80         StringBuilder builder = new StringBuilder();
     81         builder.append(this.name());
     82         builder.append(" (");
     83 
     84         for (int i = 0; i < possibleTypes.length; i++) {
     85             if (i > 0)
     86                 builder.append(", ");
     87             builder.append(possibleTypes[i]);
     88             builder.append(')');
     89         }
     90         builder.append(')');
     91 
     92         return builder.toString();
     93     }
     94 }