1 package software.amazon.awssdk.crt.eventstream; 2 3 import software.amazon.awssdk.crt.CrtRuntimeException; 4 5 /** 6 * Java mirror of the native aws_event_stream_header_value_type enum, specifying properties of 7 * the type of a header's value 8 */ 9 public enum HeaderType { 10 BooleanTrue(0, 0,false), 11 BooleanFalse(1, 0,false), 12 Byte(2, 0,false), 13 Int16(3, 0,false), 14 Int32(4, 0,false), 15 Int64(5, 0,false), 16 ByteBuf(6, 2,true), 17 String(7, 2,true), 18 TimeStamp(8, 0,false), 19 UUID(9, 0,false); 20 21 private int intValue; 22 private boolean isVariableLength; 23 private int overhead; 24 HeaderType(int intValue, int overhead, boolean isVariableLength)25 HeaderType(int intValue, int overhead, boolean isVariableLength) { 26 this.intValue = intValue; 27 this.overhead = overhead; 28 this.isVariableLength = isVariableLength; 29 } 30 31 /** 32 * 33 * @return additional bytes needed to serialize the header's value, beyond the value's data itself 34 */ getWireBytesOverhead()35 public int getWireBytesOverhead() { 36 return overhead; 37 } 38 39 /** 40 * 41 * @return the native integer value associated with this Java enum value 42 */ getEnumIntValue()43 public int getEnumIntValue() { 44 return intValue; 45 } 46 47 /** 48 * 49 * @return true if encoding this type requires a variable number of bytes, false if a fixed number of bytes 50 */ isVariableLength()51 public boolean isVariableLength() { 52 return isVariableLength; 53 } 54 55 /** 56 * Creates a Java header type enum from an associated native integer value 57 * @param intValue native integer value 58 * @return a new Java header type value 59 */ getValueFromInt(int intValue)60 public static HeaderType getValueFromInt(int intValue) { 61 for (HeaderType type : HeaderType.values()) { 62 if (type.intValue == intValue) { 63 return type; 64 } 65 } 66 67 throw new CrtRuntimeException("Invalid event-stream header int value."); 68 } 69 } 70