Skip to content

高速字节缓存库,顺序的写入读取,不用在意资源的释放整理

License

Notifications You must be signed in to change notification settings

chenyalyg/ByteBuf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ByteBuf

高速字节缓存库,顺序的写入读取,不用在意资源的释放整理

Installing

go get -u github.com/chenyalyg/ByteBuf

Usage

package main

import (

  "encoding/binary"
  "fmt"
  "log"
  
  "github.com/chenyalyg/ByteBuf"
)

func main() {
  buf := bytebuf.New(bytebuf.DeepCopy)
  buf.WriteInt16(12345,binary.BigEndian)
  buf.WriteInt32(12345,binary.BigEndian)
  buf.WriteFloat32(12345.22,binary.BigEndian)
  buf.WriteFloat64(12345.33,binary.BigEndian)
  b:=make([]byte,10)
  buf.WriteBytes(b)
  
  num1,err:=buf.ReadInt16(binary.BigEndian)
  if err != nil {
	log.Fatal(err)
  }
  fmt.Println("num1 :",num1)
  
  num2,err:=buf.ReadInt32(binary.BigEndian)
  if err != nil {
	log.Fatal(err)
  }
  fmt.Println("num2 :",num2)
  
  num3,err:=buf.ReadFloat32(binary.BigEndian)
  if err != nil {
	log.Fatal(err)
  }
  fmt.Println("num3 :",num3)
  
  num4,err:=buf.ReadFloat64(binary.BigEndian)
  if err != nil {
	log.Fatal(err)
  }
  fmt.Println("num4 :",num4)
  
  b2:=make([]byte,buf.Len())
  n:=buf.ReadBytes(b2)
  fmt.Println("read size:",n)

}

About

高速字节缓存库,顺序的写入读取,不用在意资源的释放整理

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages