1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.http3;
17
18 import io.netty.util.collection.LongObjectHashMap;
19 import io.netty.util.collection.LongObjectMap;
20 import io.netty.util.internal.StringUtil;
21
22 import java.util.Iterator;
23 import java.util.Map;
24
25 public final class DefaultHttp3SettingsFrame implements Http3SettingsFrame {
26
27 private final LongObjectMap<Long> settings = new LongObjectHashMap<>(4);
28
29 @Override
30 public Long get(long key) {
31 return settings.get(key);
32 }
33
34 @Override
35 public Long put(long key, Long value) {
36 if (Http3CodecUtils.isReservedHttp2Setting(key)) {
37 throw new IllegalArgumentException("Setting is reserved for HTTP/2: " + key);
38 }
39 return settings.put(key, value);
40 }
41
42 @Override
43 public Iterator<Map.Entry<Long, Long>> iterator() {
44 return settings.entrySet().iterator();
45 }
46
47 @Override
48 public int hashCode() {
49 return settings.hashCode();
50 }
51
52 @Override
53 public boolean equals(Object o) {
54 if (this == o) {
55 return true;
56 }
57 if (o == null || getClass() != o.getClass()) {
58 return false;
59 }
60 DefaultHttp3SettingsFrame that = (DefaultHttp3SettingsFrame) o;
61 return that.settings.equals(settings);
62 }
63
64 @Override
65 public String toString() {
66 return StringUtil.simpleClassName(this) + "(settings=" + settings + ')';
67 }
68
69
70
71
72
73
74
75 public static DefaultHttp3SettingsFrame copyOf(Http3SettingsFrame settingsFrame) {
76 DefaultHttp3SettingsFrame copy = new DefaultHttp3SettingsFrame();
77 if (settingsFrame instanceof DefaultHttp3SettingsFrame) {
78 copy.settings.putAll(((DefaultHttp3SettingsFrame) settingsFrame).settings);
79 } else {
80 for (Map.Entry<Long, Long> entry: settingsFrame) {
81 copy.put(entry.getKey(), entry.getValue());
82 }
83 }
84 return copy;
85 }
86 }