1 /** @file
2  *
3  *  A brief file description
4  *
5  *  @section license License
6  *
7  *  Licensed to the Apache Software Foundation (ASF) under one
8  *  or more contributor license agreements.  See the NOTICE file
9  *  distributed with this work for additional information
10  *  regarding copyright ownership.  The ASF licenses this file
11  *  to you under the Apache License, Version 2.0 (the
12  *  "License"); you may not use this file except in compliance
13  *  with the License.  You may obtain a copy of the License at
14  *
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  *
17  *  Unless required by applicable law or agreed to in writing, software
18  *  distributed under the License is distributed on an "AS IS" BASIS,
19  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  *  See the License for the specific language governing permissions and
21  *  limitations under the License.
22  */
23 
24 #pragma once
25 
26 #include "QUICTypes.h"
27 #include "QUICEvents.h"
28 #include "QUICTransportParameters.h"
29 #include "QUICStreamState.h"
30 
31 class QUICDebugNames
32 {
33 public:
34   static const char *packet_type(QUICPacketType type);
35   static const char *frame_type(QUICFrameType type);
36   static const char *error_class(QUICErrorClass cls);
37   static const char *error_code(uint16_t code);
38   static const char *transport_parameter_id(QUICTransportParameterId id);
39   static const char *stream_state(const QUICSendStreamState state);
40   static const char *stream_state(const QUICReceiveStreamState state);
41   static const char *stream_state(const QUICBidirectionalStreamState state);
42   static const char *quic_event(int event);
43   static const char *key_phase(QUICKeyPhase phase);
44   static const char *encryption_level(QUICEncryptionLevel level);
45   static const char *pn_space(QUICPacketNumberSpace pn_space);
46 };
47 
48 class QUICDebug
49 {
50 public:
51   static void
to_hex(uint8_t * out,const uint8_t * in,int in_len)52   to_hex(uint8_t *out, const uint8_t *in, int in_len)
53   {
54     for (int i = 0; i < in_len; ++i) {
55       int u4         = in[i] / 16;
56       int l4         = in[i] % 16;
57       out[i * 2]     = (u4 < 10) ? ('0' + u4) : ('a' + u4 - 10);
58       out[i * 2 + 1] = (l4 < 10) ? ('0' + l4) : ('a' + l4 - 10);
59     }
60     out[in_len * 2] = 0;
61   }
62 };
63