diff --git a/README-CN.md b/README-CN.md index f739893..ce61ffa 100644 --- a/README-CN.md +++ b/README-CN.md @@ -1,36 +1,36 @@ -# msgpack +# tcpack -[![Go Reference](https://pkg.go.dev/badge/github.com/lim-yoona/msgpack.svg)](https://pkg.go.dev/github.com/lim-yoona/msgpack) -![GitHub](https://img.shields.io/github/license/lim-yoona/msgpack) -[![Go Report](https://img.shields.io/badge/go%20report-A+-brightgreen.svg?style=flat)](https://goreportcard.com/report/github.com/lim-yoona/msgpack) -![GitHub release (with filter)](https://img.shields.io/github/v/release/lim-yoona/msgpack) +[![Go Reference](https://pkg.go.dev/badge/github.com/lim-yoona/tcpack.svg)](https://pkg.go.dev/github.com/lim-yoona/tcpack) +![GitHub](https://img.shields.io/github/license/lim-yoona/tcpack) +[![Go Report](https://img.shields.io/badge/go%20report-A+-brightgreen.svg?style=flat)](https://goreportcard.com/report/github.com/lim-yoona/tcpack) +![GitHub release (with filter)](https://img.shields.io/github/v/release/lim-yoona/tcpack) [English](README.md) | 简体中文 -[msgpack](https://pkg.go.dev/github.com/lim-yoona/msgpack) 是一个基于 TCP 的应用层协议,用于在 [go](https://go.dev/) 程序中打包和解包字节流。 +[tcpack](https://pkg.go.dev/github.com/lim-yoona/tcpack) 是一个基于 TCP 的应用层协议,用于在 [go](https://go.dev/) 程序中打包和解包字节流。 -## msgpack做了什么? +## tcpack做了什么? 众所周知,TCP 是面向字节流的传输层协议,其数据传输没有明确的边界,因此应用层读取的数据可能包含多个请求而导致无法处理业务。 -[msgpack](https://pkg.go.dev/github.com/lim-yoona/msgpack) 就是为了解决这个问题,将请求数据封装成消息,发送时打包,接收时解包。 +[tcpack](https://pkg.go.dev/github.com/lim-yoona/tcpack) 就是为了解决这个问题,将请求数据封装成消息,发送时打包,接收时解包。 -## msgpack中有什么? +## tcpack中有什么? -msgpack 提供了一个支持 Pack 和 Unpack 的打包器。 +`tcpack` 提供了一个支持 Pack 和 Unpack 的打包器。 ## 安装指南 -1. 为安装 msgpack 包, 首先你需要安装 [Go](https://go.dev/doc/install) , 然后你可以使用下面的命令将 `msgpack` 作为你Go程序的依赖。 +1. 为安装 tcpack 包, 首先你需要安装 [Go](https://go.dev/doc/install) , 然后你可以使用下面的命令将 `tcpack` 作为你Go程序的依赖。 ```sh -go get -u github.com/lim-yoona/msgpack +go get -u github.com/lim-yoona/tcpack ``` -2. 将 msgpack 导入到代码中: +2. 将 tcpack 导入到代码中: ```go -import "github.com/lim-yoona/msgpack" +import "github.com/lim-yoona/tcpack" ``` ## 使用 @@ -38,14 +38,14 @@ import "github.com/lim-yoona/msgpack" ```go package main -import "github.com/lim-yoona/msgpack" +import "github.com/lim-yoona/tcpack" func main() { // 创建一个打包器 - mp := msgpack.NewMsgPack(8, tcpConn) + mp := tcpack.NewMsgPack(8, tcpConn) // 打包一个消息 - msg := msgpack.NewMessage(0, uint32(len([]byte(data))), []byte(data)) + msg := tcpack.NewMessage(0, uint32(len([]byte(data))), []byte(data)) msgByte, err := mp.Pack(msg) num, err := tcpConn.Write(msgByte) @@ -63,7 +63,7 @@ type Person struct { } // 创建一个打包器 -mp := msgpack.NewMsgPack(8, tcpConn) +mp := tcpack.NewMsgPack(8, tcpConn) // data JSON Marshal data := &Person{ @@ -73,7 +73,7 @@ data := &Person{ dataJSON, _ := json.Marshal(data) // 打包一个消息 -msgSend := msgpack.NewMessage(0, uint32(len(dataJSON)), dataJSON) +msgSend := tcpack.NewMessage(0, uint32(len(dataJSON)), dataJSON) msgSendByte, _ := mpClient.Pack(msgSend) num, err := tcpConn.Write(msgSendByte) @@ -87,5 +87,5 @@ json.Unmarshal(msgRsv.GetMsgData(), &dataRsv) ## 示例 -这有一些 [示例](https://github.com/lim-yoona/msgpack/tree/main/example)。 +这有一些 [示例](https://github.com/lim-yoona/tcpack/tree/main/example)。 diff --git a/README.md b/README.md index 9fc5328..a1572b4 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,20 @@ -# msgpack +# tcpack -[![Go Reference](https://pkg.go.dev/badge/github.com/lim-yoona/msgpack.svg)](https://pkg.go.dev/github.com/lim-yoona/msgpack) -![GitHub](https://img.shields.io/github/license/lim-yoona/msgpack) -[![Go Report](https://img.shields.io/badge/go%20report-A+-brightgreen.svg?style=flat)](https://goreportcard.com/report/github.com/lim-yoona/msgpack) -![GitHub release (with filter)](https://img.shields.io/github/v/release/lim-yoona/msgpack) +[![Go Reference](https://pkg.go.dev/badge/github.com/lim-yoona/tcpack.svg)](https://pkg.go.dev/github.com/lim-yoona/tcpack) +![GitHub](https://img.shields.io/github/license/lim-yoona/tcpack) +[![Go Report](https://img.shields.io/badge/go%20report-A+-brightgreen.svg?style=flat)](https://goreportcard.com/report/github.com/lim-yoona/tcpack) +![GitHub release (with filter)](https://img.shields.io/github/v/release/lim-yoona/tcpack) English | [简体中文](README-CN.md) -[msgpack](https://pkg.go.dev/github.com/lim-yoona/msgpack) is an application protocol based on TCP to Pack and Unpack bytes stream in [go](https://go.dev/) (or 'golang' for search engine friendliness) program. +[tcpack](https://pkg.go.dev/github.com/lim-yoona/tcpack) is an application protocol based on TCP to Pack and Unpack bytes stream in [go](https://go.dev/) (or 'golang' for search engine friendliness) program. -## What dose msgpack do? +## What dose tcpack do? As we all know, TCP is a transport layer protocol oriented to byte streams. Its data transmission has no clear boundaries, so the data read by the application layer may contain multiple requests and cannot be processed. -[msgpack](https://pkg.go.dev/github.com/lim-yoona/msgpack) is to solve this problem by encapsulating the request data into a message, packaging it when sending and unpacking it when receiving. +[tcpack](https://pkg.go.dev/github.com/lim-yoona/tcpack) is to solve this problem by encapsulating the request data into a message, packaging it when sending and unpacking it when receiving. ## What's in the box? @@ -22,16 +22,16 @@ This library provides a packager which support Pack and Unpack. ## Installation Guidelines -1. To install the msgpack package, you first need to have [Go](https://go.dev/doc/install) installed, then you can use the command below to add `msgpack` as a dependency in your Go program. +1. To install the tcpack package, you first need to have [Go](https://go.dev/doc/install) installed, then you can use the command below to add `tcpack` as a dependency in your Go program. ```sh -go get -u github.com/lim-yoona/msgpack +go get -u github.com/lim-yoona/tcpack ``` 2. Import it in your code: ```go -import "github.com/lim-yoona/msgpack" +import "github.com/lim-yoona/tcpack" ``` ## Usage @@ -39,14 +39,14 @@ import "github.com/lim-yoona/msgpack" ```go package main -import "github.com/lim-yoona/msgpack" +import "github.com/lim-yoona/tcpack" func main() { // Create a packager - mp := msgpack.NewMsgPack(8, tcpConn) + mp := tcpack.NewMsgPack(8, tcpConn) // Pack a message - msg := msgpack.NewMessage(0, uint32(len([]byte(data))), []byte(data)) + msg := tcpack.NewMessage(0, uint32(len([]byte(data))), []byte(data)) msgByte, err := mp.Pack(msg) num, err := tcpConn.Write(msgByte) @@ -64,7 +64,7 @@ type Person struct { } // Create a packager -mp := msgpack.NewMsgPack(8, tcpConn) +mp := tcpack.NewMsgPack(8, tcpConn) // data JSON Marshal data := &Person{ @@ -74,7 +74,7 @@ data := &Person{ dataJSON, _ := json.Marshal(data) // Pack a message -msgSend := msgpack.NewMessage(0, uint32(len(dataJSON)), dataJSON) +msgSend := tcpack.NewMessage(0, uint32(len(dataJSON)), dataJSON) msgSendByte, _ := mpClient.Pack(msgSend) num, err := tcpConn.Write(msgSendByte) @@ -88,5 +88,5 @@ json.Unmarshal(msgRsv.GetMsgData(), &dataRsv) ## Examples -Here are some [Examples](https://github.com/lim-yoona/msgpack/tree/main/example). +Here are some [Examples](https://github.com/lim-yoona/tcpack/tree/main/example). diff --git a/go.mod b/go.mod index 36fa755..57af57e 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,11 @@ -module github.com/lim-yoona/msgpack +module github.com/lim-yoona/tcpack go 1.20 -require github.com/smartystreets/goconvey v1.8.1 +require ( + github.com/lim-yoona/msgpack v0.1.0 + github.com/smartystreets/goconvey v1.8.1 +) require ( github.com/gopherjs/gopherjs v1.17.2 // indirect diff --git a/go.sum b/go.sum index 7fea79b..14348cd 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25d github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/lim-yoona/msgpack v0.1.0 h1:sAULeEVw0RpF9iujzIFzAYntuE/dFd9v6yLqhWZKAPU= +github.com/lim-yoona/msgpack v0.1.0/go.mod h1:w/GynN0+bueeewRWfznv51+auiQuX1O/BSp41dAHFWk= github.com/smarty/assertions v1.15.0 h1:cR//PqUBUiQRakZWqBiFFQ9wb8emQGDb0HeGdqGByCY= github.com/smarty/assertions v1.15.0/go.mod h1:yABtdzeQs6l1brC900WlRNwj6ZR55d7B+E8C6HtKdec= github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY= diff --git a/message.go b/message.go index 8626465..d31322e 100644 --- a/message.go +++ b/message.go @@ -1,4 +1,4 @@ -package msgpack +package tcpack // Imessage is an interface that definds a message, // which carries DataLen, MsgId and MsgData. diff --git a/msgpack.go b/msgpack.go index d7dac29..ab21dc2 100644 --- a/msgpack.go +++ b/msgpack.go @@ -1,4 +1,4 @@ -package msgpack +package tcpack import ( "bytes" diff --git a/msgpack_test.go b/msgpack_test.go index d2224fb..3dcb030 100644 --- a/msgpack_test.go +++ b/msgpack_test.go @@ -1,4 +1,4 @@ -package msgpack +package tcpack import ( "fmt"