New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cstruct

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cstruct

  • 1.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

##Synopsis CStruct is a simulation of the C language's struct.Its main purpose is to manipulate binary-data conveniently in Ruby. It can be used in:

  • Binary file IO like C.
  • The parameter of the OS's API.(e.g. Win32)
  • Other...

Lean more: http://cstruct.rubyforge.org/

##Getting Started ###Install CStruct Install CStruct is easy.

gem install cstruct

###Using CStruct Let's see an example,struct Point in C language(32-bit platform) like this:

struct Point
{
  int x;
  int y;
};

How to represent struct Point in Ruby? You can use CStruct to do it.

class Point < CStruct
  int32:x
  int32:y
end

Example:

require 'cstruct'

# struct Point in Ruby:
class Point < CStruct
 int32:x
 int32:y
end

# create a Point's instance
point = Point.new

# assign like as C language
point.x = 10
point.y = 20
puts "point.x = #{point.x},point.y = #{point.y}"

###Using Win32Struct like this:

typedef struct _OSVERSIONINFOEXA {
   DWORD dwOSVersionInfoSize;
   DWORD dwMajorVersion;
   DWORD dwMinorVersion;
   DWORD dwBuildNumber;
   DWORD dwPlatformId;
   CHAR szCSDVersion[ 128 ];
   WORD wServicePackMajor;
   WORD wReserved[2];
} OSVERSIONINFOEXA;

in Ruby:

class OSVERSIONINFOEXA < Win32Struct
   DWORD :dwOSVersionInfoSize
   DWORD :dwMajorVersion
   DWORD :dwMinorVersion
   DWORD :dwBuildNumber
   DWORD :dwPlatformId
   CHAR :szCSDVersion,[ 128 ]
   WORD :wServicePackMajor
   WORD :wServicePackMinor
   WORD :wReserved,[2]
end

##Lean More Please see also Documents and Examples.

FAQs

Package last updated on 12 Feb 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc