Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8527167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:28:46+00:00 2026-06-11T08:28:46+00:00

I have a .bin file created using C# with a protobuf library and the

  • 0

I have a .bin file created using C# with a protobuf library and the following class:

[ProtoContract]
class TextureAtlasEntry
{
    [ProtoMember(1)]
    public int Height { get; set; }

    [ProtoMember(2)]
    public string Name { get; set; }

    [ProtoMember(3)]
    public int Width { get; set; }

    [ProtoMember(4)]
    public int X { get; set; }

    [ProtoMember(5)]
    public int Y { get; set; }
}

The associated .proto file looks like

package TextureAtlasSettings;           // Namespace equivalent

message TextureAtlasEntry               
{
    required int32 Height = 1;
    required string Name = 2;
    required int32 Width = 3;
    required int32 X = 4;
    required int32 Y = 5;
}

Which has been parsed through protoc.exe to produce TextureAtlasSettings.pb.cc and TextureAtlasSettings.pb.h. for C++.

I would like to read the resultant binary file in C++, so I tried the following code

TextureAtlasSettings::TextureAtlasEntry taSettings;

ifstream::pos_type size;
char *memblock;

ifstream file("Content\\Protobuf\\TextureAtlas0.bin", ios::in | ios::binary);

if (file.is_open())
{
    size = file.tellg();
    memblock = new char[size];
    file.seekg(0, ios::beg);
    file.read(memblock, size);
    file.close();

    fstream input(&memblock[0], ios::in | ios::binary);

    if (!taSettings.ParseFromIstream(&file)) 
    {
        printf("Failed to parse TextureAtlasEntry");
    }

    delete[] memblock;
}

The code above will always trigger the printf. How do I go about reading the file correctly so it may be deserialized?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:28:48+00:00Added an answer on June 11, 2026 at 8:28 am

    It should be sufficient to do this:

    TextureAtlasSettings::TextureAtlasEntry taSettings;
    
    ifstream file("Content\\Protobuf\\TextureAtlas0.bin", ios::in | ios::binary);
    
    if (file.is_open())
    {
        if (!taSettings.ParseFromIstream(&file)) 
        {
            printf("Failed to parse TextureAtlasEntry");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a shell script file (run.sh) that contains the following: #!/bin/bash %JAVA_HOME%/bin/java -jar
I have the following code #!/usr/bin/perl use Tie::File; tie my @last_id, 'Tie::File', 'last_id.txt' or
I have serialized a collection to a file using protobuf-net. I am looking for
I have serialized a list of objects with protobuf-net. Theoretically, the .bin file can
I have a program that creates a small file in the Bin directory for
I have merged multiple jpeg files into one single .bin file. ..... ......... while(true){
I am processing some CSV file which i have copied in Bin folder of
I have a file structure that looks like this ./501.res/1.bin ./503.res/1.bin ./503.res/2.bin ./504.res/1.bin and
I have a jar file named umar.jar in /root/umar/bin directory. I have a shell
I have an exe file simpleservice.exe in the physical path F:\SAMPLEPRODUCT\Bin ,, i need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.