message

package
v1.8.8 Latest Latest
Warning

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

Go to latest
Published: May 18, 2024 License: BSD-3-Clause Imports: 14 Imported by: 13

Documentation

Overview

Package message contains the interfaces and registry for packet message types. The definitions in this package can be used to register package message types and to itemize the registered types.

Index

Constants

This section is empty.

Variables

View Source
var (
	PIFOCardinalNumberRE = regexp.MustCompile(`^[0-9]+$`) // changed * to +

	PIFODateRE = regexp.MustCompile(`^(?:0[1-9]|1[012])/(?:0[1-9]|1[0-9]|2[0-9]|3[01])/[1-2][0-9][0-9][0-9]$`)

	PIFOFrequencyRE       = regexp.MustCompile(`^[0-9]+(?:\.[0-9]+)?$`)
	PIFOFrequencyOffsetRE = regexp.MustCompile(`^(?:[-+]?[0-9]*\.[0-9]+|[-+]?[0-9]+|[-+])$`)

	PIFOPhoneNumberRE = regexp.MustCompile(`^[a-zA-Z ]*(?:[+][0-9]+ )?[0-9][0-9 -]*(?:[xX][0-9]+)?$`)
	PIFORealNumberRE  = regexp.MustCompile(`^(?:[-+]?[0-9]*\.[0-9]+|[-+]?[0-9]+)$`)

	PIFOTimeRE = regexp.MustCompile(`^(?:([01][0-9]|2[0-3]):?[0-5][0-9]|2400|24:00)$`)
)

Regular expressions for data type validation. The ones with PIFO* names are taken from the PackItForms code, unmodified except for JavaScript-to-Go conversion.

View Source
var (
	// DecodeSeverityMap maps severity codes, as returned by DecodeSubject,
	// into Situation Severity values.
	DecodeSeverityMap = map[string]string{"E": "EMERGENCY", "U": "URGENT", "O": "OTHER"}
	// DecodeHandlingMap maps handling codes, as returned by DecodeSubject,
	// into Handling values.
	DecodeHandlingMap = map[string]string{"I": "IMMEDIATE", "P": "PRIORITY", "R": "ROUTINE"}
)
View Source
var ErrNotSupported = errors.New("message type does not support PDF rendering, or program was not built with -tags packetpdf")

ErrNotSupported is the error returned if RenderPDF is called on a message with a type that does not support PDF rendering.

View Source
var RegisteredTypes = make(map[string]*Type)

RegisteredTypes is a map from message type tag to Type structure for all registered message types. It should be treated as read-only; to register a new type, call Register.

Functions

func ApplyCardinalNumber

func ApplyCardinalNumber(f *Field, v string)

ApplyCardinalNumber applies an edited value to a cardinal number field.

func DecodeSubject

func DecodeSubject(line string) (msgid, severity, handling, formtag, subject string)

DecodeSubject decodes an XSC-standard message subject line into its component parts. If the subject line does not follow the XSC standard, the function returns "", "", "", "", line.

func EditSkipAlways

func EditSkipAlways(*Field) bool

EditSkipAlways is a value for Field.EditSkip that causes the field to always be skipped during editing. It is only accessible for editing when requested specifically by name.

func EncodeSubject

func EncodeSubject(msgid, handling, formtag, subject string) string

EncodeSubject encodes an XSC-standard message subject line.

func OlderVersion

func OlderVersion(a, b string) bool

OlderVersion compares two version numbers, and returns true if the first one is older than the second one. Each version number is split into a sequence of dot-separated parts. Any such parts that start with a digit and contain non-digits are further split into the part with the leading digits and the remainder. The parts in the first version number are then compared one by one with the corresponding parts of the second number until a difference is found. When both parts contain only digits, they are compared numerically (e.g. 2 < 10). When both parts contain non-digits, they are compared as case-insensitive strings. When the parts are of mixed type, a part containing non-digits is "older" than the absence of a part, which is "older" than a part containing only digits.

This algorithm ensures that "undefined" is older than any numeric version, and that "3.15alpha" is older than "3.15".

func Register

func Register(mtype *Type)

Register registers a message type. The order of registration is significant for decoding messages: catch-all decoders (e.g. UnknownForm and PlainText) must be registered last.

func SmartJoin

func SmartJoin(a, b, sep string) string

SmartJoin joins the two provided strings with the provided separator, but only when both are non-empty. If one is empty, it returns the other. If both are empty, it returns an empty string.

func TableOmit

func TableOmit(*Field) string

TableOmit is a TableValue function that causes the field to be unconditionally omitted from the table rendering.

func ValidCardinalNumber

func ValidCardinalNumber(f *Field) string

ValidCardinalNumber verifies that the provided string is a valid cardinal number according to PackItForms.

Types

type BaseMessage

type BaseMessage struct {
	// Type is the type definition for the message type.
	Type *Type
	// PIFOVersion is the PIFO version found when decoding the message.  It
	// is set only for messages with PIFO encoding.
	PIFOVersion string
	// FormVersion identifies the form and version in the message.  It is
	// set only for messages with PIFO encoding.
	Form *FormVersion
	// Fields is an ordered list of fields in the message.  This is the
	// core of the shared message functionality:  most operations are
	// implemented by iterating through these fields.
	Fields []*Field

	// FOriginMsgID points to the value of the Origin Message ID field.  It
	// is nil for message types that do not have that field.
	FOriginMsgID *string
	// FDestinationMsgID points to the value of the Destination Message ID
	// field.  It is nil for message types that do not have that field.
	FDestinationMsgID *string
	// FMessageDate points to the value of the message date field.  It is
	// nil for message types that do not have that field.
	FMessageDate *string
	// FMessageTime points to the value of the message time field.  It is
	// nil for message types that do not have that field.
	FMessageTime *string
	// FHandling points to the value of the Handling field.  It
	// is nil for message types that do not have that field.
	FHandling *string
	// FSubject points to the value of the field of the message that will
	// get propagated to the message's subject line.  It is nil for message
	// types that do not have any such field.
	FSubject *string
	// RestrictedSubject is a flag indicating that the FSubject field allows
	// only certain restricted values.  (It will not be populated with the
	// subject of a message being replied to, unless that message is of the
	// same type.)
	RestrictedSubject bool
	// FToICSPosition points to the value of the To ICS Position field.  It
	// is nil for message types that do not have that field.
	FToICSPosition *string
	// FToLocation points to the value of the To Location field.  It
	// is nil for message types that do not have that field.
	FToLocation *string
	// FFromICSPosition points to the value of the From ICS Position field.
	// It is nil for message types that do not have that field.
	FFromICSPosition *string
	// FFromLocation points to the value of the From Location field.  It
	// is nil for message types that do not have that field.
	FFromLocation *string
	// FReference points to the value of the Reference field.  It is nil for
	// message types that do not have that field.
	FReference *string
	// FTacCall points to the value of the Tactical Call Sign field.  It is
	// nil for message types that do not have that field.
	FTacCall *string
	// FTacName points to the value of the Tactical Station Name field.  It
	// is nil for message types that do not have that field.
	FTacName *string
	// FOpCall points to the value of the Operator Call Sign field.  It is
	// nil for message types that do not have that field.
	FOpCall *string
	// FOpName points to the value of the Operator Name field.  It is nil
	// for message types that do not have that field.
	FOpName *string
	// FOpDate points to the value of the Operator Date field.  It is nil
	// for message types that do not have that field.
	FOpDate *string
	// FOpTime points to the value of the Operator Time field.  It is nil
	// for message types that do not have that field.
	FOpTime *string
	// FBody points to the value of the most prominent, or first, multi-line
	// text field of the message.  It is nil for message types that do not
	// have any such field.
	FBody *string
}

BaseMessage is the type underlying all packet messages, providing their shared functionality. Every message, regardless of type, embeds a BaseMessage and provides access to it through the Base() method on the message type.

func (*BaseMessage) Base

func (bm *BaseMessage) Base() *BaseMessage

Base returns the BaseMessage structure for the message.

func (*BaseMessage) Compare

func (bm *BaseMessage) Compare(actual Message) (score int, outOf int, cfields []*CompareField)

Compare compares two messages. It returns a score indicating how closely they match, and the detailed comparisons of each field in the message. The comparison is not symmetric: the receiver of the call is the "expected" message and the argument is the "actual" message.

func (*BaseMessage) Editable

func (bm *BaseMessage) Editable() bool

Editable returns whether the message type supports editing.

func (*BaseMessage) EncodeBody

func (bm *BaseMessage) EncodeBody() string

EncodeBody encodes the message body, suitable for transmission or storage.

func (*BaseMessage) EncodeSubject

func (bm *BaseMessage) EncodeSubject() string

EncodeSubject encodes the message subject line.

func (*BaseMessage) PIFOValid

func (bm *BaseMessage) PIFOValid() (problems []string)

PIFOValid checks the contents of the message for compliance with rules enforced by standard Santa Clara County packet software (Outpost and PackItForms). It returns a list of strings describing problems that those programs would flag or block.

func (*BaseMessage) RenderPDF

func (bm *BaseMessage) RenderPDF(_ *envelope.Envelope, filename string) (err error)

RenderPDF renders the message as a PDF file with the specified filename, overwriting any existing file with that name.

func (*BaseMessage) SetOperator

func (bm *BaseMessage) SetOperator(opcall, opname string, received bool)

SetOperator sets the operator only fields of the message, if it has them.

type ChoiceMapper

type ChoiceMapper interface {
	// IsHuman returns whether the supplied string is a human representation
	// of one of the choices in the set.
	IsHuman(string) bool
	// IsPIFO returns whether the supplied string is a PIFO representation
	// of one of the choices in the set.
	IsPIFO(string) bool
	// ToHuman translates the supplied choice from PIFO representation to
	// human representation.  If the supplied string is not a PIFO
	// representation of one of the choices in the set, ToHuman returns its
	// argument unchanged.
	ToHuman(string) string
	// ToPIFO translates the supplied choice from human representation to
	// PIFO representation.  If the supplied string is not a human
	// representation of one of the choices in the set, ToPIFO returns its
	// argument unchanged.
	ToPIFO(string) string
	// ListHuman returns a list of the human representations of the choices
	// in the set.
	ListHuman() []string
}

A ChoiceMapper provides a set of choices for a Field and maps between internal (PIFO) and human representations of them.

type ChoicePairs

type ChoicePairs []string

ChoicePairs is a wrapper around []string to make it a valid ChoiceMapper. Each pair of strings in the slice is a PIFO and a human representation of a choice.

func (ChoicePairs) IsHuman

func (c ChoicePairs) IsHuman(s string) bool

func (ChoicePairs) IsPIFO

func (c ChoicePairs) IsPIFO(s string) bool

func (ChoicePairs) ListHuman

func (c ChoicePairs) ListHuman() (human []string)

func (ChoicePairs) ToHuman

func (c ChoicePairs) ToHuman(s string) string

func (ChoicePairs) ToPIFO

func (c ChoicePairs) ToPIFO(s string) string

type Choices

type Choices []string

Choices is a wrapper around []string to make it a valid ChoiceMapper. Each string in the slice is a choice whose PIFO and human representations are the same.

func (Choices) IsHuman

func (c Choices) IsHuman(s string) bool

func (Choices) IsPIFO

func (c Choices) IsPIFO(s string) bool

func (Choices) ListHuman

func (c Choices) ListHuman() []string

func (Choices) ToHuman

func (c Choices) ToHuman(s string) string

func (Choices) ToPIFO

func (c Choices) ToPIFO(s string) string

type CompareField

type CompareField struct {
	// Label is the field label.
	Label string
	// Score is the comparison score for this field.  0 <= Score <= OutOf.
	Score int
	// OutOf is the maximum possible score for this field, i.e., the score
	// for this field if its contents match exactly.
	OutOf int
	// Expected is the value of this field in the expected message (i.e.,
	// the receiver of the Compare method), formatted for human viewing.
	Expected string
	// ExpectedMask is a string describing which characters of Expected are
	// different from those in Actual.  Space characters in the mask
	// correspond to characters in Expected that are properly matched by
	// Actual.  "~" characters in the mask correspond to characters in
	// Expected that have minor differences in Actual.  All other characters
	// in the mask correspond to significant differences.  If ExpectedMask
	// is shorter than Expected, the last character of ExpectedMask is
	// implicitly repeated.
	ExpectedMask string
	// Actual is the value of this field in the actual message (i.e., the
	// argument of the Compare method), formatted for human viewing.
	Actual string
	// ActualMask is a string describing which characters of Actual are
	// different from those in Expected.  Space characters in the mask
	// correspond to characters in Actual that properly match Expected.  "~"
	// characters in the mask correspond to characters in Actual that have
	// minor differences with Expected.  All other characters in the mask
	// correspond to significant differences.  If ActualMask is shorter than
	// Actual, the last character of ActualMask is implicitly repeated.
	ActualMask string
}

A CompareField structure represents a single field in the comparison of two messages as performed by the Compare method.

func CompareCardinal

func CompareCardinal(label, exp, act string) (c *CompareField)

CompareCardinal compares two values for a field that is supposed to contain a cardinal number.

func CompareCheckbox

func CompareCheckbox(label, exp, act string) (c *CompareField)

CompareCheckbox compares two values for a checkbox field.

func CompareDate

func CompareDate(label, exp, act string) (c *CompareField)

CompareDate compares two values for a date field.

func CompareExact

func CompareExact(label, exp, act string) (c *CompareField)

CompareExact compares two values for a field, which are expected to be exactly identical.

func CompareExactMap

func CompareExactMap(label, exp, act string, mapping map[string]string) (c *CompareField)

CompareExactMap compares two values for a field, which are expected to be exactly identical. It maps the values for human display.

func CompareNone

func CompareNone(string, string, string) *CompareField

CompareNone is a "comparison" function that causes the field to be omitted from the comparison.

func ComparePhoneNumber

func ComparePhoneNumber(label, exp, act string) (c *CompareField)

ComparePhoneNumber compares two values for a phone number field.

func CompareReal

func CompareReal(label, exp, act string) (c *CompareField)

CompareReal compares two values for a field that is supposed to contain a real number.

func CompareText

func CompareText(label, exp, act string) (c *CompareField)

CompareText compares two values for a textual field. Textual fields use a somewhat loose comparison, as follows:

  • If a group starts with "¡", a case-sensitive comparison is used for that group (without the "¡"). Otherwise, a group matches if the actual has the same case as the expected, is in all caps, or is in all lowercase.
  • Runs of spaces are treated as a single whitespace for comparison.
  • Newlines in expected that are preceded by "¡" must be matched by newlines in actual (without the "¡").
  • Runs of more than one newline in expected must be matched by runs of more than one newline in actual, but not necessarily the same length runs.
  • Any other runs of whitespace in expected can be matched by any run of whitespace in actual that contains at most one newline.

func CompareTime

func CompareTime(label, exp, act string) (c *CompareField)

CompareTime compares two values for a time field.

type Field

type Field struct {
	// Label is the name of the field, as it is displayed to the user.  It
	// should be short, definitely no more than 40 characters.
	Label string
	// Value is a pointer to where the value of the field is stored.  Not
	// all fields have a stored value, so this pointer may be nil.
	Value *string
	// Choices is a set of recommended or allowed values for the field.
	// (Whether other values are allowed is up to the validation functions.)
	Choices ChoiceMapper
	// Presence is a function that returns whether the field is allowed or
	// required.  The function may optionally return a reason, which is
	// interpolated into validation problem strings when needed.
	Presence func() (Presence, string)
	// PIFOTag is the tag for this field in a PackItForms encoding.  If this
	// is empty, the field will not be rendered in PackItForms encoding nor
	// populated from PackItForms decoding.
	PIFOTag string
	// PIFOValid checks the value of the field against the restrictions
	// enforced by the PackItForms software.  It returns a problem
	// description if the value is one that PackItForms would reject, and an
	// empty string otherwise.
	PIFOValid func(*Field) string
	// Compare compares an expected value of this field against an actual
	// value of this field, and returns a description of the comparison.  To
	// disable comparison for a field, set this to CompareNone.
	Compare func(label, exp, act string) *CompareField
	// PDFMap is the mapper that tells how to render this field into a
	// form-fillable PDF file.
	PDFMap PDFMapper
	// TableValue returns the value of this field when rendered in flat text
	// table form.  To omit a field from the table rendering, set this to
	// TableOmit.
	TableValue func(*Field) string
	// EditWidth is the width in characters of the input control for this
	// field.  It should correspond to the number of characters that will
	// fit in the PDF rendering of the field, if applicable.
	EditWidth int
	// Multiline indicates that this field can contain multiple lines, i.e.,
	// can contain newline characters.
	Multiline bool
	// EditHelp is the help text for the form field, describing its contents
	// and its validity rules.  If this is empty, the field is not editable.
	EditHelp string
	// EditHint is a short string giving a model for the field value (e.g.,
	// "MM/DD/YYYY" for a date field).  It is optional, and will only be
	// displayed if there is room for it.
	EditHint string
	// EditValue returns the editable representation of the value of the
	// field.
	EditValue func(*Field) string
	// EditApply stores the supplied edited value into the field, revising
	// it if need be to convert from human to internal (PIFO) form.
	EditApply func(*Field, string)
	// EditValid checks the value of the field and returns a problem
	// description, or an empty string if there are no problems.
	EditValid func(*Field) string
	// EditSkip returns whether the field should be skipped while editing
	// the message (e.g., no entry in this field is valid because of the
	// value of some earlier field).  This can be set to EditSkipAlways for
	// a field that should be editable only when addressed by name.
	EditSkip func(*Field) bool
	// HideValue indicates that the value of the field should be hidden.
	// This is used for password fields.
	HideValue bool
}

A Field describes a single field within a message. Generally, a message type has one Field for each field in the PackItForms encoding of the message, plus occasionally other Fields for special purposes (e.g. aggregating the underlying fields for display or editing).

func AddFieldDefaults

func AddFieldDefaults(f *Field) *Field

AddFieldDefaults adds defaults to a Field. It replaces nil functions with default implementations.

func NewAddressListField

func NewAddressListField(f *Field) *Field

NewAddressListField adds defaults to a Field that are appropriate for a field that contains a list of packet or email addresses. It modifies its argument and returns it for chaining.

func NewAggregatorField

func NewAggregatorField(f *Field) *Field

NewAggregatorField adds defaults to a Field that are appropriate for a pseudo-field that displays and/or edits the contents of multiple other fields as a unit. It modifies its argument and returns it for chaining.

func NewCalculatedField

func NewCalculatedField(f *Field) *Field

NewCalculatedField adds defaults to a Field that are appropriate for a field whose value is calculated from other fields, and is not displayed or edited directly. It modifies its argument and returns it for chaining.

func NewCardinalNumberField

func NewCardinalNumberField(f *Field) *Field

NewCardinalNumberField adds defaults to a Field that are appropriate for a field that contains a non-negative integer. It modifies its argument and returns it for chaining.

func NewDateField

func NewDateField(paired bool, f *Field) *Field

NewDateField adds defaults to a Field that are appropriate for a field that contains an MM/DD/YYYY date. If paired is true, it means this field is part of a date/time field pair with a DateTimeField aggregator. It modifies its argument and returns it for chaining.

func NewDateTimeField

func NewDateTimeField(f *Field, date, tval *string) *Field

NewDateTimeField adds defaults to a Field that are appropriate for a pseudo-field that displays and edits a pair of DateWithTime and TimeWithDate fields together. These fields must always come as a triplet: a DateWithTime field, a TimeWithDate field, and a DateTime field that refers to the first two. NewDateTimeField modifies its argument and returns it for chaining.

func NewFCCCallSignField

func NewFCCCallSignField(f *Field) *Field

NewFCCCallSignField adds defaults to a Field that are appropriate for a field that contains an FCC call sign. It modifies its argument and returns it for chaining.

func NewFrequencyField

func NewFrequencyField(f *Field) *Field

NewFrequencyField adds defaults to a Field that are appropriate for a field that contains a frequency in MHz. It modifies its argument and returns it for chaining.

func NewFrequencyOffsetField

func NewFrequencyOffsetField(f *Field) *Field

NewFrequencyOffsetField adds defaults to a Field that are appropriate for a field that contains a repeater frequency offset. It modifies its argument and returns it for chaining.

func NewMessageNumberField

func NewMessageNumberField(f *Field) *Field

NewMessageNumberField adds defaults to a Field that are appropriate for a field that contains a packet message number. It modifies its argument and returns it for chaining.

func NewMultilineField

func NewMultilineField(f *Field) *Field

NewMultilineField adds defaults to a Field that are appropriate for a field containing free-form text with possible newlines. It modifies its argument and returns it for chaining.

func NewPhoneNumberField

func NewPhoneNumberField(f *Field) *Field

NewPhoneNumberField adds defaults to a Field that are appropriate for a field that contains a phone number. It modifies its argument and returns it for chaining.

func NewRealNumberField

func NewRealNumberField(f *Field) *Field

NewRealNumberField adds defaults to a Field that are appropriate for a field that contains a real number. It modifies its argument and returns it for chaining.

func NewRestrictedField

func NewRestrictedField(f *Field) *Field

NewRestrictedField adds defaults to a Field that are appropriate for a field that can contain only a restricted set of values. It modifies its argument and returns it for chaining.

func NewStaticPDFContentField

func NewStaticPDFContentField(f *Field) *Field

NewStaticPDFContentField adds defaults to a Field that are appropriate for a pseudo-field that renders static content in a generated PDF. It modifies its argument and returns it for chaining.

func NewTacticalCallSignField

func NewTacticalCallSignField(f *Field) *Field

NewTacticalCallSignField adds defaults to a Field that are appropriate for a field that contains a tactical call sign. It modifies its argument and returns it for chaining.

func NewTextField

func NewTextField(f *Field) *Field

NewTextField adds defaults to a Field that are appropriate for a field containing free-form text, not expected to contain newlines. It modifies its argument and returns it for chaining.

func NewTimeField

func NewTimeField(paired bool, f *Field) *Field

NewTimeField adds defaults to a Field that are appropriate for a field that contains an HH:MM time. If paired is true, the field is part of a date/time field pair with a DateTimeField aggregator. It modifies its argument and returns it for chaining.

func (*Field) PresenceValid

func (f *Field) PresenceValid() string

PresenceValid returns a problem string if the field's value is incompatible with its presence requirement (i.e., empty when a value is required, or non-empty when a value is not allowed). It returns an empty string otherwise.

type FormVersion

type FormVersion struct {
	// HTML is the HTML filename that identifies the type of form.
	HTML string
	// Version is the version number of the form.
	Version string
	// Tag is the tag for the form type, which goes in the subject line.
	Tag string
	// FieldOrder is an ordered list of field tags.  When provided,
	// generated forms list the fields in that order.  (Should any fields be
	// omitted from the list, they are put at the start of the form, before
	// those in the list.)
	FieldOrder []string
}

A FormVersion identifies a version of a PackItForms form.

type Message

type Message interface {
	// Base returns the BaseMessage embedded in the message.
	Base() *BaseMessage
	// EncodeSubject encodes the message subject line.
	EncodeSubject() string
	// EncodeBody encodes the message body, suitable for transmission or
	// storage.
	EncodeBody() string
	// Validate checks the contents of the message for compliance with rules
	// enforced by standard Santa Clara County packet software (Outpost and
	// PackItForms).  It returns a list of strings describing problems that
	// those programs would flag or block.
	PIFOValid() (problems []string)
	// Compare compares two messages.  It returns a score indicating how
	// closely they match, and the detailed comparisons of each field in the
	// message.  The comparison is not symmetric:  the receiver of the call
	// is the "expected" message and the argument is the "actual" message.
	Compare(actual Message) (score, outOf int, fields []*CompareField)
	// RenderPDF renders the message as a PDF file with the specified
	// filename, overwriting any existing file with that name.  This method
	// will return ErrNotSupported for message types that do not support PDF
	// rendering.  Note that the program needs to be built with "-tags
	// packetpdf" in order for any message types to support PDF rendering.
	RenderPDF(env *envelope.Envelope, filename string) error
	// SetOperator sets the operator only fields of the message, if it has
	// them.
	SetOperator(opcall, opname string, received bool)
	// Editable returns whether the message type supports editing.
	Editable() bool
}

Message is the interface that all message types implement. In addition to implementing this interface, all message types must embed BaseMessage, which provides shared functionality.

func Create

func Create(tag string) Message

Create creates a new, outgoing message with the specified type tag. It returns nil if the type tag is not registered. All message fields have default values for an outgoing message.

func Decode

func Decode(subject string, body string) (msg Message)

Decode decodes the supplied message and returns the typed, decoded message. It returns nil if no registered type can decode the message. (Between them, he UnknownForm and PlainText message types can decode any message, so if they are registered, a nil return is not possible.)

func DecodeForm

func DecodeForm(body string, versions []*FormVersion, create func(*FormVersion) Message) (msg Message)

DecodeForm decodes the message. It returns whether the message was recognized and decoded.

type NoChoices

type NoChoices struct{}

NoChoices is a zero implementation of ChoiceMapper for fields that don't have choices.

func (NoChoices) IsHuman

func (NoChoices) IsHuman(s string) bool

func (NoChoices) IsPIFO

func (NoChoices) IsPIFO(s string) bool

func (NoChoices) ListHuman

func (NoChoices) ListHuman() []string

func (NoChoices) ToHuman

func (NoChoices) ToHuman(s string) string

func (NoChoices) ToPIFO

func (NoChoices) ToPIFO(s string) string

type NoPDFField

type NoPDFField struct{}

NoPDFField is a zero implementation of PDFMapper that returns no mappings.

func (NoPDFField) RenderPDF

func (NoPDFField) RenderPDF(*Field) []PDFField

type PDFField

type PDFField struct {
	// Name is the name of the field in the PDF.
	Name string
	// Value is the value to be placed in the PDF field.
	Value string
	// Size is the font size to be used for the PDF field; it can be zero
	// if supplied by the PDF template or the Type.PDFSize value.
	Size float64
}

PDFField describes the rendering of a single PDF field, as returned by the PDFMap interface in a Field structure.

type PDFMapFunc

type PDFMapFunc func(*Field) []PDFField

PDFMapFunc converts a PDF mapping function into an interface that satisfies PDFMapper.

func (PDFMapFunc) RenderPDF

func (fn PDFMapFunc) RenderPDF(f *Field) []PDFField

type PDFMapper

type PDFMapper interface {
	RenderPDF(*Field) []PDFField
}

PDFMapper is the interface honored by a Field.PDFMap value.

type PDFName

type PDFName string

PDFName is a simple implementation of PDFMapper. It maps the field value, unedited, to the specified PDF field name, with the default font size.

func (PDFName) RenderPDF

func (n PDFName) RenderPDF(f *Field) []PDFField

type PDFNameMap

type PDFNameMap []string

PDFNameMap is an implementation of PDFMapper. The first element of the slice is the PDF field name. The remaining elements are (PIFO value, PDF value) pairs. If the current value of the field matches any of the PIFO values in the slice, it is mapped to the corresponding PDF value. Otherwise it is rendered unchanged. All values are rendered with the default font size.

func (PDFNameMap) RenderPDF

func (m PDFNameMap) RenderPDF(f *Field) []PDFField

type PIFOEncoder

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

PIFOEncoder is a PackItForms form encoder.

func NewPIFOEncoder

func NewPIFOEncoder(w io.Writer, html, version string) *PIFOEncoder

NewPIFOEncoder creates a new PackItForms encoder that writes form data to the supplied output stream. html is the form HTML filename, which identifies the form type. version is the form version number.

func (*PIFOEncoder) Close

func (e *PIFOEncoder) Close() error

Close closes the form encoding. It returns any error that occurred at any point in the form encoding process. It does not close the underlying output stream.

func (*PIFOEncoder) Write

func (e *PIFOEncoder) Write(tag, value string)

Write writes a single tag/value pair to the form.

type PIFOForm

type PIFOForm struct {
	TextBefore   string
	HTMLIdent    string
	PIFOVersion  string
	FormVersion  string
	TaggedValues map[string]string
	TextAfter    string
}

PIFOForm is a decoded PackItForms form.

func DecodePIFO

func DecodePIFO(body string) (f *PIFOForm)

DecodePIFO decodes a message body and returns the decoded form contents. If the body does not contain a valid encoded form, Decode returns nil.

type Presence

type Presence uint8

Presence is a enumeration indicating whether a field is allowed or required.

const (
	// PresenceNotAllowed means a value for this field is not allowed.
	// (This is generally because some parent field is not set, or some
	// conflicting field is set.)
	PresenceNotAllowed Presence = iota
	// PresenceOptional means a value for this field is allowed but not
	// required.
	PresenceOptional
	// PresenceRequired means a value for this field is required.
	PresenceRequired
)

Values for Presence:

func NotAllowed

func NotAllowed() (Presence, string)

func Optional

func Optional() (Presence, string)

func Required

func Required() (Presence, string)

type Type

type Type struct {
	// Tag is the tag string that identifies the message type.
	Tag string
	// Name is the English name of the message type, in prose case.
	Name string
	// Article is the indefinite article to use before the Name when needed;
	// it is always either "a" or "an".
	Article string
	// PDFBase is the form-fillable PDF file whose fields will be filled in
	// to create a PDF rendering of the message.  It is nil if PDF rendering
	// is not supported.
	PDFBase []byte
	// PDFFontSize is default font size for the fillable fields in the PDF
	// file.  It can be zero if all of the fields already have assigned
	// sizes in the PDF file.
	PDFFontSize float64
	// Create is a function for creating a new message of the type.  If
	// Create is nil, end users are not allowed to create new messages of
	// the type.  Otherwise, create must be a function with the signature
	// func() «Message», where «Message» is any type that implements the
	// Message interface.  The new message will have default values in all
	// fields.
	Create any
	// Decode is a function for decoding messages of the type.  If the input
	// message conforms to the type, Decode will return the decoded message;
	// otherwise, it will return nil.  The function must have the signature
	// func(subject string, body string) «Message», where «Message» is any
	// type that implements the Message interface.
	Decode any
}

Type gives the details of a registered message type.

Jump to

Keyboard shortcuts

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