當前位置: 首頁>>代碼示例>>Golang>>正文


Golang read.Uint16函數代碼示例

本文整理匯總了Golang中github.com/tehmaze/netflow/read.Uint16函數的典型用法代碼示例。如果您正苦於以下問題:Golang Uint16函數的具體用法?Golang Uint16怎麽用?Golang Uint16使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Uint16函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Unmarshal

func (h *PacketHeader) Unmarshal(r io.Reader) error {
	if err := read.Uint16(&h.Version, r); err != nil {
		return err
	}
	if err := read.Uint16(&h.Count, r); err != nil {
		return err
	}
	// The spec says at most 24 flows in one packet, but reality disagrees.
	if h.Count < 1 || h.Count > 32 {
		return fmt.Errorf("protocol error: %d flows out of bounds", h.Count)
	}
	var u uint32
	if err := read.Uint32(&u, r); err != nil {
		return err
	}
	h.SysUptime = time.Duration(u)
	var t uint64
	if err := read.Uint64(&t, r); err != nil {
		return err
	}
	h.Unix = time.Unix(int64(t>>32), int64(t&0xffffffff))
	if err := read.Uint32(&h.FlowSequence, r); err != nil {
		return err
	}
	if err := read.Uint8(&h.EngineType, r); err != nil {
		return err
	}
	if err := read.Uint8(&h.EngineID, r); err != nil {
		return err
	}
	if err := read.Uint16(&h.SamplingInterval, r); err != nil {
		return err
	}
	return nil
}
開發者ID:nyxtom,項目名稱:netflow,代碼行數:35,代碼來源:packet.go

示例2: Unmarshal

func (otr *OptionsTemplateRecord) Unmarshal(r io.Reader) error {
	if err := read.Uint16(&otr.TemplateID, r); err != nil {
		return err
	}
	if err := read.Uint16(&otr.FieldCount, r); err != nil {
		return err
	}
	if err := read.Uint16(&otr.ScopeFieldCount, r); err != nil {
		return err
	}

	if otr.ScopeFieldCount > otr.FieldCount {
		return errProtocol(fmt.Sprintf("scope field count %d higher than field count %d", otr.ScopeFieldCount, otr.FieldCount))
	}

	buffer := new(bytes.Buffer)
	buffer.ReadFrom(r)
	if debug {
		hexdump(buffer.Bytes())
	}

	otr.ScopeFields = make(FieldSpecifiers, otr.ScopeFieldCount)
	if err := otr.ScopeFields.Unmarshal(buffer); err != nil {
		return err
	}

	otr.Fields = make(FieldSpecifiers, otr.FieldCount-otr.ScopeFieldCount)
	if err := otr.Fields.Unmarshal(buffer); err != nil {
		return err
	}

	return nil
}
開發者ID:tehmaze,項目名稱:netflow,代碼行數:33,代碼來源:packet.go

示例3: Unmarshal

func (f *FieldSpecifier) Unmarshal(r io.Reader) error {
	if err := read.Uint16(&f.Type, r); err != nil {
		return err
	}
	if err := read.Uint16(&f.Length, r); err != nil {
		return err
	}

	return nil
}
開發者ID:jrossi,項目名稱:netflow,代碼行數:10,代碼來源:packet.go


注:本文中的github.com/tehmaze/netflow/read.Uint16函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。