
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
cstruct-buffer
Advanced tools
A TypeScript library for precise C-style memory layout serialization/deserialization.
npm install cstruct-buffer
@CStruct.Layout({ pack: 4 })
class SensorData extends CStruct {
@CStruct.U32(1, 8) // Single value with 8-byte alignment
timestamp: number = 0;
@CStruct.F64(3) // Fixed array of 3 doubles
readings: number[] = [0.0, 0.0, 0.0];
@CStruct.Str(0, 1) // Flexible string (last field)
status: string = "OK";
}
@CStruct.Layout({
pack?: number; // Member alignment (0=default)
align?: number; // Struct alignment (0=natural)
})
@CStruct.U8(arrLength?, align?)
@CStruct.U16(arrLength?, align?)
@CStruct.U32(arrLength?, align?)
@CStruct.U64(arrLength?, align?)
@CStruct.I8(arrLength?, align?)
@CStruct.I16(arrLength?, align?)
@CStruct.I32(arrLength?, align?)
@CStruct.I64(arrLength?, align?)
@CStruct.F32(arrLength?, align?)
@CStruct.F64(arrLength?, align?)
| Position | Parameter | Description |
|---|---|---|
| 1 | arrLength = 1 | Array length: 0=flexible, 1=single, >1=fixed |
| 2 | align = 0 | Field alignment (optional, default=0) |
@CStruct.Str(maxBytes, align?)
| Position | Parameter | Description |
|---|---|---|
| 1 | maxBytes = 0 | Max bytes (0=flexible length) |
| 2 | align = 0 | Field alignment (optional) |
@CStruct.Struct(StructClass, arrLength?, align?)
| Position | Parameter | Description |
|---|---|---|
| 1 | StructClass | Nested struct class (must extend CStruct) |
| 2 | arrLength = 1 | Array length |
| 3 | align = 0 | Field alignment (optional, default=0) |
@CStruct.Layout({ pack: 8 })
class Vector3D extends CStruct {
@CStruct.F32(3) coordinates: number[] = [0,0,0];
}
@CStruct.Layout({ align: 16 })
class PhysicsObject extends CStruct {
@CStruct.Struct(Vector3D)
position: Vector3D = new Vector3D();
@CStruct.Struct(Vector3D, 4) // Fixed array of 4 vectors
vertices: Vector3D[] = Array(4).fill(new Vector3D());
}
const sensor = new SensorData();
sensor.timestamp = Date.now();
sensor.readings = [25.3, 26.1, 24.9];
sensor.status = "ACTIVE";
// Serialize with default endianness (little-endian)
const buffer = sensor.serialize();
// Serialize with big-endian
const beBuffer = sensor.serialize('big');
// From network/data stream
const receivedBuffer = new Uint8Array([...]);
// Deserialize with validation
const restoredSensor = SensorData.deserialize(receivedBuffer);
console.log(restoredSensor.status); // "ACTIVE"
// Cross-platform data exchange
const networkBuffer = sensor.serialize('big');
const localCopy = SensorData.deserialize(networkBuffer, 'big');
// Verify struct size matches C implementation
console.log(sensor.size); // 64 (bytes)
// Check field offsets
console.log(sensor.Fields[0].offset); // 0
console.log(sensor.Fields[1].offset); // 8
MIT
FAQs
Binary serialization framework for C-style structs
The npm package cstruct-buffer receives a total of 2 weekly downloads. As such, cstruct-buffer popularity was classified as not popular.
We found that cstruct-buffer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.