1 /** 2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 * SPDX-License-Identifier: Apache-2.0. 4 */ 5 6 package software.amazon.awssdk.crt.http; 7 8 import java.util.List; 9 10 public class Http2ConnectionSetting { 11 /** 12 * Predefined settings identifiers (RFC-7540 6.5.2). 13 */ 14 public enum ID { 15 HEADER_TABLE_SIZE(1), ENABLE_PUSH(2), MAX_CONCURRENT_STREAMS(3), INITIAL_WINDOW_SIZE(4), MAX_FRAME_SIZE(5), 16 MAX_HEADER_LIST_SIZE(6); 17 18 private int settingID; 19 ID(int value)20 ID(int value) { 21 settingID = value; 22 } 23 getValue()24 public int getValue() { 25 return settingID; 26 } 27 } 28 29 private ID id; 30 private long value; 31 getValue()32 public long getValue() { 33 return value; 34 } 35 getId()36 public ID getId() { 37 return id; 38 } 39 40 /** 41 * HTTP/2 connection setting. 42 * 43 * @param id Predefined settings identifiers (RFC-7540 6.5.2). 44 * @param value The value of the setting, limited from 0 to UINT32_MAX (RFC-7540 45 * 6.5.1) 46 */ Http2ConnectionSetting(ID id, long value)47 public Http2ConnectionSetting(ID id, long value) { 48 if (value > 4294967296L || value < 0) { 49 throw new IllegalArgumentException(); 50 } 51 this.id = id; 52 this.value = value; 53 } 54 55 /** 56 * @hidden Marshals a list of settings into an array for Jni to deal with. 57 * 58 * @param settings list of headers to write to the headers block 59 * @return a long[] that with the [id, value, id, value, *] 60 */ marshallSettingsForJNI(final List<Http2ConnectionSetting> settings)61 public static long[] marshallSettingsForJNI(final List<Http2ConnectionSetting> settings) { 62 /* Each setting is two long */ 63 int totalLength = settings.size(); 64 65 long marshalledSettings[] = new long[totalLength * 2]; 66 67 for (int i = 0; i < totalLength; i++) { 68 marshalledSettings[i * 2] = settings.get(i).id.getValue(); 69 marshalledSettings[i * 2 + 1] = settings.get(i).value; 70 } 71 72 return marshalledSettings; 73 } 74 75 /** 76 * Helper to build a List of Http2ConnectionSetting 77 * 78 * @return {@link Http2ConnectionSettingListBuilder} 79 */ builder()80 public static Http2ConnectionSettingListBuilder builder() { 81 return new Http2ConnectionSettingListBuilder(); 82 } 83 } 84