parser

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2023 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Copyright [2019] housepower

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.

Copyright [2019] housepower

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

This section is empty.

Variables

View Source
var (
	Layouts = []string{

		"2006-01-02T15:04:05Z07:00",
		"2006-01-02T15:04:05Z0700",
		"2006-01-02T15:04:05",

		"2006-01-02 15:04:05Z07:00",
		"2006-01-02 15:04:05Z0700",
		"2006-01-02 15:04:05",

		"Mon Jan _2 15:04:05 2006",
		"Mon Jan _2 15:04:05 MST 2006",
		"Mon Jan 02 15:04:05 -0700 2006",
		"02 Jan 06 15:04 MST",
		"02 Jan 06 15:04 -0700",
		"Monday, 02-Jan-06 15:04:05 MST",
		"Mon, 02 Jan 2006 15:04:05 MST",
		"Mon, 02 Jan 2006 15:04:05 -0700",

		"Mon Jan 02 15:04:05 MST 2006",
		"Mon 02 Jan 2006 03:04:05 PM MST",

		"Jan 02, 2006 15:04:05Z07:00",
		"Jan 02, 2006 15:04:05Z0700",
		"Jan 02, 2006 15:04:05",
		"02/Jan/2006 15:04:05 Z07:00",
		"02/Jan/2006 15:04:05 Z0700",
		"02/Jan/2006 15:04:05",

		"2006-01-02",
		"02/01/2006",
		"02/Jan/2006",
		"Jan 02, 2006",
		"Mon Jan 02, 2006",
	}
	Epoch            = time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC)
	ErrParseDateTime = errors.Newf("value doesn't contain DateTime")
)

Functions

func CsvGetFloat

func CsvGetFloat[T constraints.Float](c *CsvMetric, key string, nullable bool, max float64) (val interface{})

GetFloat returns the value as float

func CsvGetInt

func CsvGetInt[T constraints.Signed](c *CsvMetric, key string, nullable bool, min, max int64) (val interface{})

func CsvGetUint

func CsvGetUint[T constraints.Unsigned](c *CsvMetric, key string, nullable bool, max uint64) (val interface{})

func FastjsonFloatArray

func FastjsonFloatArray[T constraints.Float](a []*fastjson.Value, max float64) (arr []T)

func FastjsonGetFloat

func FastjsonGetFloat[T constraints.Float](c *FastjsonMetric, key string, nullable bool, max float64) (val interface{})

func FastjsonGetInt

func FastjsonGetInt[T constraints.Signed](c *FastjsonMetric, key string, nullable bool, min, max int64) (val interface{})

func FastjsonGetUint

func FastjsonGetUint[T constraints.Unsigned](c *FastjsonMetric, key string, nullable bool, max uint64) (val interface{})

func FastjsonIntArray

func FastjsonIntArray[T constraints.Signed](a []*fastjson.Value, min, max int64) (arr []T)

func FastjsonUintArray

func FastjsonUintArray[T constraints.Unsigned](a []*fastjson.Value, max uint64) (arr []T)

func GjsonFloatArray

func GjsonFloatArray[T constraints.Float](a []gjson.Result, max float64) (arr []T)

func GjsonGetFloat

func GjsonGetFloat[T constraints.Float](c *GjsonMetric, key string, nullable bool, max float64) (val interface{})

func GjsonGetInt

func GjsonGetInt[T constraints.Signed](c *GjsonMetric, key string, nullable bool, min, max int64) (val interface{})

func GjsonGetUint

func GjsonGetUint[T constraints.Unsigned](c *GjsonMetric, key string, nullable bool, max uint64) (val interface{})

func GjsonIntArray

func GjsonIntArray[T constraints.Signed](a []gjson.Result, min, max int64) (arr []T)

func GjsonUintArray

func GjsonUintArray[T constraints.Unsigned](a []gjson.Result, max uint64) (arr []T)

func UnixFloat

func UnixFloat(sec, unit float64) (t time.Time)

Types

type CsvMetric

type CsvMetric struct {
	// contains filtered or unexported fields
}

CsvMetic

func (*CsvMetric) GetArray

func (c *CsvMetric) GetArray(key string, typ int) (val interface{})

GetArray parse an CSV encoded array

func (*CsvMetric) GetBool

func (c *CsvMetric) GetBool(key string, nullable bool) (val interface{})

func (*CsvMetric) GetDateTime

func (c *CsvMetric) GetDateTime(key string, nullable bool) (val interface{})

func (*CsvMetric) GetDecimal

func (c *CsvMetric) GetDecimal(key string, nullable bool) (val interface{})

GetDecimal returns the value as decimal

func (*CsvMetric) GetFloat32

func (c *CsvMetric) GetFloat32(key string, nullable bool) (val interface{})

func (*CsvMetric) GetFloat64

func (c *CsvMetric) GetFloat64(key string, nullable bool) (val interface{})

func (*CsvMetric) GetIPv4 added in v0.4.0

func (c *CsvMetric) GetIPv4(key string, nullable bool) interface{}

func (*CsvMetric) GetIPv6 added in v0.4.0

func (c *CsvMetric) GetIPv6(key string, nullable bool) interface{}

func (*CsvMetric) GetInt16

func (c *CsvMetric) GetInt16(key string, nullable bool) (val interface{})

func (*CsvMetric) GetInt32

func (c *CsvMetric) GetInt32(key string, nullable bool) (val interface{})

func (*CsvMetric) GetInt64

func (c *CsvMetric) GetInt64(key string, nullable bool) (val interface{})

func (*CsvMetric) GetInt8

func (c *CsvMetric) GetInt8(key string, nullable bool) (val interface{})

func (*CsvMetric) GetNewKeys

func (c *CsvMetric) GetNewKeys(knownKeys, newKeys, warnKeys *sync.Map, white, black *regexp.Regexp, partition int, offset int64) bool

func (*CsvMetric) GetString

func (c *CsvMetric) GetString(key string, nullable bool) (val interface{})

GetString get the value as string.

func (*CsvMetric) GetUUID added in v0.2.0

func (c *CsvMetric) GetUUID(key string, nullable bool) interface{}

func (*CsvMetric) GetUint16

func (c *CsvMetric) GetUint16(key string, nullable bool) (val interface{})

func (*CsvMetric) GetUint32

func (c *CsvMetric) GetUint32(key string, nullable bool) (val interface{})

func (*CsvMetric) GetUint64

func (c *CsvMetric) GetUint64(key string, nullable bool) (val interface{})

func (*CsvMetric) GetUint8

func (c *CsvMetric) GetUint8(key string, nullable bool) (val interface{})

type CsvParser

type CsvParser struct {
	// contains filtered or unexported fields
}

CsvParser implementation to parse input from a CSV format per RFC 4180

func (*CsvParser) Parse

func (p *CsvParser) Parse(bs []byte) (metric model.Metric, err error)

Parse extract a list of comma-separated values from the data

type FastjsonMetric

type FastjsonMetric struct {
	// contains filtered or unexported fields
}

func (*FastjsonMetric) GetArray

func (c *FastjsonMetric) GetArray(key string, typ int) (val interface{})

func (*FastjsonMetric) GetBool

func (c *FastjsonMetric) GetBool(key string, nullable bool) (val interface{})

func (*FastjsonMetric) GetDateTime

func (c *FastjsonMetric) GetDateTime(key string, nullable bool) (val interface{})

func (*FastjsonMetric) GetDecimal

func (c *FastjsonMetric) GetDecimal(key string, nullable bool) (val interface{})

func (*FastjsonMetric) GetFloat32

func (c *FastjsonMetric) GetFloat32(key string, nullable bool) (val interface{})

func (*FastjsonMetric) GetFloat64

func (c *FastjsonMetric) GetFloat64(key string, nullable bool) (val interface{})

func (*FastjsonMetric) GetIPv4 added in v0.4.0

func (c *FastjsonMetric) GetIPv4(key string, nullable bool) interface{}

func (*FastjsonMetric) GetIPv6 added in v0.4.0

func (c *FastjsonMetric) GetIPv6(key string, nullable bool) interface{}

func (*FastjsonMetric) GetInt16

func (c *FastjsonMetric) GetInt16(key string, nullable bool) (val interface{})

func (*FastjsonMetric) GetInt32

func (c *FastjsonMetric) GetInt32(key string, nullable bool) (val interface{})

func (*FastjsonMetric) GetInt64

func (c *FastjsonMetric) GetInt64(key string, nullable bool) (val interface{})

func (*FastjsonMetric) GetInt8

func (c *FastjsonMetric) GetInt8(key string, nullable bool) (val interface{})

func (*FastjsonMetric) GetNewKeys

func (c *FastjsonMetric) GetNewKeys(knownKeys, newKeys, warnKeys *sync.Map, white, black *regexp.Regexp, partition int, offset int64) (foundNew bool)

func (*FastjsonMetric) GetString

func (c *FastjsonMetric) GetString(key string, nullable bool) (val interface{})

func (*FastjsonMetric) GetUUID added in v0.2.0

func (c *FastjsonMetric) GetUUID(key string, nullable bool) interface{}

func (*FastjsonMetric) GetUint16

func (c *FastjsonMetric) GetUint16(key string, nullable bool) (val interface{})

func (*FastjsonMetric) GetUint32

func (c *FastjsonMetric) GetUint32(key string, nullable bool) (val interface{})

func (*FastjsonMetric) GetUint64

func (c *FastjsonMetric) GetUint64(key string, nullable bool) (val interface{})

func (*FastjsonMetric) GetUint8

func (c *FastjsonMetric) GetUint8(key string, nullable bool) (val interface{})

type FastjsonParser

type FastjsonParser struct {
	// contains filtered or unexported fields
}

FastjsonParser, parser for get data in json format

func (*FastjsonParser) Parse

func (p *FastjsonParser) Parse(bs []byte) (metric model.Metric, err error)

type GjsonMetric

type GjsonMetric struct {
	// contains filtered or unexported fields
}

func (*GjsonMetric) GetArray

func (c *GjsonMetric) GetArray(key string, typ int) (val interface{})

func (*GjsonMetric) GetBool

func (c *GjsonMetric) GetBool(key string, nullable bool) interface{}

func (*GjsonMetric) GetDateTime

func (c *GjsonMetric) GetDateTime(key string, nullable bool) (val interface{})

func (*GjsonMetric) GetDecimal

func (c *GjsonMetric) GetDecimal(key string, nullable bool) (val interface{})

func (*GjsonMetric) GetFloat32

func (c *GjsonMetric) GetFloat32(key string, nullable bool) (val interface{})

func (*GjsonMetric) GetFloat64

func (c *GjsonMetric) GetFloat64(key string, nullable bool) (val interface{})

func (*GjsonMetric) GetIPv4 added in v0.4.0

func (c *GjsonMetric) GetIPv4(key string, nullable bool) interface{}

func (*GjsonMetric) GetIPv6 added in v0.4.0

func (c *GjsonMetric) GetIPv6(key string, nullable bool) interface{}

func (*GjsonMetric) GetInt16

func (c *GjsonMetric) GetInt16(key string, nullable bool) (val interface{})

func (*GjsonMetric) GetInt32

func (c *GjsonMetric) GetInt32(key string, nullable bool) (val interface{})

func (*GjsonMetric) GetInt64

func (c *GjsonMetric) GetInt64(key string, nullable bool) (val interface{})

func (*GjsonMetric) GetInt8

func (c *GjsonMetric) GetInt8(key string, nullable bool) (val interface{})

func (*GjsonMetric) GetNewKeys

func (c *GjsonMetric) GetNewKeys(knownKeys, newKeys, warnKeys *sync.Map, white, black *regexp.Regexp, partition int, offset int64) (foundNew bool)

func (*GjsonMetric) GetString

func (c *GjsonMetric) GetString(key string, nullable bool) interface{}

func (*GjsonMetric) GetUUID added in v0.2.0

func (c *GjsonMetric) GetUUID(key string, nullable bool) interface{}

func (*GjsonMetric) GetUint16

func (c *GjsonMetric) GetUint16(key string, nullable bool) (val interface{})

func (*GjsonMetric) GetUint32

func (c *GjsonMetric) GetUint32(key string, nullable bool) (val interface{})

func (*GjsonMetric) GetUint64

func (c *GjsonMetric) GetUint64(key string, nullable bool) (val interface{})

func (*GjsonMetric) GetUint8

func (c *GjsonMetric) GetUint8(key string, nullable bool) (val interface{})

type GjsonParser

type GjsonParser struct {
	// contains filtered or unexported fields
}

func (*GjsonParser) Parse

func (p *GjsonParser) Parse(bs []byte) (metric model.Metric, err error)

type Parser

type Parser interface {
	Parse(bs []byte) (metric model.Metric, err error)
}

Parse is the Parser interface

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool may be used for pooling Parsers for similarly typed JSONs.

func NewParserPool

func NewParserPool(
	name string,
	csvFormat []string,
	delimiter string,
	timezone string,
	timeunit float64,
	topic string,
	schemaRegistry schemaregistry.Client,
) (pp *Pool, err error)

NewParserPool creates a parser pool

func (*Pool) Get

func (pp *Pool) Get() Parser

Get returns a Parser from pp.

The Parser must be Put to pp after use.

func (*Pool) ParseDateTime

func (pp *Pool) ParseDateTime(key string, val string) (t time.Time, err error)

Assuming that all values of a field of kafka message has the same layout, and layouts of each field are unrelated. Automatically detect the layout from till the first successful detection and reuse that layout forever. Return time in UTC.

func (*Pool) Put

func (pp *Pool) Put(p Parser)

Put returns p to pp.

p and objects recursively returned from p cannot be used after p is put into pp.

type ProtoDeserializer

type ProtoDeserializer struct {
	// contains filtered or unexported fields
}

ProtoDeserializer represents a Protobuf deserializer.

func (*ProtoDeserializer) ToDynamicMessage

func (p *ProtoDeserializer) ToDynamicMessage(bytes []byte) (*dynamic.Message, error)

type ProtoMetric

type ProtoMetric struct {
	// contains filtered or unexported fields
}

func (*ProtoMetric) GetArray

func (m *ProtoMetric) GetArray(key string, t int) interface{}

func (*ProtoMetric) GetBool

func (m *ProtoMetric) GetBool(key string, nullable bool) interface{}

func (*ProtoMetric) GetDateTime

func (m *ProtoMetric) GetDateTime(key string, nullable bool) interface{}

func (*ProtoMetric) GetDecimal

func (m *ProtoMetric) GetDecimal(key string, nullable bool) interface{}

func (*ProtoMetric) GetFloat32

func (m *ProtoMetric) GetFloat32(key string, nullable bool) interface{}

func (*ProtoMetric) GetFloat64

func (m *ProtoMetric) GetFloat64(key string, nullable bool) interface{}

func (*ProtoMetric) GetIPv4 added in v0.4.0

func (m *ProtoMetric) GetIPv4(key string, nullable bool) interface{}

func (*ProtoMetric) GetIPv6 added in v0.4.0

func (m *ProtoMetric) GetIPv6(key string, nullable bool) interface{}

func (*ProtoMetric) GetInt16

func (m *ProtoMetric) GetInt16(key string, nullable bool) interface{}

func (*ProtoMetric) GetInt32

func (m *ProtoMetric) GetInt32(key string, nullable bool) interface{}

func (*ProtoMetric) GetInt64

func (m *ProtoMetric) GetInt64(key string, nullable bool) interface{}

func (*ProtoMetric) GetInt8

func (m *ProtoMetric) GetInt8(key string, nullable bool) interface{}

func (*ProtoMetric) GetNewKeys

func (m *ProtoMetric) GetNewKeys(knownKeys, newKeys, warnKeys *sync.Map, white, black *regexp.Regexp, partition int, offset int64) bool

func (*ProtoMetric) GetString

func (m *ProtoMetric) GetString(key string, nullable bool) interface{}

func (*ProtoMetric) GetUUID added in v0.2.0

func (m *ProtoMetric) GetUUID(key string, nullable bool) interface{}

func (*ProtoMetric) GetUint16

func (m *ProtoMetric) GetUint16(key string, nullable bool) interface{}

func (*ProtoMetric) GetUint32

func (m *ProtoMetric) GetUint32(key string, nullable bool) interface{}

func (*ProtoMetric) GetUint64

func (m *ProtoMetric) GetUint64(key string, nullable bool) interface{}

func (*ProtoMetric) GetUint8

func (m *ProtoMetric) GetUint8(key string, nullable bool) interface{}

type ProtoParser

type ProtoParser struct {
	// contains filtered or unexported fields
}

ProtoParser knows how to get data from proto format.

func (*ProtoParser) Parse

func (p *ProtoParser) Parse(bs []byte) (model.Metric, error)

Parse parses bytes into metric that knows how.

Jump to

Keyboard shortcuts

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