×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang bytes.ErrTooLarge Variable with Examples

Golang | bytes.ErrTooLarge Variable: Here, we are going to learn about the ErrTooLarge variable of the bytes package with its usages, syntax, and examples.
Submitted by IncludeHelp, on September 21, 2021

bytes.ErrTooLarge Variable

The ErrTooLarge variable is an inbuilt variable of the bytes package which indicates that memory cannot be allocated to store data in a buffer. The value of the ErrTooLarge variable is "bytes.Buffer: too large".

Syntax

*errors.errorString bytes.ErrTooLarge

Implementation in the package source code:

var ErrTooLarge = errors.New("bytes.Buffer: too large")

Parameters

  • None

Return Value

The return type of the bytes.ErrTooLarge variable is a *errors.errorString, it returns the string "bytes.Buffer: too large ".

Example 1

// Golang program to demonstrate the
// example of bytes.ErrTooLarge Variable

package main

import (
	"bytes"
	"fmt"
)

func main() {
	fmt.Printf("Type of bytes.ErrTooLarge is %T\n",
		bytes.ErrTooLarge)
	fmt.Println("Value of bytes.ErrTooLarge:",
		bytes.ErrTooLarge)
}

Output:

Type of bytes.ErrTooLarge is *errors.errorString
Value of bytes.ErrTooLarge: bytes.Buffer: too large

Example 2

// Golang program to demonstrate the
// example of bytes.Compare() function

package main

import (
	"bytes"
	"fmt"
)

func main() {
	// Declaring byte slices
	var a = []byte{10, 20, 30, 70, 120, 255}
	var b = []byte{100, 120, 50, 70, 120, 255}
	var c = []byte{10, 20, 30, 70, 120, 255}

	// Comparing byte slices and printing results
	fmt.Println(bytes.Compare(a, b))
	fmt.Println(bytes.Compare(b, c))
	fmt.Println(bytes.Compare(a, c))
}

Output:

-1
1
0

Golang bytes Package »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.