# How to correct serialize Protobuf?

**URL:** <https://forums.unrealengine.com/t/how-to-correct-serialize-protobuf/488970>\
**Category:** C++\
**Tags:** fstring, serialization, unreal-engine, UE5-0, question, CPP\
**Created:** [September 19, 2021, 9:58am UTC](https://forums.unrealengine.com/t/how-to-correct-serialize-protobuf/488970 "2021-09-19T09:58:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vasyl\_Khvostyk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Vasyl\_Khvostyk](https://forums.unrealengine.com/u/Vasyl_Khvostyk)\
**Post date:** [September 19, 2021, 9:58am UTC](https://forums.unrealengine.com/t/how-to-correct-serialize-protobuf/488970/1 "2021-09-19T09:58:52Z")

</div>

Environment:

- **Unreal Engine 5**
- **Windows 10**
- **Protocol Buffers v3.18.0**

I’m trying to decode serialized data in Unreal Engine 5 (c++) by using `protoc`. If the message contains the value of int var less than 127 everything is okay. But if the value is more than 127 I catch the error: **Failed to parse input.**

**player.proto:**

```
syntax = "proto3";
package com.game;

message Player {
    string username = 1;
    int64 experience = 2;
}

```

## Success case

**C++ serialization and save to file:**

```
com::game::Player MyPlayer;
MyPlayer.set_username("test user name");
MyPlayer.set_experience(127); // <-- PAY ATTENTION

// serialization
std::string MyPlayerString;
if(!MyPlayer.SerializeToString(&MyPlayerString))
{
    UE_LOG(LogGameInstance, Error, TEXT("Can't serialize MyPlayer to String"));
    return;
}
const FString MyPlayerFString(MyPlayerString.c_str());

// save to file
const FString File = *FPaths::Combine(FPaths::GameSourceDir(), FApp::GetProjectName(), TEXT("temp.dat"));
FFileHelper::SaveStringToFile(
    MyPlayerFString,
    *File,
    FFileHelper::EEncodingOptions::AutoDetect,
    &IFileManager::Get()
);

```

**protoc --decode\_raw \< temp.dat**

```
1: "test user name"
2: 127

```

## Fail case

**C++ serialization and save to file:**

```
...
MyPlayer.set_experience(128); // <-- PAY ATTENTION
...

```

**protoc --decode\_raw \< temp.dat**

```
Failed to parse input.

```

I guess the problem occurs when I try to convert std::string → FString. Any ideas?

P.S: I tried to use macro: **UTF8\_TO\_TCHAR** and **ANSI\_TO\_TCHAR** but no result.

---

<div class="post-metadata">

**Author:** ![Origin\_plan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Origin\_plan](https://forums.unrealengine.com/u/Origin_plan)\
**Post date:** [April 26, 2022, 2:18am UTC](https://forums.unrealengine.com/t/how-to-correct-serialize-protobuf/488970/2 "2022-04-26T02:18:26Z")

</div>

I need a help,How does ue5 integrate protobuf?Thanks.
