106 lines
2.3 KiB

package geagle
import (
// A Gate
// multiple gates form a device
type Gate struct {
Name string `xml:"name,attr"`
Symbol string `xml:"symbol,attr"`
// A list of technologies
type Technology struct {
Name string `xml:"name,attr"`
// A connection
// Connectes Pads of one package with the pins of
// all gates a device posseses
type Connection struct {
Gate string `xml:"gate,attr"`
Pin string `xml:"pin,attr"`
Pad string `xml:"pad,attr"`
// A 3d package
// new in Eagle 8 and above
// only contains a urn for the autodesk library service
type Package3d struct {
Urn string `xml:"package3d_urn,attr"`
// A device
// bundles multiple gates and packages
// then defines how they are connected
type Device struct {
Name string `xml:"name,attr"`
Package string `xml:"package,attr"`
Package3d []Package3d `xml:package3dinstances>package3dinstance"`
Technologies []Technology `xml:"technologies>technology"`
Connections []Connection `xml:"connects>connect"`
type Deviceset struct {
Name string `xml:"name,attr"`
Prefix string `xml:"prefix,attr"`
Description string `xml:"description,omitempty"`
Urn string `xml:"urn,attr,omitempty"`
Gates []Gate `xml:"gates>gate"`
Devices []Device `xml:"devices>device"`
type Library struct {
Packages []Package `xml:"packages>package"`
Symbols []Symbol `xml:"symbols>symbol"`
Devicesets []Deviceset `xml:"devicesets>deviceset"`
type Drawing struct {
Grid Grid `xml:"grid"`
Layers []Layer `xml:"layers>layer"`
Library Library `xml:"library"`
type FileHeader struct {
Version string `xml:"version,attr"`
func ParseLibrary(in io.Reader) (result Drawing, err error) {
file := struct {
Eagle FileHeader
Drawing Drawing `xml:"drawing"`
decoder := xml.NewDecoder(in)
err = decoder.Decode(&file)
return file.Drawing, err
// defines an eagle file
type eagle struct {
Drawing *Drawing `xml:"drawing"`
func (drw *Drawing) WriteTo(out io.Writer) error {
// write DOCTYPE and xml header
io.WriteString(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>")
io.WriteString(out, "<!DOCTYPE eagle SYSTEM \"eagle.dtd\">")
encoder := xml.NewEncoder(out)
file := eagle{
FileHeader: FileHeader{"8.3.2"},
Drawing: drw,
return encoder.Encode(&file)