cstruct

package
v0.0.0-...-8c018af Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

package proto

Index

Constants

View Source
const (
	VersionFieldName    string = "Ver" // struct版本字段名,值为正数,一般定义为:Ver uint8,值从1开始;如果新增定义Ver字段,Ver可定义为无符号数据类型(无符号最小值为0),其它字段的tag ver设置从0开始,这样就可以处理所有字段数据
	VersionFieldTagName string = "ver" // struct版本字段tag名,表示定义该字段时的版本号,例如:Data uint32 `ver:"1"`,当 tag ver的值 <= struct版本字段值,本struc字段的数据就会做解码处理;当编码的时候发现 tag ver的值 > struct版本字段值,会panic
)

Variables

View Source
var (
	ErrNil = errors.New("cstruct: Marshal called with nil")
)
View Source
var OptionSliceIgnoreNil = false

OptionSliceIgnoreNil slice 元素类型为指针时,是否忽略nil

View Source
var OptionSliceStructPointer = true

OptionSliceStructPointer slice 元素类型为结构体时,是否要求为结构体指针

Functions

func GetSize

func GetSize(obj IStruct) (uint16, error)

func Marshal

func Marshal(obj IStruct) ([]byte, error)

func Unmarshal

func Unmarshal(buf []byte, obj IStruct) error

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

func NewBuffer

func NewBuffer(e []byte) *Buffer

func (*Buffer) Marshal

func (p *Buffer) Marshal(obj IStruct) error

func (*Buffer) Reset

func (p *Buffer) Reset()

func (*Buffer) Unmarshal

func (p *Buffer) Unmarshal(obj IStruct) error

type IStruct

type IStruct interface {
}

type Properties

type Properties struct {
	Name string
	// contains filtered or unexported fields
}

type StructProperties

type StructProperties struct {
	Prop []*Properties
	// contains filtered or unexported fields
}

func GetProperties

func GetProperties(t reflect.Type) *StructProperties

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL