rfc6242

package
v2.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Copyright 2018 Andrew Fort

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Index

Constants

View Source
const (
	// DecoderMinScannerBufferSize is the scanner buffer size floor.
	DecoderMinScannerBufferSize = 20
)

Variables

View Source
var (
	// ErrZeroChunks is a protocol error indicating that no chunk was
	// seen prior to the end-of-chunks token.
	ErrZeroChunks = errors.New("end-of-chunks seen prior to chunk")
	// ErrChunkSizeInvalid is a protocol error indicating that a chunk
	// frame introduction was seen, but chunk-size decoding failed.
	ErrChunkSizeInvalid = errors.New("no valid chunk-size detected")
	// ErrChunkSizeTokenTooLong is a protocol error indicating a
	// valid chunk-size token start was seen, but that the chunk-size
	// token was longer than that necessary to store the maximum
	// permitted chunk size "4294967295".
	ErrChunkSizeTokenTooLong = errors.New("token too long")
	// ErrChunkSizeTooLarge is a protocol error indicating that the
	// chunk-size decoded exceeds the limit stated in RFC6242.
	ErrChunkSizeTooLarge = errors.New("chunk size larger than maximum (4294967295)")
)

Functions

func SetChunkedFraming

func SetChunkedFraming(objects ...interface{})

SetChunkedFraming enables chunked framing mode on any non-nil *Decoder and *Encoder objects passed to it.

Types

type Decoder

type Decoder struct {
	// Input is the input source for the Decoder. The input stream
	// must consist of RFC6242 encoded data according to the current
	// Framer.
	Input io.Reader
	// contains filtered or unexported fields
}

Decoder is an RFC6242 transport framing decoder filter.

Decoder operates as an inline filter, taking a io.Reader as input and providing io.Reader.

Decoder is not safe for concurrent use.

func NewDecoder

func NewDecoder(input io.Reader, options ...DecoderOption) *Decoder

NewDecoder creates a new RFC6242 transport framing decoder reading from input, configured with any options provided.

func (*Decoder) Read

func (d *Decoder) Read(b []byte) (n int, err error)

Read reads from the Decoder's input and copies the data into b, implementing io.Reader.

type DecoderOption

type DecoderOption func(*Decoder)

DecoderOption is a constructor option function for the Decoder type.

func WithFramer

func WithFramer(f FramerFn) DecoderOption

WithFramer sets the Decoder's initial Framer.

func WithScannerBufferSize

func WithScannerBufferSize(bytes int) DecoderOption

WithScannerBufferSize configures the buffer size of the bufio.Scanner used by the decoder to scan input tokens. If bytes is smaller than the constant DecoderMinScannerBufferSize, the buffer size will be set to DecoderMinScannerBufferSize.

type Encoder

type Encoder struct {
	// Output is the underlying Writer to receive encoded output
	Output io.Writer
	// ChunkedFraming sets whether the next call to Write should use
	// chunked-message framing (true) or end-of-message framing (false)
	ChunkedFraming bool
	// MaxChunkSize is the maximum size of chunks the encoder will Encode. If
	// zero, the Encoder places no artificial ceiling on the chunk size.
	MaxChunkSize uint32
}

Encoder is a filtering writer. By default it acts as a pass through writer. If chunked mode is enabled (see SetChunkedFramingMode), input to Write calls is chunked and the RFC6242 chunked encoding output written to the underlying writer.

func NewEncoder

func NewEncoder(output io.Writer, opts ...EncoderOption) *Encoder

NewEncoder returns a new RFC6242 transport encoding writer with underlying writer output, configured with any options provided.

func (*Encoder) Close

func (e *Encoder) Close() error

Close attempts to close the underlying writer.

func (*Encoder) EndOfMessage

func (e *Encoder) EndOfMessage() error

EndOfMessage must be called after each conceptual message (or XML document) is written to the Encoder. It writes the appropriate NETCONF message ending, either "]]>]]>" or if chunked framing is enabled, "\n##\n".

func (*Encoder) Write

func (e *Encoder) Write(b []byte) (n int, err error)

Write writes the framed output for b to the underlying writer

type EncoderOption

type EncoderOption func(*Encoder)

EncoderOption is a consturctor option function for the Encoder type.

func WithMaximumChunkSize

func WithMaximumChunkSize(size uint32) EncoderOption

WithMaximumChunkSize sets an upper bound on the chunk size used when writing data to an Encoder. If 0 is passed, the upper bound reverts to the maximum chunk size permitted by RFC6242.

type FramerFn

type FramerFn func(d *Decoder, data []byte, atEOF bool) (advance int, token []byte, err error)

FramerFn is the input tokenization function used by a Decoder.

Jump to

Keyboard shortcuts

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