<commit_before>/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2015. All Rights Reserved.                             */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project.                                                               */
/*----------------------------------------------------------------------------*/

#include "Message.h"

#include "WireDecoder.h"
#include "WireEncoder.h"

#define kClearAllMagic 0xD06CB27Aul

using namespace nt;

std::shared_ptr<Message> Message::Read(WireDecoder& decoder,
                                       GetEntryTypeFunc get_entry_type) {
  unsigned int msg_type;
  if (!decoder.Read8(&msg_type)) return nullptr;
  auto msg =
      std::make_shared<Message>(static_cast<MsgType>(msg_type), private_init());
  switch (msg_type) {
    case kKeepAlive:
      break;
    case kClientHello: {
      unsigned int proto_rev;
      if (!decoder.Read16(&proto_rev)) return nullptr;
      msg->m_id = proto_rev;
      // This intentionally uses the provided proto_rev instead of
      // decoder.proto_rev().
      if (proto_rev >= 0x0300u) {
        if (!decoder.ReadString(&msg->m_str)) return nullptr;
      }
      break;
    }
    case kProtoUnsup: {
      if (!decoder.Read16(&msg->m_id)) return nullptr;  // proto rev
      break;
    }
    case kServerHelloDone:
      if (decoder.proto_rev() < 0x0300u) {
        decoder.set_error("received SERVER_HELLO_DONE in protocol < 3.0");
        return nullptr;
      }
      break;
    case kClientHelloDone:
      if (decoder.proto_rev() < 0x0300u) {
        decoder.set_error("received CLIENT_HELLO_DONE in protocol < 3.0");
        return nullptr;
      }
      break;
    case kEntryAssign: {
      if (!decoder.ReadString(&msg->m_str)) return nullptr;
      NT_Type type;
      if (!decoder.ReadType(&type)) return nullptr;  // name
      if (!decoder.Read16(&msg->m_id)) return nullptr;  // id
      if (!decoder.Read16(&msg->m_seq_num_uid)) return nullptr;  // seq num
      if (decoder.proto_rev() >= 0x0300u) {
        if (!decoder.Read8(&msg->m_flags)) return nullptr;  // flags
      }
      msg->m_value = decoder.ReadValue(type);
      if (!msg->m_value) return nullptr;
      break;
    }
    case kEntryUpdate: {
      if (!decoder.Read16(&msg->m_id)) return nullptr;  // id
      if (!decoder.Read16(&msg->m_seq_num_uid)) return nullptr;  // seq num
      NT_Type type;
      if (decoder.proto_rev() >= 0x0300u) {
        unsigned int itype;<commit_msg>Message: Handle receiving Server Hello.<commit_after>/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2015. All Rights Reserved.                             */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project.                                                               */
/*----------------------------------------------------------------------------*/

#include "Message.h"

#include "WireDecoder.h"
#include "WireEncoder.h"

#define kClearAllMagic 0xD06CB27Aul

using namespace nt;

std::shared_ptr<Message> Message::Read(WireDecoder& decoder,
                                       GetEntryTypeFunc get_entry_type) {
  unsigned int msg_type;
  if (!decoder.Read8(&msg_type)) return nullptr;
  auto msg =
      std::make_shared<Message>(static_cast<MsgType>(msg_type), private_init());
  switch (msg_type) {
    case kKeepAlive:
      break;
    case kClientHello: {
      unsigned int proto_rev;
      if (!decoder.Read16(&proto_rev)) return nullptr;
      msg->m_id = proto_rev;
      // This intentionally uses the provided proto_rev instead of
      // decoder.proto_rev().
      if (proto_rev >= 0x0300u) {
        if (!decoder.ReadString(&msg->m_str)) return nullptr;
      }
      break;
    }
    case kProtoUnsup: {
      if (!decoder.Read16(&msg->m_id)) return nullptr;  // proto rev
      break;
    }
    case kServerHelloDone:
      if (decoder.proto_rev() < 0x0300u) {
        decoder.set_error("received SERVER_HELLO_DONE in protocol < 3.0");
        return nullptr;
      }
      break;
    case kServerHello:
      if (decoder.proto_rev() < 0x0300u) {
        decoder.set_error("received SERVER_HELLO_DONE in protocol < 3.0");
        return nullptr;
      }
      if (!decoder.Read8(&msg->m_flags)) return nullptr;
      if (!decoder.ReadString(&msg->m_str)) return nullptr;
      break;
    case kClientHelloDone:
      if (decoder.proto_rev() < 0x0300u) {
        decoder.set_error("received CLIENT_HELLO_DONE in protocol < 3.0");
        return nullptr;
      }
      break;
    case kEntryAssign: {
      if (!decoder.ReadString(&msg->m_str)) return nullptr;
      NT_Type type;
      if (!decoder.ReadType(&type)) return nullptr;  // name
      if (!decoder.Read16(&msg->m_id)) return nullptr;  // id
      if (!decoder.Read16(&msg->m_seq_num_uid)) return nullptr;  // seq num
      if (decoder.proto_rev() >= 0x0300u) {
        if (!decoder.Read8(&msg->m_flags)) return nullptr;  // flags
      }
      msg->m_value = decoder.ReadValue(type);
      if (!msg->m_value) return nullptr;
      break;
    }
    case kEntryUpdate: {
      if (!decoder.Read16(&msg->m_id)) return nullptr;  // id
      if (!decoder.Read16(&msg->m_seq_num_uid)) return nullptr;  // seq num
      NT_Type type;
      if (decoder.proto_rev() >= 0x0300u) {
        unsigned int itype;
{'fraction_non_alphanumeric': 0.1691923694063113, 'fraction_numerical': 0.019967908718131575, 'mean_word_length': 1.9682539682539681, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1949091', 'n_tokens_mistral': 1771, 'n_tokens_neox': 1632, 'n_words': 410}