wrappers

package
v1.0.1-0...-6d317da Latest Latest
Warning

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

Go to latest
Published: May 15, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrYearOutsideOfRange = errors.New("Wrappers.Time.MarshalText: year outside of range [0,9999]")

ErrYearOutsideOfRange is the error returned when the year is outside 0 and 9999

Functions

func WithKDBX4Formatting

func WithKDBX4Formatting(t *TimeWrapper)

Types

type BoolWrapper

type BoolWrapper struct {
	Bool bool
}

BoolWrapper is a bool wrapper that provides xml marshaling and unmarshaling

func NewBoolWrapper

func NewBoolWrapper(value bool) BoolWrapper

NewBoolWrapper initializes a wrapper type around a bool value which holds the given value

func (*BoolWrapper) MarshalXML

func (b *BoolWrapper) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the boolean into e

func (*BoolWrapper) MarshalXMLAttr

func (b *BoolWrapper) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

MarshalXMLAttr returns the encoded XML attribute

func (*BoolWrapper) UnmarshalXML

func (b *BoolWrapper) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the boolean from d

func (*BoolWrapper) UnmarshalXMLAttr

func (b *BoolWrapper) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr decodes a single XML attribute

type NullableBoolWrapper

type NullableBoolWrapper struct {
	Bool  bool
	Valid bool
}

NullableBoolWrapper is a bool wrapper that provides xml un-/marshalling and additionally allows "null" as value.

func NewNullableBoolWrapper

func NewNullableBoolWrapper(value bool) NullableBoolWrapper

NewNullableBoolWrapper initializes a new NewNullableBoolWrapper with the given value and valid `true`.

func (*NullableBoolWrapper) MarshalXML

func (b *NullableBoolWrapper) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML marshals the boolean into e

func (*NullableBoolWrapper) MarshalXMLAttr

func (b *NullableBoolWrapper) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

MarshalXMLAttr returns the encoded XML attribute

func (*NullableBoolWrapper) UnmarshalXML

func (b *NullableBoolWrapper) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML unmarshals the boolean from d

func (*NullableBoolWrapper) UnmarshalXMLAttr

func (b *NullableBoolWrapper) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr decodes a single XML attribute

type TimeOption

type TimeOption func(*TimeWrapper)

func WithFormatted

func WithFormatted(formatted bool) TimeOption

type TimeWrapper

type TimeWrapper struct {
	Formatted bool      // True for Kdbx v3.1 (formatted as RFC3339)
	Time      time.Time // Time value
}

TimeWrapper is a time.Time wrapper that provides xml marshaling and unmarshaling

func Now

func Now(options ...TimeOption) TimeWrapper

Now returns a TimeWrapper instance with the current time in UTC

func (TimeWrapper) MarshalText

func (tw TimeWrapper) MarshalText() ([]byte, error)

MarshalText marshals time into an RFC3339 compliant value in UTC (Kdbx v3.1) On Kdbx v4 it calculates the timestamp subtracting seconds from the time date and encode it with base64

func (TimeWrapper) String

func (tw TimeWrapper) String() string

func (*TimeWrapper) UnmarshalText

func (tw *TimeWrapper) UnmarshalText(data []byte) error

UnmarshalText take a string of format time.RFC3339 and marshals it into the TimeWrapper value (Kdbx v3.1) On Kdbx v4 it calculates the time with given seconds via data byte array (base64 encoded)

Jump to

Keyboard shortcuts

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