Refactor so that varint_paramlen returns parameter length
@@ -78,8 +78,12 @@ void ngtcp2_crypto_create_nonce(uint8_t *dest, const uint8_t *iv, size_t ivlen,
}
}
-static void inc_len_varint(size_t *len, uint64_t param) {
- *len += 4 + ngtcp2_put_varint_len(param);
+/*
+ * varint_paramlen returns the length of a single transport parameter
+ * which has variable integer in its parameter.
+ */
+static size_t varint_paramlen(uint64_t param) {
+ return 4 + ngtcp2_put_varint_len(param);
}
ssize_t ngtcp2_encode_transport_params(uint8_t *dest, size_t destlen,
@@ -117,40 +121,40 @@ ssize_t ngtcp2_encode_transport_params(uint8_t *dest, size_t destlen,
}
if (params->initial_max_stream_data_bidi_local) {
- inc_len_varint(&len, params->initial_max_stream_data_bidi_local);
+ len += varint_paramlen(params->initial_max_stream_data_bidi_local);
}
if (params->initial_max_stream_data_bidi_remote) {
- inc_len_varint(&len, params->initial_max_stream_data_bidi_remote);
+ len += varint_paramlen(params->initial_max_stream_data_bidi_remote);
}
if (params->initial_max_stream_data_uni) {
- inc_len_varint(&len, params->initial_max_stream_data_uni);
+ len += varint_paramlen(params->initial_max_stream_data_uni);
}
if (params->initial_max_data) {
- inc_len_varint(&len, params->initial_max_data);
+ len += varint_paramlen(params->initial_max_data);
}
if (params->initial_max_streams_bidi) {
- inc_len_varint(&len, params->initial_max_streams_bidi);
+ len += varint_paramlen(params->initial_max_streams_bidi);
}
if (params->initial_max_streams_uni) {
- inc_len_varint(&len, params->initial_max_streams_uni);
+ len += varint_paramlen(params->initial_max_streams_uni);
}
if (params->max_packet_size != NGTCP2_MAX_PKT_SIZE) {
- inc_len_varint(&len, params->max_packet_size);
+ len += varint_paramlen(params->max_packet_size);
}
if (params->ack_delay_exponent != NGTCP2_DEFAULT_ACK_DELAY_EXPONENT) {
- inc_len_varint(&len, params->ack_delay_exponent);
+ len += varint_paramlen(params->ack_delay_exponent);
}
if (params->disable_active_migration) {
len += 4;
}
if (params->max_ack_delay != NGTCP2_DEFAULT_MAX_ACK_DELAY) {
- inc_len_varint(&len, params->max_ack_delay / NGTCP2_MILLISECONDS);
+ len += varint_paramlen(params->max_ack_delay / NGTCP2_MILLISECONDS);
}
if (params->idle_timeout) {
- inc_len_varint(&len, params->idle_timeout / NGTCP2_MILLISECONDS);
+ len += varint_paramlen(params->idle_timeout / NGTCP2_MILLISECONDS);
}
if (params->active_connection_id_limit) {
- inc_len_varint(&len, params->active_connection_id_limit);
+ len += varint_paramlen(params->active_connection_id_limit);
}
if (destlen < len) {
