# typebuffer

> 一个简单的二进制读写库,可用于定义复杂的协议

Latest version **0.1.6** (published 2024-03-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install typebuffer
pnpm add typebuffer
yarn add typebuffer
bun add typebuffer
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2024-03-13 |
| First published | 2024-01-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 70.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | bansky |
| Maintainers | bansky |
| Keywords | vless, socks, protocols |

## Links

- npm: https://www.npmjs.com/package/typebuffer
- Repository: https://github.com/BanKnight/protocols
- Homepage: https://github.com/BanKnight/protocols#readme
- Issues: https://github.com/BanKnight/protocols/issues
- npm.io page: https://npm.io/package/typebuffer

## Recent versions

- 0.1.6 (latest) — 2024-03-13
- 0.1.0-alpha.1 (alpha) — 2024-01-24
- 0.1.5 — 2024-03-13
- 0.1.4 — 2024-03-13
- 0.1.3 — 2024-03-13
- 0.1.2 — 2024-03-10
- 0.1.1 — 2024-03-03
- 0.1.0 — 2024-03-02

## README

# typebuffer

一个简单的二进制读写库,可用于定义复杂的协议

### 安装方式

```bash
npm install typebuffer
```

### 例子：socks5例子

```typescript
import { Types } from "typebuffer";

export const TypeAddress = Types.Struct()
    .define("family", Types.UInt8())
    .switch("family", {
        0x01: ["ipv4", Types.IPV4()],
        0x03: ["domain", Types.Domain()],
        0x04: ["ipv6", Types.IPV6BE()],
    })

export const Version = Types.Struct()
    .define("version", Types.UInt8(0x05))

export const Negotiate = Types.Struct(Version)
    .define("nmethods", Types.UInt8())

export const NegotiateReply = Types.Struct(Version)
    .define("method", Types.UInt8())

export const Auth = Types.Struct(Version)
    .define("uname", Types.L8String())
    .define("passwd", Types.L8String())

export const AuthReply = Types.Struct(Version)
    .define("status", Types.UInt8())

export const Request = Types.Struct(Version)
    .define("cmd", Types.UInt8())
    .define("rsv", Types.UInt8(0x00))
    .define("address", TypeAddress)
    .define("port", Types.UInt16BE())

export const Reply = Types.Struct(Version)
    .define("reply", Types.UInt8())
    .define("rsv", Types.UInt8(0x00))
    .define("bind", TypeAddress)
    .define("port", Types.UInt16BE())
```

---
_Source: https://npm.io/package/typebuffer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
