ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - lim-yoona/tcpack: tcpack is an application protocol based on TCP to Pack and Unpack bytes stream in go program.
tcpack is an application protocol based on TCP to Pack and Unpack bytes stream in go program. - lim-yoona/tcpack
Visit Site

GitHub - lim-yoona/tcpack: tcpack is an application protocol based on TCP to Pack and Unpack bytes stream in go program.

GitHub - lim-yoona/tcpack: tcpack is an application protocol based on TCP to Pack and Unpack bytes stream in go program.

tcpack

Go Reference GitHub Go Report GitHub release (with filter) Mentioned in Awesome Go

English | 简体中文

tcpack is an application protocol based on TCP to Pack and Unpack bytes stream in go (or 'golang' for search engine friendliness) program.

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.

tcpack is to solve this problem by encapsulating the request data into a message, packaging it when sending and unpacking it when receiving.

notice: It is unsafe to use a packer to read and write messages concurrently on the same connection. Do not do this, as it will have unpredictable consequences!

If you want to use multiple packagers based on the same TCP connection to send and receive messages concurrently, please use safetcpack.

What's in the box?

This library provides a packager which support Pack and Unpack.

Installation Guidelines

  1. To install the tcpack package, you first need to have Go installed, then you can use the command below to add tcpack as a dependency in your Go program.
go get -u github.com/lim-yoona/tcpack
  1. Import it in your code:
import "github.com/lim-yoona/tcpack"

Usage

package main

import "github.com/lim-yoona/tcpack"

func main() {
	// Create a packager
	mp := tcpack.NewMsgPack(8, tcpConn)

	// Pack and send a message
	msg := tcpack.NewMessage(0, uint32(len([]byte(data))), []byte(data))
	num, err := mp.Pack(msg)

	// Unpack and receive a message
	msg, err := mp.Unpack()
}

Support JSON

type Person struct {
	Name string `json:"name"`
	Age  int    `json:"age"`
}

// Create a packager
mp := tcpack.NewMsgPack(8, tcpConn)

// data JSON Marshal
data := &Person{
	Name: "jack",
	Age:  20,
}
dataJSON, _ := json.Marshal(data)

// Pack and send a message
msgSend := tcpack.NewMessage(0, uint32(len(dataJSON)), dataJSON)
num, err := mp.Pack(msgSend)

// Unpack and receive a message
msgRsv, err := mp.Unpack()

// JSON UnMarshal
var dataRsv Person
json.Unmarshal(msgRsv.GetMsgData(), &dataRsv)

Examples

Here are some Examples.

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory