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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:00:50+00:00 2026-06-04T23:00:50+00:00

I am using Visual Studio 2005 with .Net20 version of protobuf-net r480. I try

  • 0

I am using Visual Studio 2005 with .Net20 version of protobuf-net r480.

I try to follow an example and serialize a class with string, enum, int, and byte[] data as below

[ProtoContract]
public class Proto_DemoMessage {
    public enum ESSCommandType : int {
        ClientServer = 0,
        Broadcast = 10,
        Assign = 11,
    }

    [ProtoMember(1, IsRequired = false)]
    public string Name;
    [ProtoMember(3, IsRequired = true)]
    public ESSCommandType CommandType;
    [ProtoMember(4, IsRequired = false)]
    public int Code;
    [ProtoMember(5, IsRequired = false)]
    public byte[] BytesData;

    public byte[] Serialize(){
        byte[] b = null;
        using (MemoryStream ms = new MemoryStream()) {
            Serializer.Serialize<Proto_DemoMessage>(ms, this);
            b = new byte[ms.Position];
            byte[] fullB = ms.GetBuffer();
            Array.Copy(fullB, b, b.Length);
        }
        return b;
    }

And give value to each field as below

Proto_DemoMessage inner_message = new Proto_DemoMessage();
inner_message.Name = "innerName";
inner_message.CommandType = Proto_DemoMessage.ESSCommandType.Broadcast;
inner_message.Code = 11;
inner_message.BytesData = System.Text.Encoding.Unicode.GetBytes("1234567890");

After calling inner_message.Serialize(), I write the result byte[] to a file. When I open the file in HEX mode to verify it, I found each byte in byte[] has a 00 padding behind it.
The result is:

2A 14 31 00 32 00 33 00 34 00 35 00 36 00 37 00 38 00 39 00 30 00

Is there something I did wrong? I appreciate for your help.

  • 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-04T23:00:52+00:00Added an answer on June 4, 2026 at 11:00 pm

    Everything’s OK. Your string is encoded in UTF-16. In this encoding all characters are (at least) two bytes wide.

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

Sidebar

Related Questions

Using Visual Studio 2005 I have list of class files, when i try to
I am using Visual Studio 2005, (.NET version > 2.0+) to create a windows
(Using Visual Studio 2005 / .NET 2.0) I have a DataSet which is being
I'm using Visual Studio 2005 with VB.NET. I have a number of Crystal Reports,
I am using Visual Studio 2005 (C\C++). I am passing a string into a
I am using Visual Studio 2005, Sql Server 2005, C#, ADO.NET. We have a
I'm using Visual Studio 2005 w/.NET 2.0. I have no idea what happened, but
I'm using Visual Studio 2005 and writing in VB.NET. I have a subreport in
First, a couple operating parameters: .NET development using Visual Studio 2005/2008 TortoiseSVN client I've
I am using Visual Studio 2005, .NET Framework 2.0. Now I started using Visual

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.