Top.Mail.Ru
package codec — KubFly SDK for Go

KubFly SDK for Go / codec

package codec

import "kubfly.io/sdk/codec"

Package codec is the base of the streaming parsers and generators of the formats of exchange — the kubfly-sdk-codec module of the Java SDK: XML (codec/xml), JSON, Smile and CBOR, strict, without a tree, with limits, only the standard library. Here: the limits of a document and the one failure of every parser. Strict UTF-8 is that of unicode/utf8 — no overlong forms, no surrogates, nothing above U+10FFFF — the rules of Utf8 of the Java SDK.

Variables

var DefaultLimits = Limits{Bytes: 16 << 20, Depth: 64, Text: 1 << 20, Names: 256, Items: 1_000_000}

DefaultLimits are the limits by default: 16 MiB, depth 64, texts of 1 MiB, names of 256 bytes, a million items.

Types

type Error

type Error struct {
	// Rule is what is broken, in lower case.
	Rule string
	// Offset is the offset of the byte where it is found, in bytes from the beginning of the document.
	Offset int64
}

Error is the only failure of the parsers and the generators: a document that is not of its format, or one beyond its Limits — CodecException of the Java SDK. It tells the rule and the offset in bytes, never a part of the document, which may hold secrets of a server.

func (*Error) Error

func (e *Error) Error() string

Error is the rule at the offset.

type Limits

type Limits struct {
	// Bytes is the longest document, bytes.
	Bytes int64
	// Depth is the deepest nesting of elements, arrays or objects.
	Depth int
	// Text is the longest text, value of an attribute or string, bytes of UTF-8 after the references are resolved.
	Text int
	// Names is the longest name of an element, an attribute or a key, bytes of UTF-8.
	Names int
	// Items is the most items of a document: elements, attributes and texts, or values.
	Items int64
}

Limits are the limits of a document a parser takes: beyond any of them it fails with an *Error, so a document from outside cannot take the memory or the stack of the process. The same in every SDK.

func (Limits) Valid

func (l Limits) Valid() bool

Valid tells whether every limit is positive.