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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:04:00+00:00 2026-05-14T20:04:00+00:00

I have the following CPython code which I now try to run in IronPython:

  • 0

I have the following CPython code which I now try to run in IronPython:

import ctypes

class BarHeader(ctypes.Structure):
    _fields_ = [
        ("id", ctypes.c_char * 4),
        ("version", ctypes.c_uint32)]

bar_file = open("data.bar", "rb")
header_raw = bar_file.read(ctypes.sizeof(BarHeader))
header = BarHeader.from_buffer_copy(header_raw)

The last line raises this exception: TypeError: expected array, got str

I tried BarHeader.from_buffer_copy(bytes(header_raw)) instead of the above, but then the exception message changes to TypeError: expected array, got bytes.

Any idea what I’m doing wrong?

  • 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-14T20:04:00+00:00Added an answer on May 14, 2026 at 8:04 pm

    I tried the following code in Python 2.7 and it worked perfectly.

    import ctypes  
    
    class BarHeader(ctypes.Structure):
       _fields_ = [("version", ctypes.c_uint)]
    
    
    header = BarHeader.from_buffer_copy("\x01\x00\x00\x00")
    print header.version #prints 1 on little endian
    

    And a solution using the array class

    import ctypes
    import array
    
    class BarHeader(ctypes.Structure):
       _fields_ = [
          ("id", ctypes.c_char * 4),
          ("version", ctypes.c_uint32)]
    
    bar_file = open("data.bar", "rb")
    
    bytearray = array.array('b')
    bytearray.fromfile(bar_file, ctypes.sizeof(BarHeader))
    
    header = BarHeader.from_buffer_copy(bytearray)
    
    print header.id
    print header.version
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code import sys from ctypes import * from ctypes.util import find_library
I have following setup. from django.db import models from django.contrib.auth.models import User class Event(models.Model):
I have following structure of an HTML document: <body> <div class=main> <div class=left></div> <div
I have following code: public class reader extends Activity { WebView mWebView; String mFilename;
I have following Code Block Which I tried to optimize in the Optimized section
I have following code in html: <div> <div style=float:left;margin:0.5em> <span class=title>Label1</span><br/> <input type=text name=name1
I have the following piece of code which I'd like to optimize using Cython:
I have following HTML code in my JSP page: <label class=txt12Red>Label 1</label> <label class=txt12Red>Label
I have following code in which i am doing JSON parsing and showing results
I have following code in initialization im = imread('Image02.tif'); figure(); imagesc(im); colormap(gray); [hImage hfig

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.