Documentation
¶
Overview ¶
Package cotlib implements the Cursor on Target (CoT) protocol for Go.
The package provides data structures and utilities for parsing and generating CoT messages, as well as a comprehensive type catalog system for working with CoT type codes.
Type Catalog ¶
The type catalog system provides a way to work with CoT type codes and their metadata. Each type code (e.g., "a-f-G-E-X-N") has associated metadata:
- Full Name: A hierarchical name (e.g., "Gnd/Equip/Nbc Equipment")
- Description: A human-readable description (e.g., "NBC EQUIPMENT")
The catalog supports several operations:
- Looking up metadata for a specific type code
- Searching for types by description or full name
- Validating type codes
- Registering custom type codes
Example usage:
// Look up type metadata
fullName, err := cotlib.GetTypeFullName("a-f-G-E-X-N")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Full name: %s\n", fullName)
// Search for types
types := cotlib.FindTypesByDescription("NBC")
for _, t := range types {
fmt.Printf("Found type: %s (%s)\n", t.Name, t.Description)
}
Thread Safety ¶
All operations on the type catalog are thread-safe. The catalog uses internal synchronization to ensure safe concurrent access.
Custom Types ¶
Applications can register custom type codes using RegisterCoTType. These custom types must follow the standard CoT type format and will be validated before registration.
For more information about CoT types and their format, see: https://www.mitre.org/sites/default/files/pdf/09_4937.pdf
Security features include:
- XML parsing restrictions to prevent XXE attacks
- Input validation on all fields
- Strict coordinate range enforcement
- Time field validation to prevent time-based attacks
- Secure logging practices
- Detail extension isolation
For more information about CoT, see:
- https://apps.dtic.mil/sti/citations/ADA637348 (Developer Guide)
- https://www.mitre.org/sites/default/files/pdf/09_4937.pdf (Message Router Guide)
- http://cot.mitre.org
The package follows these design principles:
- High cohesion: focused on CoT event parsing and serialization
- Low coupling: separated concerns for expansions and transport
- Composition over inheritance: nested sub-structures for detail fields
- Full schema coverage: implements Event.xsd with example extensions
- Secure by design: validates inputs and prevents common attacks
Example (RoundTripStrokeColorUsericon) ¶
package main
import (
"bytes"
"context"
"fmt"
"github.com/NERVsystems/cotlib"
)
func main() {
evt, _ := cotlib.NewEvent("EX-UI", "a-f-G", 0, 0, 0)
evt.StrokeColor = "ff0000ff"
evt.UserIcon = "icon.png"
xmlData, _ := evt.ToXML()
cotlib.ReleaseEvent(evt)
out, _ := cotlib.UnmarshalXMLEvent(context.Background(), xmlData)
fmt.Printf("strokeColor: %s\n", out.StrokeColor)
fmt.Printf("usericon: %s\n", out.UserIcon)
outXML, _ := out.ToXML()
fmt.Printf("round-trip equal: %v\n", bytes.Equal(xmlData, outXML))
cotlib.ReleaseEvent(out)
}
Output: strokeColor: ff0000ff usericon: icon.png round-trip equal: true
Example (TypePredicates) ¶
Example_typePredicates demonstrates using type predicates
package main
import (
"fmt"
"github.com/NERVsystems/cotlib"
)
func main() {
// Create some example events
events := []*cotlib.Event{
{Type: "a-f-G-U-C"}, // Friendly ground combat unit
{Type: "a-h-A-M-F"}, // Hostile fixed wing aircraft
{Type: "b-d-c-n-r"}, // NBC radiation detection
{Type: "t-s-i-e"}, // ISR EO tasking
}
// Test various predicates
predicates := []string{"atom", "friend", "hostile", "ground", "air"}
for _, evt := range events {
fmt.Printf("\nEvent type: %s\n", evt.Type)
for _, pred := range predicates {
if evt.Is(pred) {
fmt.Printf(" Matches predicate: %s\n", pred)
}
}
}
}
Output: Event type: a-f-G-U-C Matches predicate: atom Matches predicate: friend Matches predicate: ground Event type: a-h-A-M-F Matches predicate: atom Matches predicate: hostile Matches predicate: air Event type: b-d-c-n-r Matches predicate: atom Event type: t-s-i-e Matches predicate: atom
Index ¶
- Constants
- Variables
- func FindTypes(query string) []cottypes.Type
- func FindTypesByDescription(desc string) []cottypes.Type
- func FindTypesByFullName(name string) []cottypes.Type
- func GetHowDescriptor(how string) (string, error)
- func GetRelationDescription(relation string) (string, error)
- func GetTypeDescription(name string) (string, error)
- func GetTypeFullName(name string) (string, error)
- func GetTypeInfo(name string) (cottypes.Type, error)
- func GetTypeInfoBatch(names []string) ([]cottypes.Type, error)
- func LoadCoTTypesFromFile(ctx context.Context, path string) error
- func LoggerFromContext(ctx context.Context) *slog.Logger
- func LookupType(name string) (cottypes.Type, bool)
- func RegisterAllCoTTypes() error
- func RegisterCoTType(name string)
- func RegisterCoTTypesFromFile(ctx context.Context, filename string) error
- func RegisterCoTTypesFromReader(ctx context.Context, r io.Reader) error
- func RegisterCoTTypesFromXMLContent(ctx context.Context, xmlContent string) error
- func ReleaseEvent(e *Event)
- func SetEventHowFromDescriptor(event *Event, descriptor string) error
- func SetLogger(l *slog.Logger)
- func SetMaxElementCount(max int64)
- func SetMaxElementDepth(max int64)
- func SetMaxTokenLen(max int64)
- func SetMaxValueLen(max int64)
- func SetMaxXMLSize(max int64)
- func ValidateAgainstSchema(data []byte) error
- func ValidateHow(how string) error
- func ValidateLatLon(lat, lon float64) error
- func ValidateRelation(relation string) error
- func ValidateType(typ string) error
- func ValidateUID(uid string) error
- func WithLogger(ctx context.Context, l *slog.Logger) context.Context
- type Archive
- type AttachmentList
- type Bullseye
- type Chat
- type ChatGrp
- type ChatReceipt
- type CoTTime
- func (t CoTTime) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (t CoTTime) MarshalXMLAttr(name xml.Name) (xml.Attr, error)
- func (t CoTTime) Time() time.Time
- func (t *CoTTime) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
- func (t *CoTTime) UnmarshalXMLAttr(attr xml.Attr) error
- type ColorExtension
- type Contact
- type Detail
- type DetailLink
- type Emergency
- type Environment
- type Event
- func (e *Event) AddLink(link *Link)
- func (e *Event) AddValidatedLink(uid, linkType, relation string) error
- func (e *Event) InjectIdentity(selfUid, groupName, groupRole string)
- func (e *Event) Is(pred string) bool
- func (e *Event) ToXML() ([]byte, error)
- func (e *Event) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error
- func (e *Event) Validate() error
- func (e *Event) ValidateAt(now time.Time) error
- type EventBuilder
- type FileShare
- type FillColor
- type Geofence
- type Group
- type GroupExtension
- type Height
- type HeightUnit
- type Hierarchy
- type LabelsOn
- type Link
- type Marti
- type MartiDest
- type Mission
- type Point
- type PrecisionLocation
- type RawMessage
- type Remarks
- type RouteInfo
- type ServerDestination
- type Shape
- type Status
- type StrokeColor
- type StrokeWeight
- type Takv
- type Track
- type UID
- type UserIcon
- type Video
Examples ¶
Constants ¶
const ( // CotTimeFormat is the standard time format for CoT messages (Zulu time, no offset) // Format: "2006-01-02T15:04:05Z" (UTC without timezone offset) CotTimeFormat = "2006-01-02T15:04:05Z" )
Security limits for XML parsing and validation
Variables ¶
var ( ErrInvalidInput = fmt.Errorf("invalid input") ErrInvalidLatitude = fmt.Errorf("invalid latitude") ErrInvalidLongitude = fmt.Errorf("invalid longitude") ErrInvalidUID = fmt.Errorf("invalid UID") // ErrInvalidType is returned when a CoT type fails validation. ErrInvalidType = fmt.Errorf("invalid type") // ErrInvalidHow is returned when a how value is not recognised. ErrInvalidHow = fmt.Errorf("invalid how") // ErrInvalidRelation is returned when a relation value is not recognised. ErrInvalidRelation = fmt.Errorf("invalid relation") )
Error sentinels for validation
Functions ¶
func FindTypesByDescription ¶
FindTypesByDescription searches for types matching the given description. The search is case-insensitive and matches partial descriptions.
For example:
- "NBC" finds all types containing "NBC" in their description
- "EQUIPMENT" finds all equipment-related types
- "COMBAT" finds all combat-related types
This is useful for building search interfaces and type discovery tools. Returns an empty slice if no matches are found.
Example ¶
package main
import (
"fmt"
"sort"
"github.com/NERVsystems/cotlib"
)
func main() {
types := cotlib.FindTypesByDescription("NBC EQUIPMENT")
// Sort by name for consistent output
sort.Slice(types, func(i, j int) bool {
return types[i].Name < types[j].Name
})
for _, t := range types {
fmt.Printf("Found type: %s (%s)\n", t.Name, t.Description)
}
}
Output: Found type: a-f-G-E-X-N (NBC EQUIPMENT) Found type: a-h-G-E-X-N (NBC EQUIPMENT) Found type: a-n-G-E-X-N (NBC EQUIPMENT) Found type: a-u-G-E-X-N (NBC EQUIPMENT)
func FindTypesByFullName ¶
FindTypesByFullName searches for types matching the given full name. The search is case-insensitive and matches partial names.
For example:
- "Nbc Equipment" finds all NBC equipment types
- "Ground" finds all ground-based types
- "Vehicle" finds all vehicle types
This is useful for finding types based on their hierarchical classification. Returns an empty slice if no matches are found.
Example ¶
package main
import (
"fmt"
"sort"
"github.com/NERVsystems/cotlib"
)
func main() {
types := cotlib.FindTypesByFullName("Gnd/Equip/Nbc Equipment")
// Sort by name for consistent output
sort.Slice(types, func(i, j int) bool {
return types[i].Name < types[j].Name
})
for _, t := range types {
fmt.Printf("Found type: %s (%s)\n", t.Name, t.FullName)
}
}
Output: Found type: a-f-G-E-X-N (Gnd/Equip/Nbc Equipment) Found type: a-h-G-E-X-N (Gnd/Equip/Nbc Equipment) Found type: a-n-G-E-X-N (Gnd/Equip/Nbc Equipment) Found type: a-u-G-E-X-N (Gnd/Equip/Nbc Equipment)
func GetHowDescriptor ¶ added in v0.2.7
GetHowDescriptor returns a human-readable description of the how value. For example: "h-g-i-g-o" returns "gps".
func GetRelationDescription ¶ added in v0.2.7
GetRelationDescription returns a human-readable description of the relation value. For example: "p-p" returns "parent-point".
func GetTypeDescription ¶
GetTypeDescription returns the human-readable description for a CoT type. For example, "a-f-G-E-X-N" returns "NBC EQUIPMENT".
The description is a concise explanation of what the type represents, suitable for display in user interfaces and logs.
Returns an error if the type is not registered in the catalog.
Example ¶
package main
import (
"fmt"
"github.com/NERVsystems/cotlib"
)
func main() {
desc, err := cotlib.GetTypeDescription("a-f-G-E-X-N")
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Printf("Description: %s\n", desc)
}
Output: Description: NBC EQUIPMENT
func GetTypeFullName ¶
GetTypeFullName returns the full hierarchical name for a CoT type. For example, "a-f-G-E-X-N" returns "Gnd/Equip/Nbc Equipment".
The full name represents the type's position in the CoT type hierarchy, making it useful for building user interfaces and documentation.
Returns an error if the type is not registered in the catalog.
Example ¶
package main
import (
"fmt"
"github.com/NERVsystems/cotlib"
)
func main() {
fullName, err := cotlib.GetTypeFullName("a-f-G-E-X-N")
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Printf("Full name: %s\n", fullName)
}
Output: Full name: Gnd/Equip/Nbc Equipment
func GetTypeInfo ¶ added in v0.3.7
GetTypeInfo returns the metadata for a CoT type. It includes the type code, full hierarchical name, and description.
Returns an error if the type is not registered in the catalog.
func GetTypeInfoBatch ¶ added in v0.3.7
GetTypeInfoBatch returns metadata for all provided type names. If any lookup fails, the function returns an error.
func LoadCoTTypesFromFile ¶
LoadCoTTypesFromFile loads CoT types from a file
func LoggerFromContext ¶ added in v0.2.7
LoggerFromContext retrieves the logger from context or returns slog.Default.
func LookupType ¶
LookupType returns the Type for the given name if it exists LookupType returns the Type for the given name if it exists. If the exact type is not found, the function attempts wildcard resolution by substituting affiliation segments (f/h/n/u) with '.' and retrying the lookup. This mirrors ValidateType's wildcard handling to ensure lookups succeed for types that only exist in their wildcard form in the catalog.
func RegisterAllCoTTypes ¶
func RegisterAllCoTTypes() error
RegisterAllCoTTypes is a no-op since XML is already embedded
func RegisterCoTType ¶
func RegisterCoTType(name string)
RegisterCoTType adds a specific CoT type to the valid types registry It does not log individual type registrations to avoid log spam
func RegisterCoTTypesFromFile ¶
RegisterCoTTypesFromFile loads and registers CoT types from an XML file
func RegisterCoTTypesFromReader ¶
RegisterCoTTypesFromReader loads and registers CoT types from an XML reader
func RegisterCoTTypesFromXMLContent ¶
RegisterCoTTypesFromXMLContent registers CoT types from the given XML content string This is particularly useful for embedding the CoTtypes.xml content directly in code
func ReleaseEvent ¶ added in v0.2.6
func ReleaseEvent(e *Event)
ReleaseEvent returns an Event to the internal pool after resetting all fields.
The provided pointer should no longer be used after calling this function.
func SetEventHowFromDescriptor ¶ added in v0.2.7
SetEventHowFromDescriptor sets the how field on an event using a descriptor. For example: SetEventHowFromDescriptor(event, "gps") sets how to "h-g-i-g-o". It returns an error if event is nil or the descriptor is invalid.
func SetMaxElementCount ¶ added in v0.2.7
func SetMaxElementCount(max int64)
SetMaxElementCount sets the maximum allowed number of XML elements
func SetMaxElementDepth ¶ added in v0.2.7
func SetMaxElementDepth(max int64)
SetMaxElementDepth sets the maximum depth of XML elements
func SetMaxTokenLen ¶ added in v0.2.7
func SetMaxTokenLen(max int64)
SetMaxTokenLen sets the maximum length for any single XML token
func SetMaxValueLen ¶
func SetMaxValueLen(max int64)
SetMaxValueLen sets the maximum allowed length for XML attribute values and character data This is used to prevent memory exhaustion attacks via large XML payloads
func SetMaxXMLSize ¶ added in v0.2.7
func SetMaxXMLSize(max int64)
SetMaxXMLSize sets the maximum allowed size for XML input
func ValidateAgainstSchema ¶ added in v0.3.0
ValidateAgainstSchema validates the given CoT event XML against the point schema.
func ValidateHow ¶ added in v0.2.7
ValidateHow checks if a how value is valid according to the CoT catalog. How values indicate the source or method of position determination.
func ValidateLatLon ¶
ValidateLatLon checks if latitude and longitude are within valid ranges
func ValidateRelation ¶ added in v0.2.7
ValidateRelation checks if a relation value is valid according to the CoT catalog. Relation values indicate the relationship type in link elements.
func ValidateType ¶
ValidateType checks if a CoT type is valid
Example ¶
package main
import (
"fmt"
"github.com/NERVsystems/cotlib"
)
func main() {
// Test various CoT types
types := []string{
"a-f-G", // Friendly ground
"a-h-A", // Hostile air
"b-d", // Detection
"t-x-takp-v", // TAK presence
"invalid", // Invalid type
}
for _, typ := range types {
err := cotlib.ValidateType(typ)
fmt.Printf("Type %s: %v\n", typ, err == nil)
}
}
Output: Type a-f-G: true Type a-h-A: true Type b-d: true Type t-x-takp-v: true Type invalid: false
func ValidateUID ¶
ValidateUID checks if a UID is valid. It rejects empty values, leading hyphens, double dots, whitespace, and UIDs longer than 64 characters.
Types ¶
type Archive ¶ added in v0.2.8
type Archive struct {
Raw RawMessage
}
Archive represents the TAK archive extension.
func (Archive) MarshalXML ¶ added in v0.2.8
func (*Archive) UnmarshalXML ¶ added in v0.2.8
type AttachmentList ¶ added in v0.2.8
type AttachmentList struct {
Raw RawMessage
}
AttachmentList represents the TAK attachmentList extension.
func (AttachmentList) MarshalXML ¶ added in v0.2.8
func (a AttachmentList) MarshalXML(enc *xml.Encoder, start xml.StartElement) error
func (*AttachmentList) UnmarshalXML ¶ added in v0.2.8
func (a *AttachmentList) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error
type Bullseye ¶ added in v0.2.8
type Bullseye struct {
Raw RawMessage
}
Bullseye represents the TAK bullseye extension.
func (Bullseye) MarshalXML ¶ added in v0.2.8
func (*Bullseye) UnmarshalXML ¶ added in v0.2.8
type Chat ¶ added in v0.2.8
type Chat struct {
XMLName xml.Name `xml:"__chat"`
ID string `xml:"id,attr,omitempty"`
Message string `xml:"message,attr,omitempty"`
Sender string `xml:"sender,attr,omitempty"`
Chatroom string `xml:"chatroom,attr,omitempty"`
GroupOwner string `xml:"groupOwner,attr,omitempty"`
SenderCallsign string `xml:"senderCallsign,attr,omitempty"`
Parent string `xml:"parent,attr,omitempty"`
MessageID string `xml:"messageId,attr,omitempty"`
DeleteChild string `xml:"deleteChild,attr,omitempty"`
ChatGrps []ChatGrp `xml:"chatgrp,omitempty"`
Hierarchy *Hierarchy `xml:"hierarchy,omitempty"`
Raw RawMessage `xml:"-"`
}
Chat represents the TAK __chat extension including group information.
func (*Chat) IsGroupChat ¶ added in v0.3.7
IsGroupChat reports whether the chat message targets a group. A chat is considered a group chat when the Chatroom or GroupOwner fields are non-empty or when any ChatGrp elements are present.
Example ¶
package main
import (
"fmt"
"github.com/NERVsystems/cotlib"
)
func main() {
direct := &cotlib.Chat{Message: "hi", Sender: "A"}
fmt.Println(direct.IsGroupChat())
group := &cotlib.Chat{Chatroom: "room", SenderCallsign: "A"}
fmt.Println(group.IsGroupChat())
}
Output: false true
func (Chat) MarshalXML ¶ added in v0.2.8
func (*Chat) UnmarshalXML ¶ added in v0.2.8
type ChatGrp ¶ added in v0.3.6
type ChatGrp struct {
XMLName xml.Name `xml:"chatgrp"`
ID string `xml:"id,attr,omitempty"`
UID0 string `xml:"uid0,attr,omitempty"`
UID1 string `xml:"uid1,attr,omitempty"`
UID2 string `xml:"uid2,attr,omitempty"`
}
ChatGrp represents a chat group entry within a chat message.
type ChatReceipt ¶ added in v0.2.8
type ChatReceipt struct {
XMLName xml.Name `xml:""`
Ack string `xml:"ack,attr,omitempty"`
ID string `xml:"id,attr,omitempty"`
Chatroom string `xml:"chatroom,attr,omitempty"`
GroupOwner string `xml:"groupOwner,attr,omitempty"`
SenderCallsign string `xml:"senderCallsign,attr,omitempty"`
MessageID string `xml:"messageId,attr,omitempty"`
Parent string `xml:"parent,attr,omitempty"`
ChatGrp *ChatGrp `xml:"chatgrp,omitempty"`
Raw RawMessage `xml:"-"`
}
ChatReceipt represents the TAK chat receipt extensions.
func (ChatReceipt) MarshalXML ¶ added in v0.2.8
func (c ChatReceipt) MarshalXML(enc *xml.Encoder, start xml.StartElement) error
func (*ChatReceipt) UnmarshalXML ¶ added in v0.2.8
func (c *ChatReceipt) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error
type CoTTime ¶
CoTTime represents a time in CoT format (UTC without timezone offset)
func (CoTTime) MarshalXML ¶
MarshalXML implements xml.Marshaler
func (CoTTime) MarshalXMLAttr ¶
MarshalXMLAttr implements xml.MarshalerAttr
func (*CoTTime) UnmarshalXML ¶
UnmarshalXML implements xml.Unmarshaler
type ColorExtension ¶ added in v0.2.8
type ColorExtension struct {
Raw RawMessage
}
ColorExtension represents the TAK color extension.
func (ColorExtension) MarshalXML ¶ added in v0.2.8
func (c ColorExtension) MarshalXML(enc *xml.Encoder, start xml.StartElement) error
func (*ColorExtension) UnmarshalXML ¶ added in v0.2.8
func (c *ColorExtension) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error
type Contact ¶
type Contact struct {
XMLName xml.Name `xml:"contact"`
Callsign string `xml:"callsign,attr,omitempty"`
}
Contact represents contact information
type Detail ¶
type Detail struct {
Group *Group `xml:"group,omitempty"`
Contact *Contact `xml:"contact,omitempty"`
Chat *Chat `xml:"__chat,omitempty"`
ChatReceipt *ChatReceipt `xml:"__chatReceipt,omitempty"`
Emergency *Emergency `xml:"emergency,omitempty"`
Geofence *Geofence `xml:"__geofence,omitempty"`
ServerDestination *ServerDestination `xml:"__serverdestination,omitempty"`
Video *Video `xml:"__video,omitempty"`
GroupExtension *GroupExtension `xml:"__group,omitempty"`
Archive *Archive `xml:"archive,omitempty"`
AttachmentList *AttachmentList `xml:"attachmentList,omitempty"`
Environment *Environment `xml:"environment,omitempty"`
PrecisionLocation *PrecisionLocation `xml:"precisionlocation,omitempty"`
Takv *Takv `xml:"takv,omitempty"`
Track *Track `xml:"track,omitempty"`
Mission *Mission `xml:"mission,omitempty"`
Status *Status `xml:"status,omitempty"`
Shape *Shape `xml:"shape,omitempty"`
StrokeColor *StrokeColor `xml:"strokecolor,omitempty"`
StrokeWeight *StrokeWeight `xml:"strokeweight,omitempty"`
FillColor *FillColor `xml:"fillcolor,omitempty"`
Height *Height `xml:"height,omitempty"`
HeightUnit *HeightUnit `xml:"height_unit,omitempty"`
LabelsOn *LabelsOn `xml:"labelson,omitempty"`
ColorExtension *ColorExtension `xml:"color,omitempty"`
Hierarchy *Hierarchy `xml:"hierarchy,omitempty"`
LinkDetail *DetailLink `xml:"link,omitempty"`
UserIcon *UserIcon `xml:"usericon,omitempty"`
UID *UID `xml:"uid,omitempty"`
Bullseye *Bullseye `xml:"bullseye,omitempty"`
RouteInfo *RouteInfo `xml:"routeInfo,omitempty"`
Marti *Marti `xml:"marti,omitempty"`
Remarks *Remarks `xml:"remarks,omitempty"`
Unknown []RawMessage `xml:"-"`
}
Detail contains additional information about an event
func (*Detail) MarshalXML ¶ added in v0.2.8
MarshalXML implements xml.Marshaler for Detail.
func (*Detail) UnmarshalXML ¶ added in v0.2.8
UnmarshalXML implements xml.Unmarshaler for Detail.
type DetailLink ¶ added in v0.3.1
type DetailLink struct {
Raw RawMessage
}
DetailLink represents the TAK link detail extension.
func (DetailLink) MarshalXML ¶ added in v0.3.1
func (dl DetailLink) MarshalXML(enc *xml.Encoder, start xml.StartElement) error
func (*DetailLink) UnmarshalXML ¶ added in v0.3.1
func (dl *DetailLink) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error
type Emergency ¶ added in v0.3.1
type Emergency struct {
Raw RawMessage
}
Emergency represents the TAK emergency extension.
func (Emergency) MarshalXML ¶ added in v0.3.1
func (*Emergency) UnmarshalXML ¶ added in v0.3.1
type Environment ¶ added in v0.2.8
type Environment struct {
Raw RawMessage
}
Environment represents the TAK environment extension.
func (Environment) MarshalXML ¶ added in v0.2.8
func (e Environment) MarshalXML(enc *xml.Encoder, start xml.StartElement) error
func (*Environment) UnmarshalXML ¶ added in v0.2.8
func (e *Environment) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error
type Event ¶
type Event struct {
XMLName xml.Name `xml:"event"`
Version string `xml:"version,attr"`
Uid string `xml:"uid,attr"`
Type string `xml:"type,attr"`
How string `xml:"how,attr,omitempty"`
Time CoTTime `xml:"time,attr"`
Start CoTTime `xml:"start,attr"`
Stale CoTTime `xml:"stale,attr"`
// UnknownAttrs captures attributes that are not explicitly mapped to
// struct fields when unmarshalling.
UnknownAttrs []xml.Attr `xml:"-"`
Point Point `xml:"point"`
Detail *Detail `xml:"detail,omitempty"`
Links []Link `xml:"link,omitempty"`
// Message is populated for GeoChat events from the <remarks> element.
Message string `xml:"-"`
// StrokeColor is an ARGB hex color used for drawing events.
StrokeColor string `xml:"strokeColor,attr,omitempty"`
// UserIcon specifies a custom icon URL or resource for the event.
UserIcon string `xml:"usericon,attr,omitempty"`
}
Event represents a CoT event message
func NewEvent ¶
NewEvent creates a new CoT event with the given parameters
Example ¶
package main
import (
"fmt"
"github.com/NERVsystems/cotlib"
)
func main() {
// Create a new event with a friendly ground unit
event, err := cotlib.NewEvent("test123", "a-f-G", 30.0, -85.0, 0.0)
if err != nil {
fmt.Printf("Error creating event: %v\n", err)
return
}
// Add some details
event.Detail = &cotlib.Detail{
Contact: &cotlib.Contact{
Callsign: "TEST-1",
},
}
// Print event details
fmt.Printf("Event Type: %s\n", event.Type)
fmt.Printf("Location: %.2f, %.2f\n", event.Point.Lat, event.Point.Lon)
fmt.Printf("Callsign: %s\n", event.Detail.Contact.Callsign)
}
Output: Event Type: a-f-G Location: 30.00, -85.00 Callsign: TEST-1
func NewPresenceEvent ¶
NewPresenceEvent creates a new presence event (t-x-takp-v)
func UnmarshalXMLEvent ¶
UnmarshalXMLEvent parses an XML byte slice into an Event. The returned Event is obtained from an internal pool; callers should release it with ReleaseEvent when finished. The function uses the standard library's encoding/xml Decoder under the hood.
func UnmarshalXMLEventCtx ¶ added in v0.2.8
UnmarshalXMLEventCtx parses an XML byte slice into an Event using the provided context for logging. The returned Event is obtained from an internal pool and must be released with ReleaseEvent when finished.
func (*Event) AddLink ¶
AddLink adds a link to the event
Example ¶
package main
import (
"fmt"
"github.com/NERVsystems/cotlib"
)
func main() {
// Create a main event
event, err := cotlib.NewEvent("test123", "a-f-G", 30.0, -85.0, 0.0)
if err != nil {
fmt.Printf("Error creating event: %v\n", err)
return
}
// Add a link to another unit
event.AddLink(&cotlib.Link{
Uid: "TARGET1",
Type: "a-f-G",
Relation: "wingman",
})
// Print link details
for _, link := range event.Links {
fmt.Printf("Linked to: %s\n", link.Uid)
fmt.Printf("Link type: %s\n", link.Type)
fmt.Printf("Relation: %s\n", link.Relation)
}
}
Output: Linked to: TARGET1 Link type: a-f-G Relation: wingman
func (*Event) AddValidatedLink ¶ added in v0.2.7
AddValidatedLink adds a link to the event after validating the relation and type. It returns an error if called on a nil Event.
func (*Event) InjectIdentity ¶
InjectIdentity adds identity information to the event
Example ¶
package main
import (
"fmt"
"github.com/NERVsystems/cotlib"
)
func main() {
// Create a new event
event, err := cotlib.NewEvent("test123", "a-f-G", 30.0, -85.0, 0.0)
if err != nil {
fmt.Printf("Error creating event: %v\n", err)
return
}
// Inject identity information
event.InjectIdentity("self123", "Blue", "HQ")
// Print identity details
if event.Detail != nil && event.Detail.Group != nil {
fmt.Printf("Group: %s\n", event.Detail.Group.Name)
fmt.Printf("Role: %s\n", event.Detail.Group.Role)
}
}
Output: Group: Blue Role: HQ
func (*Event) Is ¶
Is checks if the event matches a predicate
Example ¶
package main
import (
"fmt"
"github.com/NERVsystems/cotlib"
)
func main() {
// Create a friendly ground unit event
event, err := cotlib.NewEvent("test123", "a-f-G", 30.0, -85.0, 0.0)
if err != nil {
fmt.Printf("Error creating event: %v\n", err)
return
}
// Check various predicates
fmt.Printf("Is friendly: %v\n", event.Is("friend"))
fmt.Printf("Is hostile: %v\n", event.Is("hostile"))
fmt.Printf("Is ground: %v\n", event.Is("ground"))
fmt.Printf("Is air: %v\n", event.Is("air"))
}
Output: Is friendly: true Is hostile: false Is ground: true Is air: false
func (*Event) ToXML ¶
ToXML serialises an Event to CoT-compliant XML. Attribute values are escaped to prevent XML-injection. The <point> element is always emitted so that the zero coordinate (0° N 0° E) is representable.
func (*Event) UnmarshalXML ¶ added in v0.3.8
UnmarshalXML implements xml.Unmarshaler for Event. It preserves any attributes that are not recognised by storing them in UnknownAttrs.
type EventBuilder ¶ added in v0.3.7
type EventBuilder struct {
// contains filtered or unexported fields
}
EventBuilder is a helper for constructing Event objects.
func NewEventBuilder ¶ added in v0.3.7
func NewEventBuilder(uid, typ string, lat, lon, hae float64) *EventBuilder
NewEventBuilder creates a new EventBuilder with the basic event fields set.
func (*EventBuilder) Build ¶ added in v0.3.7
func (b *EventBuilder) Build() (*Event, error)
Build validates and returns the constructed Event.
func (*EventBuilder) WithContact ¶ added in v0.3.7
func (b *EventBuilder) WithContact(c *Contact) *EventBuilder
WithContact sets the contact detail on the event.
func (*EventBuilder) WithGroup ¶ added in v0.3.7
func (b *EventBuilder) WithGroup(g *Group) *EventBuilder
WithGroup sets the group detail on the event.
func (*EventBuilder) WithStaleTime ¶ added in v0.3.7
func (b *EventBuilder) WithStaleTime(t time.Time) *EventBuilder
WithStaleTime sets a custom stale time for the event.
type FileShare ¶ added in v0.2.8
type FileShare struct {
}
FileShare represents the TAK fileshare extension.
func (FileShare) MarshalXML ¶ added in v0.2.8
func (*FileShare) UnmarshalXML ¶ added in v0.2.8
type FillColor ¶ added in v0.2.8
type FillColor struct {
Raw RawMessage
}
FillColor represents the TAK fillcolor extension.
func (FillColor) MarshalXML ¶ added in v0.2.8
func (*FillColor) UnmarshalXML ¶ added in v0.2.8
type Geofence ¶ added in v0.2.8
type Geofence struct {
Raw RawMessage
}
Geofence represents the TAK __geofence extension.
func (Geofence) MarshalXML ¶ added in v0.2.8
func (*Geofence) UnmarshalXML ¶ added in v0.2.8
type GroupExtension ¶ added in v0.2.8
type GroupExtension struct {
Raw RawMessage
}
GroupExtension represents the TAK __group extension.
func (GroupExtension) MarshalXML ¶ added in v0.2.8
func (g GroupExtension) MarshalXML(enc *xml.Encoder, start xml.StartElement) error
func (*GroupExtension) UnmarshalXML ¶ added in v0.2.8
func (g *GroupExtension) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error
type Height ¶ added in v0.3.1
type Height struct {
Raw RawMessage
}
Height represents the TAK height extension.
func (Height) MarshalXML ¶ added in v0.3.1
func (*Height) UnmarshalXML ¶ added in v0.3.1
type HeightUnit ¶ added in v0.3.1
type HeightUnit struct {
Raw RawMessage
}
HeightUnit represents the TAK height_unit extension.
func (HeightUnit) MarshalXML ¶ added in v0.3.1
func (hu HeightUnit) MarshalXML(enc *xml.Encoder, start xml.StartElement) error
func (*HeightUnit) UnmarshalXML ¶ added in v0.3.1
func (hu *HeightUnit) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error
type Hierarchy ¶ added in v0.3.1
type Hierarchy struct {
Raw RawMessage
}
Hierarchy represents the TAK hierarchy extension.
func (Hierarchy) MarshalXML ¶ added in v0.3.1
func (*Hierarchy) UnmarshalXML ¶ added in v0.3.1
type LabelsOn ¶ added in v0.2.8
type LabelsOn struct {
Raw RawMessage
}
LabelsOn represents the TAK labelson extension.
func (LabelsOn) MarshalXML ¶ added in v0.2.8
func (*LabelsOn) UnmarshalXML ¶ added in v0.2.8
type Link ¶
type Link struct {
Uid string `xml:"uid,attr"`
Type string `xml:"type,attr"`
Relation string `xml:"relation,attr"`
}
Link represents a relationship to another event
type Marti ¶ added in v0.3.6
Marti represents the TAK marti extension containing destination callsigns.
type MartiDest ¶ added in v0.3.6
type MartiDest struct {
Callsign string `xml:"callsign,attr,omitempty"`
}
MartiDest represents a destination callsign within a Marti extension.
type Mission ¶ added in v0.2.8
type Mission struct {
Raw RawMessage
}
Mission represents the TAK mission extension.
func (Mission) MarshalXML ¶ added in v0.2.8
func (*Mission) UnmarshalXML ¶ added in v0.2.8
type Point ¶
type Point struct {
Lat float64 `xml:"lat,attr"` // Latitude in degrees
Lon float64 `xml:"lon,attr"` // Longitude in degrees
Hae float64 `xml:"hae,attr"` // Height above ellipsoid in meters
Ce float64 `xml:"ce,attr"` // Circular error in meters
Le float64 `xml:"le,attr"` // Linear error in meters
}
Point represents a location in 3D space with error estimates
type PrecisionLocation ¶ added in v0.2.8
type PrecisionLocation struct {
Raw RawMessage
}
PrecisionLocation represents the TAK precisionlocation extension.
func (PrecisionLocation) MarshalXML ¶ added in v0.2.8
func (p PrecisionLocation) MarshalXML(enc *xml.Encoder, start xml.StartElement) error
func (*PrecisionLocation) UnmarshalXML ¶ added in v0.2.8
func (p *PrecisionLocation) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error
type RawMessage ¶ added in v0.2.8
type RawMessage []byte
RawMessage represents raw XML data preserved during decoding.
type Remarks ¶ added in v0.2.8
type Remarks struct {
XMLName xml.Name `xml:"remarks"`
Source string `xml:"source,attr,omitempty"`
SourceID string `xml:"sourceID,attr,omitempty"`
To string `xml:"to,attr,omitempty"`
Time CoTTime `xml:"time,attr,omitempty"`
Text string `xml:",chardata"`
Raw RawMessage `xml:"-"`
}
Remarks represents the TAK remarks extension. Remarks represents the TAK remarks extension. It preserves the original XML while also allowing convenient access to common attributes and the text payload.
func (Remarks) MarshalXML ¶ added in v0.2.8
func (*Remarks) Parse ¶ added in v0.3.6
Parse fills the Remarks fields from Raw if present. It is safe to call multiple times.
func (*Remarks) UnmarshalXML ¶ added in v0.2.8
type RouteInfo ¶ added in v0.2.8
type RouteInfo struct {
Raw RawMessage
}
RouteInfo represents the TAK routeInfo extension.
func (RouteInfo) MarshalXML ¶ added in v0.2.8
func (*RouteInfo) UnmarshalXML ¶ added in v0.2.8
type ServerDestination ¶ added in v0.2.8
type ServerDestination struct {
Raw RawMessage
}
ServerDestination represents the TAK __serverdestination extension.
func (ServerDestination) MarshalXML ¶ added in v0.2.8
func (sd ServerDestination) MarshalXML(enc *xml.Encoder, start xml.StartElement) error
func (*ServerDestination) UnmarshalXML ¶ added in v0.2.8
func (sd *ServerDestination) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error
type Shape ¶ added in v0.2.8
type Shape struct {
Raw RawMessage
}
Shape represents the TAK shape extension.
func (Shape) MarshalXML ¶ added in v0.2.8
func (*Shape) UnmarshalXML ¶ added in v0.2.8
type Status ¶ added in v0.2.8
type Status struct {
Raw RawMessage
}
Status represents the TAK status extension.
func (Status) MarshalXML ¶ added in v0.2.8
func (*Status) UnmarshalXML ¶ added in v0.2.8
type StrokeColor ¶ added in v0.2.8
type StrokeColor struct {
Raw RawMessage
}
StrokeColor represents the TAK strokecolor extension.
func (StrokeColor) MarshalXML ¶ added in v0.2.8
func (sc StrokeColor) MarshalXML(enc *xml.Encoder, start xml.StartElement) error
func (*StrokeColor) UnmarshalXML ¶ added in v0.2.8
func (sc *StrokeColor) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error
type StrokeWeight ¶ added in v0.2.8
type StrokeWeight struct {
Raw RawMessage
}
StrokeWeight represents the TAK strokeweight extension.
func (StrokeWeight) MarshalXML ¶ added in v0.2.8
func (sw StrokeWeight) MarshalXML(enc *xml.Encoder, start xml.StartElement) error
func (*StrokeWeight) UnmarshalXML ¶ added in v0.2.8
func (sw *StrokeWeight) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error
type Takv ¶ added in v0.2.8
type Takv struct {
Raw RawMessage
}
Takv represents the TAK takv extension.
func (Takv) MarshalXML ¶ added in v0.2.8
func (*Takv) UnmarshalXML ¶ added in v0.2.8
type Track ¶ added in v0.2.8
type Track struct {
Raw RawMessage
}
Track represents the TAK track extension.
func (Track) MarshalXML ¶ added in v0.2.8
func (*Track) UnmarshalXML ¶ added in v0.2.8
type UID ¶ added in v0.3.1
type UID struct {
Raw RawMessage
}
UID represents the TAK uid extension.
func (UID) MarshalXML ¶ added in v0.3.1
func (*UID) UnmarshalXML ¶ added in v0.3.1
type UserIcon ¶ added in v0.2.8
type UserIcon struct {
Raw RawMessage
}
UserIcon represents the TAK usericon extension.
func (UserIcon) MarshalXML ¶ added in v0.2.8
func (*UserIcon) UnmarshalXML ¶ added in v0.2.8
type Video ¶ added in v0.2.8
type Video struct {
Raw RawMessage
}
Video represents the TAK __video extension.
