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 7438419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:33:08+00:00 2026-05-29T10:33:08+00:00

I have some questions regarding packed fields, and storing/serializing data with protocolbuffers. What i

  • 0

I have some questions regarding packed fields, and storing/serializing
data with protocolbuffers.
What i want to do essentially, is to store 4MB of data to a file.

The data i have (in our embedded system) is received as uint8_t (a byte) and i want to store this data as efficiently as possible.

I have been testing a variety of protobuf setups (four);

repeated uint32_t datastruct = 1;
repeated uint32_t datastruct = 1 [packed = true]

with both variants assigned 1-to-1 (putting a uint8 to uint32) and both variants bitshifted with 4 values cramped into a uint32_t.

To my surprise the stored files are much larger than the original
data. (the examples where i put a uint8 into uint32 was expected of course..)
The best result i could achieve was 5.2MB for the 4MB data, which
really isnt that good.

Have i misunderstood something vital here?
I do realize that protobuf adds information to the packets, but 25%
increase is too much imho.

Also using GzipOutputStream increases the size of the file instead of decreasing it.

Any tips would be very appreciated!

Thanks for your time.

  • 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-05-29T10:33:09+00:00Added an answer on May 29, 2026 at 10:33 am

    This answer is based on the assumption that you are using uint32 in .proto terms:

    packed is a positive thing here (removes headers per value); however, by packing a single uint8 into a uint32, you are running into a facet of “varint” encoding – specifically, that if the most significant bit of the byte is set, it will take 2 bytes (varint uses 7 bits per byte for data, and one bit as continuation). Consequently, I would recommend switching to the bytes type, which represents any arbitrary chunk of bytes, and is encoded “as is”, without any varint or similar. It wouldn’t be repeated/packed – just:

    [required|optional] bytes data = 1;
    

    Another option would be to use fixed32 (repeated and packed), and place (via shifting) 4 bytes per value, but by the time you’ve done that you may as well go to bytes and have a more obvious 1:1 map.

    Re gzip; it is not uncommon for gzip to increase the size of arbitrary binary without many repeated blocks. By contrast, if your protobuf document contains strings it is common for the size to shrink, as gzip can spot repeated blocks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some questions regarding data base design for simple CMS. Every Page in
I have some questions regarding my MVC learning curve Goal: I want to get
I have some questions regarding dex files What is a dex file in Android?
There have been some similar questions asked regarding Grid views, but none have been
I have couple questions regarding some C++ rules. Why am I able to call
I have a question regarding the some data which is being transfered from one
I'm new to funcctional programming and have some questions regarding coding style and debugging.
I am new to the concept of Pipeline Functions. I have some questions regarding
I have some questions regarding calendars Is there any good calendar generates for either
I am writing a small application in c++ and I have some questions regarding

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.