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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:36:51+00:00 2026-05-14T08:36:51+00:00

How can I read the data from read stream in Objective-C? The code below

  • 0
  1. How can I read the data from read stream in Objective-C? The code below would give me how many bytes are read from stream, but how can I know what data is read from stream?

    CFIndex cf = CFReadStreameRead(Stream, buffer, length);
    
  2. How can I extract only the 1st 2bytes of data in the read stream in Objective-C? For example, if this is the data from stream:

    017MacApp
    

    1st byte has 0 in it, and 2nd byte has 17 in it.

    How do I extract 0 and 17 into byte array?

I know that the below code would give me back the byte array to int value.

((b[0] & 0xFF) << 8)+ (b[1] & 0xFF);

but how to put 0 into b[0] and 17 into b[1]?

  • 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-14T08:36:51+00:00Added an answer on May 14, 2026 at 8:36 am
    uint8_t buffer[2];
    CFIndex cf = CFReadStreamRead(Stream, buffer, 2);
    if (cf == 2)
    {
        uint8_t firstByte = buffer[0];
        uint8_t secondByte = buffer[1];
    }
    else
    {
        // cf == -1 => error, cf == 0 => end of file, cf == 1 => you need to call again to get the second byte
    }
    

    Here is the Apple doc.

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

Sidebar

Related Questions

I would like to read some data from a stream I have using std::getline
Okay, so I want to have a generic method that can read data from
I am trying to build a website where I can read the data from
The program can read all the data from the pipe. However, the program just
I'm trying to read data from excel using POI. How can I check if
I need to read the data from a file that can be either comma
I have android.permission.READ_OWNER_DATA but I can't find any reliable code that would explain how
I want to read data records from a non-seekable stream in Ruby. I want
I discovered a nice abstraction whereby I can read in data from UDP using
I have some SerialPort code that constantly needs to read data from a serial

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.