github.com/webmafia/fast@v0.10.0/binary/stream_write_int.go (about)

     1  // Borrowed from jsoniter (https://github.com/json-iterator/go)
     2  package binary
     3  
     4  import (
     5  	"encoding/binary"
     6  )
     7  
     8  // Write int8
     9  func (b *StreamWriter) WriteInt8(v int8) error {
    10  	return b.WriteByte(uint8(v))
    11  }
    12  
    13  // Write int16
    14  func (b *StreamWriter) WriteInt16(v int16) error {
    15  	return b.WriteUint16(uint16(v))
    16  }
    17  
    18  // Write int32
    19  func (b *StreamWriter) WriteInt32(v int32) error {
    20  	return b.WriteUint32(uint32(v))
    21  }
    22  
    23  // Write int64
    24  func (b *StreamWriter) WriteInt64(v int64) error {
    25  	return b.WriteUint64(uint64(v))
    26  }
    27  
    28  // Write int
    29  func (b *StreamWriter) WriteInt(v int) error {
    30  	return b.WriteInt64(int64(v))
    31  }
    32  
    33  func (b *StreamWriter) WriteVarint(v int64) (err error) {
    34  	var buf [binary.MaxVarintLen64]byte
    35  	n := binary.PutVarint(buf[:], v)
    36  	_, err = b.Write(buf[:n])
    37  	return
    38  }