util

package
v0.0.0-...-afbecfe Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2022 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderSize   = 6
	BufferSize   = 4096
	Uint32Max    = 4294967295
	DownloadPath = "./downloaded"
)

Variables

View Source
var EmptyFileName = errors.New("empty filename")

Functions

func ByteToUint16

func ByteToUint16(b []byte) uint16

ByteToUint16 converts byte slices to uint16

func BytesToBase64

func BytesToBase64(data []byte) []byte

BytesToBase64 encodes raw bytes to base64-encoded bytes

func CheckIPAddress

func CheckIPAddress(ip string) bool

CheckIPAddress check if ip address is valid or not

func Int64ToUint32

func Int64ToUint32(n int64) (uint32, error)

Int64ToUint32 converts int64 value to uint32. Returns value and error. If value occurs overflow, 0 and error is returned

func IntToUint32

func IntToUint32(n int) (uint32, error)

IntToUint32 converts int64 value to uint32. Returns value and error. If value occurs overflow, 0 and error is returned

func ReadBinary deprecated

func ReadBinary(reader io.Reader) (errorCode *common.Error, err error)

Deprecated: ReadBinary reads file name and file content from a connection and save it.

func ReadBytes deprecated

func ReadBytes(reader io.Reader) (b []byte, err error)

Deprecated: ReadBytes reads bytes from reader

func ReadBytesErr deprecated

func ReadBytesErr(reader io.Reader) (b []byte, errorCode *common.Error, err error)

Deprecated: ReadBytesErr reads b from reader.

func ReadBytesToWriter

func ReadBytesToWriter(reader io.Reader, writer io.Writer, writeWithSize bool) (n int, err error)

ReadBytesToWriter reads message from reader and write it to writer. First four bytes of reader should be uint32 size of the message, represented in big endian. Common usage for this function is to read from net.Conn, and write to temp file.

func ReadString deprecated

func ReadString(reader io.Reader) (str string, err error)

Deprecated: ReadString reads string from reader

func Uint16ToByte

func Uint16ToByte(size uint16) []byte

Uint16ToByte converts uint16 value to byte slices

func Uint32ToByte

func Uint32ToByte(size uint32) []byte

Uint32ToByte converts uint32 value to byte slices

func WriteBinary deprecated

func WriteBinary(writer io.Writer, filePath string) (int, error)

Deprecated: WriteBinary opens file and writes byte data to writer. Returns total length of bytes sent, and error. err == nil only if total bytes sent = file size. writer is likely to be net.Conn. File size cannot exceed max value of uint32 as of now. We can split files or change the data type to uint64 if time allows.

func WriteBytes deprecated

func WriteBytes(writer io.Writer, b []byte) (int, error)

Deprecated: WriteBytes

func WriteBytesErr deprecated

func WriteBytesErr(writer io.Writer, b []byte, errorToWrite *common.Error) (n int, err error)

Deprecated: WriteBytesErr write b to writer. Returns int indicating the number of bytes written, and error, if any.

func WriteConfig

func WriteConfig(fileName string, config interface{}) (err error)

WriteConfig writes config to fileName in yaml format

func WriteMessage

func WriteMessage(writer io.Writer, b []byte, errorToWrite *common.Error, commandToWrite *common.Command) (n int, err error)

WriteMessage write msg to writer. commandToWrite should not be nil Returns int indicating the number of bytes written, and error, if any. err == nil only if length of sent bytes = length of msg

func WriteString deprecated

func WriteString(writer io.Writer, msg string) (int, error)

Deprecated: WriteString writes msg to writer length of msg cannot exceed BufferSize Returns total bytes sent and error, if any. err == nil only if length of sent bytes = length of msg

Types

type Message

type Message struct {
	Data        []byte
	ErrorCode   uint8
	CommandCode uint8
}

func ReadMessage

func ReadMessage(reader io.Reader) (msg *Message, err error)

ReadMessage reads message from reader.

Jump to

Keyboard shortcuts

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