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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:12:37+00:00 2026-05-24T20:12:37+00:00

I want to encode a message…This is the message that i have generated from

  • 0

I want to encode a message…This is the message that i have generated

from ctypes import memmove, addressof, Structure, c_uint16,c_bool

class AC(Structure):
    _fields_ = [("UARFCN",  c_uint16),
                 ("ValidUARFCN", c_bool ),("PassiveActivationTime", c_uint16) ]

    def __init__(self , UARFCN ,ValidUARFCN , PassiveActivationTime):
            self.UARFCN                 =    UARFCN
            self.ValidUARFCN            =    True
            self.PassiveActivationTime  =    PassiveActivationTime

    def __str__(self):
        s = "AC"
        s += "UARFCN:"  + str(self.UARFCN)
        s += "ValidUARFCN"  + str(self.ValidUARFCN)
        s += "PassiveActivationTime"  +str(self.PassiveActivationTime)
        return s

class ABCD(AC):
        a1 = AC( 0xADFC , True , 2)
        a2 = AC( 13 , False ,5)
        print a1
        print a2

I want to encode it and then store it in a variable…..So how can i do it???

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

    For C structures, all you have to do to write it to a file is open the file, then do

    fileobj.write(my_c_structure).
    

    Then you can reload it by opening the file and doing

    my_c_structure = MyCStructure()
    fileobj.readinto(my_c_structure)
    

    All you need is to make your __init__ arguments optional. See this post on Binary IO. It explains how to send Structure over sockets or with multiprocessing Listeners.

    To save it in a string / bytes just do

    from io import BytesIO # Or StringIO on old Pythons, they are the same
    fakefile = BytesIO()
    fakefile.write(my_c_structure)
    my_encoded_c_struct = fakefile.getvalue()
    

    Then read it back out with

    from io import BytesIO # Or StringIO on old Pythons, they are the same
    fakefile = BytesIO(my_encoded_c_struct)
    my_c_structure = MyCStructure()
    fakefile.readinto(my_c_structure)
    

    Pickle and the like are not necessary. Neither is struct.pack though it would work. It’s just more complicated.

    Edit: also see the linked answer at How to pack and unpack using ctypes (Structure <-> str) for another method for doing this.

    Edit 2: See http://doughellmann.com/PyMOTW/struct or http://effbot.org/librarybook/struct.htm for struct examples.

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

Sidebar

Related Questions

So I have this function that takes all the users from an MySql table
I have this json encode in the database, and i want just echo values
I want to send email messages that have arbitrary unicode bodies in a Python
I want insert in the row from database, array of values as that each
I want insert following checkbox in a row from database table, but have error,
I use OpenSSL to encryt a string. After that I want to encode the
I want to encode DNS protocol header using C and create a UDP datagram.
I want to encode and decode Bitmap object in string base64 . I use
I want to encode binary file into base64 and put it into php page
As the title mentioned, I want to encode a Image Obj into some kind

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.