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


Golang ByteOrder.Uint32方法代碼示例

本文整理匯總了Golang中encoding/binary.ByteOrder.Uint32方法的典型用法代碼示例。如果您正苦於以下問題:Golang ByteOrder.Uint32方法的具體用法?Golang ByteOrder.Uint32怎麽用?Golang ByteOrder.Uint32使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在encoding/binary.ByteOrder的用法示例。


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

示例1: ReadUInt32

// ReadUInt32 reads a uint32 from r.
func ReadUInt32(r io.Reader, byteOrder binary.ByteOrder) (uint32, error) {
	var buf [4]byte
	if _, err := io.ReadFull(r, buf[:]); err != nil {
		return 0, err
	}
	return byteOrder.Uint32(buf[:]), nil
}
開發者ID:dgraph-io,項目名稱:dgraph,代碼行數:8,代碼來源:binary.go

示例2: NewNullFrame

func NewNullFrame(data []byte, byteOrder binary.ByteOrder) (*NullFrame, error) {
	if len(data) < NULL_FRAME_HEADER_LENGTH {
		return nil, errors.New(fmt.Sprintf("required at least %d bytes of data.", NULL_FRAME_HEADER_LENGTH))
	}

	return &NullFrame{byteOrder.Uint32(data), data[4:]}, nil
}
開發者ID:justmao945,項目名稱:httpdump,代碼行數:7,代碼來源:null.go

示例3: ReadFloat32

func ReadFloat32(buf []byte, format byte, endianness binary.ByteOrder) float32 {
	encoding := format & EncodingMask

	if encoding == EncodingFloatingPoint {
		return math.Float32frombits(endianness.Uint32(buf))
	} else {
		offset := 0
		if endianness == binary.LittleEndian {
			offset = len(buf) - 1
		}
		var neg byte = 0
		if encoding == EncodingSignedInt && buf[offset]&(1<<7) != 0 {
			neg = 0xFF
		}
		tmp := []byte{neg, neg, neg, neg}

		if endianness == binary.BigEndian {
			copy(tmp[4-len(buf):], buf)
		} else {
			copy(tmp, buf)
		}

		sample := endianness.Uint32(tmp)

		div := math.Pow(2, float64(len(buf)*8-1))
		if encoding == EncodingSignedInt {
			return float32(float64(int32(sample)) / div)
		} else {
			return float32(float64(sample)/div - 1.0)
		}
	}
}
開發者ID:xthexder,項目名稱:rawstreamer,代碼行數:32,代碼來源:common.go

示例4: ReadUint32

func (b *Buffer) ReadUint32(order binary.ByteOrder) (uint32, error) {
	if b.readPos >= len(b.Buf)-4 {
		return 0, io.EOF
	}
	u := order.Uint32(b.Buf[b.readPos:])
	b.readPos += 4
	return u, nil
}
開發者ID:huangjiasingle,項目名稱:gohper,代碼行數:8,代碼來源:buffer.go

示例5: newQosHistoryFromBytes

func newQosHistoryFromBytes(bin binary.ByteOrder, b []byte) (qosHistory, error) {
	if len(b) < 4+4 {
		return qosHistory{}, io.EOF
	}
	return qosHistory{
		kind:  bin.Uint32(b[0:]),
		depth: bin.Uint32(b[4:]),
	}, nil
}
開發者ID:liamstask,項目名稱:go-rtps,代碼行數:9,代碼來源:qos.go

示例6: timeFromBytes

func timeFromBytes(order binary.ByteOrder, b []byte) (time.Time, error) {
	if len(b) < 8 {
		return timeInvalid, io.EOF
	}

	sec := int64(order.Uint32(b[0:]))
	frac := int64(order.Uint32(b[4:]))
	return time.Unix(sec, (frac*nanosPerSec)>>32).UTC(), nil
}
開發者ID:liamstask,項目名稱:go-rtps,代碼行數:9,代碼來源:time.go

示例7: durationFromBytes

func durationFromBytes(order binary.ByteOrder, b []byte) (time.Duration, error) {
	if len(b) < 8 {
		return time.Duration(0), io.EOF
	}

	sec := order.Uint32(b[0:])
	nsec := order.Uint32(b[4:])

	return time.Duration(sec*nanosPerSec + nsec), nil
}
開發者ID:liamstask,項目名稱:go-rtps,代碼行數:10,代碼來源:time.go

示例8: makeGuid

func makeGuid(b []byte, order binary.ByteOrder) Guid {
	g := Guid{
		DataA: order.Uint32(b[:4]),
		DataB: order.Uint16(b[4:6]),
		DataC: order.Uint16(b[6:8]),
		DataD: [8]byte{},
	}
	copy(g.DataD[:], b[8:])
	return g
}
開發者ID:jhsimpson,項目名稱:siegfried,代碼行數:10,代碼來源:guid.go

示例9: rvalSRational

func rvalSRational(in []byte, bo binary.ByteOrder) reflect.Value {
	denom := int64(int32(bo.Uint32(in[4:])))
	if denom == 0 {
		// Prevent panics due to poorly written Rational fields with a
		// denominator of 0.  Their usable value would likely be 0.
		return reflect.New(reflect.TypeOf(big.Rat{}))
	}
	numer := int64(int32(bo.Uint32(in)))
	return reflect.ValueOf(big.NewRat(numer, denom))
}
開發者ID:jonathanpittman,項目名稱:tiff,代碼行數:10,代碼來源:fieldtype_default.go

示例10: newUDPv4LocFromBytes

func newUDPv4LocFromBytes(bin binary.ByteOrder, b []byte) (locator, error) {
	if len(b) < 4+4+16 {
		return locator{}, io.EOF
	}
	return locator{
		kind: int32(bin.Uint32(b[0:])),
		port: bin.Uint32(b[4:]),
		addr: net.IPv4(b[20], b[21], b[22], b[23]), // xxx: ipv6 support
	}, nil
}
開發者ID:liamstask,項目名稱:go-rtps,代碼行數:10,代碼來源:locator.go

示例11: Uint32

// Uint32 reads four bytes from the provided reader using a buffer from the
// free list, converts it to a number using the provided byte order, and returns
// the resulting uint32.
func (l binaryFreeList) Uint32(r io.Reader, byteOrder binary.ByteOrder) (uint32, error) {
	buf := l.Borrow()[:4]
	if _, err := io.ReadFull(r, buf); err != nil {
		l.Return(buf)
		return 0, err
	}
	rv := byteOrder.Uint32(buf)
	l.Return(buf)
	return rv, nil
}
開發者ID:decred,項目名稱:dcrd,代碼行數:13,代碼來源:common.go

示例12: valToString

func (p *paramListItem) valToString(bin binary.ByteOrder) (string, error) {
	if len(p.value) < 4 {
		return "", io.EOF
	}
	sz := int(bin.Uint32(p.value[0:]))
	if len(p.value) < 4+sz {
		return "", io.EOF
	}
	// encoded with null terminator, strip that out
	return string(p.value[4 : 4+sz-1]), nil
}
開發者ID:liamstask,項目名稱:go-rtps,代碼行數:11,代碼來源:proto.go

示例13: walksymtab

func walksymtab(data []byte, ptrsz int, fn func(sym) error) error {
	var order binary.ByteOrder = binary.BigEndian
	var s sym
	p := data
	for len(p) >= 4 {
		// Symbol type, value.
		if len(p) < ptrsz {
			return &formatError{len(data), "unexpected EOF", nil}
		}
		// fixed-width value
		if ptrsz == 8 {
			s.value = order.Uint64(p[0:8])
			p = p[8:]
		} else {
			s.value = uint64(order.Uint32(p[0:4]))
			p = p[4:]
		}

		var typ byte
		typ = p[0] & 0x7F
		s.typ = typ
		p = p[1:]

		// Name.
		var i int
		var nnul int
		for i = 0; i < len(p); i++ {
			if p[i] == 0 {
				nnul = 1
				break
			}
		}
		switch typ {
		case 'z', 'Z':
			p = p[i+nnul:]
			for i = 0; i+2 <= len(p); i += 2 {
				if p[i] == 0 && p[i+1] == 0 {
					nnul = 2
					break
				}
			}
		}
		if len(p) < i+nnul {
			return &formatError{len(data), "unexpected EOF", nil}
		}
		s.name = p[0:i]
		i += nnul
		p = p[i:]

		fn(s)
	}
	return nil
}
開發者ID:RajibTheKing,項目名稱:gcc,代碼行數:53,代碼來源:file.go

示例14: decodeTag

// decodeTag assumes len(buf) >= 8
func decodeTag(buf []byte, bo binary.ByteOrder) tag {
	var t tag
	smallTag := bo.Uint32(buf[:])
	t.dataType = dataType(smallTag)
	t.smallFormat = (smallTag >> 16) != 0
	if t.smallFormat == true {
		t.nBytes = uint32(smallTag >> 16)
	} else {
		t.nBytes = bo.Uint32(buf[4:])
	}
	return t
}
開發者ID:maspitz,項目名稱:matfile,代碼行數:13,代碼來源:matfile.go

示例15: newQosReliabilityFromBytes

func newQosReliabilityFromBytes(bin binary.ByteOrder, b []byte) (qosReliability, error) {
	if len(b) < 4+4+4 {
		return qosReliability{}, io.EOF
	}
	dur, err := durationFromBytes(bin, b[4:])
	if err != nil {
		return qosReliability{}, err
	}
	return qosReliability{
		kind:            bin.Uint32(b[0:]),
		maxBlockingTime: dur,
	}, nil
}
開發者ID:liamstask,項目名稱:go-rtps,代碼行數:13,代碼來源:qos.go


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