Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Encodes and decodes objects to binary, supports nested references.
npm i
npm run compile
npm run test
.rollup.cache
cache
dist
npm run compile
import { ObjCodec } from 'obj-codec';
import { createWriteStream } from 'fs';
const DATA = {};
// Using globally registered custom codecs
function useGlobalCodoc() {
const encoder = ObjCodec.encode(DATA);
const writeStream = createWriteStream('path/to/file');
for (const data of encoder.encode()) {
writeStream.write(data);
}
writeStream.end();
}
// Use custom codecs that are instance-only
function useInstanceCodoc() {
const codec = new ObjCodec();
// Call `codec.registerCodecs` to register custom codecs limited to the instance `codec
const encoder = codec.encode(DATA);
const writeStream = createWriteStream('path/to/file');
for (const data of encoder.encode()) {
writeStream.write(data);
}
writeStream.end();
}
import { ObjCodec } from 'obj-codec';
import { createReadStream } from 'fs';
// Using globally registered custom codecs
function useGlobalCodoc() {
const decoder = ObjCodec.decode();
const readStream = createReadStream('path/to/file');
readStream.on('data', (chunk) => {
decoder.write(new Uint8Array(chunk));
});
readStream.on('end', () => {
encoder.end().then(console.log);
});
}
// Use custom codecs that are instance-only
function useInstanceCodoc() {
const codec = new ObjCodec();
// Call `codec.registerCodecs` to register custom codecs limited to the instance `codec
const decoder = codec.decode();
const readStream = createReadStream('path/to/file');
readStream.on('data', (chunk) => {
decoder.write(new Uint8Array(chunk));
});
readStream.on('end', () => {
encoder.end().then(console.log);
});
}
Descripton | Type |
---|---|
Version | u8 |
Custom Type Mapping Table Length | Flexable Unsigned Integer |
Custom Type Mapping Table | Custom Type Mapping Table |
Data Object[] | Data Object |
Length of customized type mapping table
.
Data Object
type ID is the index of the mapping table if it is greater than 16, minus 17.Custom Type Codecs
based on the mapping tableInternal Type
DataReference: Codec
ID | Name | Length (Bytes) | Weights (the smaller the first) | Referencable* | Comment |
---|---|---|---|---|---|
0 | Pointer | Flexable* | N/A | N/A | Implicit type, cannot be used directly. Created automatically by the main codecs (ObjEncoder , ObjDecoder ) |
1 | Binary | 2 | X | ||
2 | Number | 8 | 0 | ||
3 | BigInt | 0 | |||
4 | String | 1 | X | ||
5 | false | 0 | 0 | No data area | |
6 | true | 0 | 0 | No data area | |
7 | null | 0 | 0 | No data area | |
8 | undefined | 0 | 0 | No data area | |
9 | Object | 5 | X | Fallback type | |
10 | Array | 5 | X | Fallback type | |
11 | Set | 4 | X | ||
12 | Map | 4 | X | ||
13 | Date | 8 | 4 | X | |
14 | RegExp | 4 | X | ||
15 | Symbol | 1 | X | ||
16 | Unique Pointer | Not Implemented | |||
17+ | Custom Type | N/A | 3 | X |
Comments:
Used to represent unsigned integers, supports dynamic encoding of lengths.
0
-> `0b0000_0000127
-> 0b0111_1111
128
-> 0b1000_0000
and `0b0000_0001129
-> 0b1000_0001
and 0b0000_0001
.interface ICodec<
Data,
DecodeMiddle = Data,
EncodeResult extends BasicType,
> {
encode(data: Data): EncodeResult;
decode(encoded: EncodeResult): DecodeMiddle;
dereference?(data: DecodeMiddle): any;
}
The encode
method can return data of any type belonging to BasicType
.
If a non-BasicType
type is returned, it will be encoded directly as a BasicType
, and custom codecs will be ignored.
The decode
method needs to return Data
type.
Parameter encoded
may contain a pointer, which cannot be dereferenced and should be kept in the return value.
The dereference
method is used to dereference the return value of the decode
method.
The method return value is ignored.
registerCodecs(id: string, codec: AnyCodec, constructor: IClass): void;
FAQs
Encodes and decodes objects to binary, supports nested references
The npm package obj-codec receives a total of 0 weekly downloads. As such, obj-codec popularity was classified as not popular.
We found that obj-codec demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.