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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:33:33+00:00 2026-06-12T11:33:33+00:00

Basically I have void FileReader::parseBuffer(char * buffer, int length) { //start by looking for

  • 0

Basically I have

void FileReader::parseBuffer(char * buffer, int length)
{
  //start by looking for a vrsn
  //Header seek around for a vrns followed by 32 bit size descriptor
  //read 32 bits at a time
  int cursor = 0;
  char vrsn[5] = "vrsn";
  cursor = this->searchForMarker(cursor, length, vrsn, buffer);
  int32_t size = this->getObjectSizeForMarker(cursor, length, buffer);
  cursor = cursor + 8; //advance cursor past marker and size
  wchar_t *version = this->getObjectForSizeAndCursor(size, cursor, buffer);
  cout << version << "\n";
  delete[] version;
}

wchar_t* FileReader::getObjectForSizeAndCursor(int32_t size, int cursor, char *buffer) {
  wchar_t *destination = NULL;
  destination = new wchar_t[(size/2)+1];
  memcpy(destination, buffer + cursor, size);
  return destination;
}

in my example say i have the following bytes

7672736E – marker vrsn

00000040 – size of string to follow

0032002E0030002F00530065007200610074006F002000530063007200610074006300680020004C004900560045002000440061007400610062006100730065 – string

the string uses 16 bytes per character, so i cannot use a char * for the actual string, wchar_t seems like the best bet.

However when i memcpy these bytes to a wchar_t i get 0x7fe7abc037e0 in cout which i assume is a pointer?

which seems wrong. when i use wcout i get nothing in the terminal.

Will memcpy not work for this?

also should my wchar_t size be halved since i only have half as many wchar_t’s as i would have chars?

size is a byte count.

  • 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-12T11:33:35+00:00Added an answer on June 12, 2026 at 11:33 am

    Your string looks like it’s in big endian order, but you are (probably) using a little-endian machine. Therefore, your wchar_t string is full of characters like U+3200 which your terminal might not correctly print out.

    You will have to properly flip every one of those characters. Your best bet is to just treat the input as a unsigned char * and copy the elements one-at-a-time into your wchar_t * with the correct endian reversal:

    int wlen = size/2;
    uint16_t *dest = new uint16_t[wlen + 1];
    unsigned char *ptr = (unsigned char *)(buffer + cursor);
    for(int i=0; i<wlen; i++) {
        dest[i] = (ptr[0] << 8) + ptr[1];
        ptr += 2;
    }
    dest[wlen] = 0;
    return dest;
    

    Note that you can’t assume wchar_t is 16 bits wide. If you can use C++11 features, use char16_t.

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

Sidebar

Related Questions

Basically I have a buffer in which i am looking for various flags to
I basically have something like this: class CGlToolBase { public: CGlToolBase(void) { } virtual
i have some sample code i have been playing around with. Basically im just
I basically have something like this: void Foo(Type ty) { var result = serializer.Deserialize<ty>(inputContent);
Basically I have this scenario going on: //in interface header @property(nonatomic,retain)OtherClass *otherClass; //implementation -
I basically have a program that filters records from one excel file to another
I basically have three tables, posts, images and postimages (this simply contains the ids
I basically have a unix process running and it is doing some heavy processing
I basically have a server set up and I'm accepting new clients(UNIX) and i'm
I basically have the following string in the format: A,B,C:D,E,F What I am trying

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.