<commit_before>/* Copyright 2013-present Barefoot Networks, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef PI_INC_PI_PI_VALUE_H_
#define PI_INC_PI_PI_VALUE_H_

typedef enum {
  PI_VALUE_TYPE_U8,
  PI_VALUE_TYPE_U16,
  PI_VALUE_TYPE_U32,
  PI_VALUE_TYPE_U64,
  PI_VALUE_TYPE_UPTR,
} pi_value_type_t;

/* 64 bit option can be disabled for 32-bit architecture */
/* implementation can be hidden from user */
/* integers in this struct are stored in network-byte order */
typedef struct {
  uint32_t type_and_size;  // first byte is type, rest is size
  union {
    uint8_t u8;
    uint16_t u16;
    uint32_t u32;
    uint64_t u64;
    char *ptr;
  } value;
} pi_value_t;

void pi_build_value_u8(const uint8_t u8, pi_value_t *value);
void pi_build_value_u16(const uint16_t u16, pi_value_t *value);
void pi_build_value_u32(const uint32_t u32, pi_value_t *value);
void pi_build_value_u64(const uint64_t u64, pi_value_t *value);

// we borrow the pointer, client is still responsible for deleting memory when
// he is done with the value
void pi_build_value_ptr(const char *ptr, uint32_t size, pi_value_t *value);

#endif  // PI_INC_PI_PI_VALUE_H_<commit_msg>defined the pi_getv_* functions<commit_after>/* Copyright 2013-present Barefoot Networks, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef PI_INC_PI_PI_VALUE_H_
#define PI_INC_PI_PI_VALUE_H_

#include <assert.h>

typedef enum {
  PI_VALUE_TYPE_U8 = 0,
  PI_VALUE_TYPE_U16,
  PI_VALUE_TYPE_U32,
  PI_VALUE_TYPE_U64,
  PI_VALUE_TYPE_PTR,
} pi_value_type_t;

/* 64 bit option can be disabled for 32-bit architecture */
/* implementation can be hidden from user */
typedef struct {
  uint32_t type_and_size;  // first byte is type, rest is size
  union {
    uint8_t u8;
    uint16_t u16;
    uint32_t u32;
    uint64_t u64;
    const char *ptr;
  } value;
} pi_value_t;

inline void pi_getv_u8(const uint8_t u8, pi_value_t *v) {
  v->type_and_size = ((uint8_t) PI_VALUE_TYPE_U8) << 24;
  v->value.u8 = u8;
}

inline void pi_getv_u16(const uint16_t u16, pi_value_t *v) {
  v->type_and_size = ((uint8_t) PI_VALUE_TYPE_U16) << 24;
  v->value.u16 = u16;
}

inline void pi_getv_u32(const uint32_t u32, pi_value_t *v) {
  v->type_and_size = ((uint8_t) PI_VALUE_TYPE_U32) << 24;
  v->value.u32 = u32;
}

inline void pi_getv_u64(const uint64_t u64, pi_value_t *v) {
  v->type_and_size = ((uint8_t) PI_VALUE_TYPE_U64) << 24;
  v->value.u64 = u64;
}

// we borrow the pointer, client is still responsible for deleting memory when
// he is done with the value
inline void pi_getv_ptr(const char *ptr, uint32_t size, pi_value_t *v) {
  assert(size < (1 << 24));
  v->type_and_size = ((uint8_t) PI_VALUE_TYPE_PTR) << 24;
  v->type_and_size |= size;
  v->value.ptr = ptr;
}

#endif  // PI_INC_PI_PI_VALUE_H_
{'fraction_non_alphanumeric': 0.08856088560885608, 'fraction_numerical': 0.04111755403268318, 'mean_word_length': 4.142276422764228, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '760371', 'n_tokens_mistral': 1456, 'n_tokens_neox': 1356, 'n_words': 429}