File: utils.go

package info (click to toggle)
golang-github-optiopay-kafka 2.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 676 kB
  • sloc: sh: 163; makefile: 2
file content (23 lines) | stat: -rw-r--r-- 443 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package proto

import (
	"fmt"
	"math"
)

const (
	maxParseBufSize = math.MaxInt32
)

func messageSizeError(size int) error {
	return fmt.Errorf("unreasonable message/block size %d (max:%d)", size, maxParseBufSize)
}

// allocParseBuf is used to allocate buffers used for parsing
func allocParseBuf(size int) ([]byte, error) {
	if size < 0 || size > maxParseBufSize {
		return nil, messageSizeError(size)
	}

	return make([]byte, size), nil
}