Standard library / encoding/binary
encoding/binary.Size()
Returns the encoded size of a fixed-size value or -1 for unsupported values. Expected stdout: '6 -1\n'.
Formal Syntax & Structure
go syntaxgo
func Size(v any) intParameters & Attributes
| Name | Type | Description |
|---|---|---|
| v | any | Value to encode or pointer to the destination for decoding. |
Return Value
int
Number of bytes or required size, as described above.
Working Example
Example Snippetgo
package main
import ( "encoding/binary" "fmt")
func must(e error) { if e != nil { panic(e) }}
func main() { fmt.Println(binary.Size([3]uint16{}), binary.Size("Go")) }