Documentation
¶
Overview ¶
Package xfer implements Fossil's sync protocol card codec. It encodes and decodes the line-oriented "xfer card" format used by Fossil's /xfer HTTP endpoint, with NO database dependency.
Index ¶
- Constants
- func EncodeCard(w *bytes.Buffer, c Card) error
- type CFileCard
- type Card
- type CardType
- type CloneCard
- type CloneSeqNoCard
- type ConfigCard
- type CookieCard
- type ErrorCard
- type FileCard
- type GimmeCard
- type IGotCard
- type LoginCard
- type Message
- type MessageCard
- type PragmaCard
- type PrivateCard
- type PullCard
- type PushCard
- type ReqConfigCard
- type SchemaCard
- type UVFileCard
- type UVGimmeCard
- type UVIGotCard
- type UnknownCard
- type XDeleteCard
- type XGimmeCard
- type XIGotCard
- type XRowCard
Examples ¶
Constants ¶
const ( UVFlagDeletion = 0x0001 // File is a deletion tombstone. UVFlagContentOmitted = 0x0004 // Content not included in this card. UVFlagNoPayload = UVFlagDeletion | UVFlagContentOmitted // Mask: no payload expected. )
UV file flag constants.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Card ¶
type Card interface {
Type() CardType
}
Card is the interface implemented by every xfer card type.
type CardType ¶
type CardType int
CardType enumerates the 24 card types in Fossil's sync protocol.
const ( CardFile CardType = iota // 0 — file CardCFile // 1 — cfile (compressed file) CardIGot // 2 — igot CardGimme // 3 — gimme CardLogin // 4 — login CardPush // 5 — push CardPull // 6 — pull CardCookie // 7 — cookie CardClone // 8 — clone CardCloneSeqNo // 9 — clone_seqno (undocumented) CardConfig // 10 — config CardReqConfig // 11 — reqconfig CardPrivate // 12 — private CardUVFile // 13 — uvfile CardUVGimme // 14 — uvgimme CardUVIGot // 15 — uvigot CardPragma // 16 — pragma CardError // 17 — error CardMessage // 18 — message CardUnknown // 19 — unrecognized card CardSchema // 20 — schema (table sync) CardXIGot // 21 — xigot (table sync row announcement) CardXGimme // 22 — xgimme (table sync row request) CardXRow // 23 — xrow (table sync row payload) CardXDelete // 24 — xdelete (table sync row deletion) )
type CloneCard ¶
CloneCard represents a "clone" card. Version and SeqNo may be zero for legacy clone requests.
type CloneSeqNoCard ¶
type CloneSeqNoCard struct {
SeqNo int
}
CloneSeqNoCard represents a "clone_seqno" card.
func (*CloneSeqNoCard) Type ¶
func (c *CloneSeqNoCard) Type() CardType
type ConfigCard ¶
ConfigCard represents a "config" card carrying configuration data.
func (*ConfigCard) Type ¶
func (c *ConfigCard) Type() CardType
type CookieCard ¶
type CookieCard struct {
Value string
}
CookieCard carries a session cookie value.
func (*CookieCard) Type ¶
func (c *CookieCard) Type() CardType
type ErrorCard ¶
type ErrorCard struct {
Message string // plain text (defossilized)
}
ErrorCard carries an error message from the server.
type GimmeCard ¶
type GimmeCard struct {
UUID string
}
GimmeCard represents a "gimme" card — the sender wants this artifact.
type LoginCard ¶
LoginCard represents a "login" card for authentication. User is stored as plain text (Fossil-decoded).
type Message ¶
type Message struct {
Cards []Card
}
Message is a sequence of cards forming one xfer request or response.
func Decode ¶
Decode decodes an xfer message. It tries three formats in order:
- Raw zlib (Fossil HTTP sync wire format — no size prefix).
- 4-byte BE size prefix + zlib (Fossil blob compression / our Encode format).
- Uncompressed card data (clone protocol v3, x-fossil-uncompressed).
The first format that successfully decompresses wins.
func DecodeUncompressed ¶
DecodeUncompressed decodes cards from uncompressed data.
func (*Message) Encode ¶
Encode serializes all cards and zlib-compresses the result. Uses Fossil's compression format: 4-byte big-endian uncompressed size prefix followed by standard zlib data.
Example ¶
package main
import (
"fmt"
"github.com/danmestas/libfossil/internal/xfer"
)
func main() {
msg := &xfer.Message{
Cards: []xfer.Card{
&xfer.PushCard{ProjectCode: "abc123"},
&xfer.PullCard{ProjectCode: "abc123", ServerCode: "def456"},
&xfer.IGotCard{UUID: "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d"},
},
}
wire, err := msg.Encode()
if err != nil {
fmt.Println("error:", err)
return
}
// Wire format is zlib-compressed xfer cards.
fmt.Printf("compressed: %v\n", len(wire) > 0)
// Decode round-trips back to a Message.
decoded, err := xfer.Decode(wire)
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Printf("cards: %d\n", len(decoded.Cards))
}
Output: compressed: true cards: 3
func (*Message) EncodeUncompressed ¶
EncodeUncompressed serializes all cards without zlib compression.
type MessageCard ¶
type MessageCard struct {
Message string // plain text (defossilized)
}
MessageCard carries an informational message.
func (*MessageCard) Type ¶
func (c *MessageCard) Type() CardType
type PragmaCard ¶
PragmaCard represents a "pragma" card for protocol negotiation.
func (*PragmaCard) Type ¶
func (c *PragmaCard) Type() CardType
type PrivateCard ¶
type PrivateCard struct{}
PrivateCard signals that subsequent igot cards are private.
func (*PrivateCard) Type ¶
func (c *PrivateCard) Type() CardType
type ReqConfigCard ¶
type ReqConfigCard struct {
Name string
}
ReqConfigCard requests a named configuration section.
func (*ReqConfigCard) Type ¶
func (c *ReqConfigCard) Type() CardType
type SchemaCard ¶
type SchemaCard struct {
Table string // table name (without x_ prefix)
Version int
Hash string // SHA1 of canonical schema definition
MTime int64
Content []byte // raw JSON schema definition
}
SchemaCard declares a synced extension table. Wire: schema TABLE VERSION HASH MTIME SIZE\nJSON
func (*SchemaCard) Type ¶
func (c *SchemaCard) Type() CardType
type UVFileCard ¶
UVFileCard represents an "uvfile" card for unversioned file content.
func (*UVFileCard) Type ¶
func (c *UVFileCard) Type() CardType
type UVGimmeCard ¶
type UVGimmeCard struct {
Name string
}
UVGimmeCard requests an unversioned file by name.
func (*UVGimmeCard) Type ¶
func (c *UVGimmeCard) Type() CardType
type UVIGotCard ¶
UVIGotCard announces possession of an unversioned file.
func (*UVIGotCard) Type ¶
func (c *UVIGotCard) Type() CardType
type UnknownCard ¶
UnknownCard captures any unrecognized card command.
func (*UnknownCard) Type ¶
func (c *UnknownCard) Type() CardType
type XDeleteCard ¶
type XDeleteCard struct {
Table string
PKHash string
MTime int64
PKData []byte // JSON-encoded PK column values
}
XDeleteCard marks a table sync row as deleted (tombstone). Wire: xdelete TABLE PK_HASH MTIME SIZE\nJSON_PK_DATA
func (*XDeleteCard) Type ¶
func (c *XDeleteCard) Type() CardType
type XGimmeCard ¶
XGimmeCard requests a table sync row. Wire: xgimme TABLE PK_HASH
func (*XGimmeCard) Type ¶
func (c *XGimmeCard) Type() CardType