mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 10:28:49 -07:00
fa0101bd60
This changes the BEP protocol to use protocol buffer serialization instead of XDR, and therefore also the database format. The local discovery protocol is also updated to be protocol buffer format. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3276 LGTM: AudriusButkevicius
40 lines
830 B
Go
40 lines
830 B
Go
// Copyright (C) 2015 The Protocol Authors.
|
|
|
|
package protocol
|
|
|
|
import "fmt"
|
|
|
|
const (
|
|
compressionThreshold = 128 // don't bother compressing messages smaller than this many bytes
|
|
)
|
|
|
|
var compressionMarshal = map[Compression]string{
|
|
CompressNever: "never",
|
|
CompressMetadata: "metadata",
|
|
CompressAlways: "always",
|
|
}
|
|
|
|
var compressionUnmarshal = map[string]Compression{
|
|
// Legacy
|
|
"false": CompressNever,
|
|
"true": CompressMetadata,
|
|
|
|
// Current
|
|
"never": CompressNever,
|
|
"metadata": CompressMetadata,
|
|
"always": CompressAlways,
|
|
}
|
|
|
|
func (c Compression) GoString() string {
|
|
return fmt.Sprintf("%q", c.String())
|
|
}
|
|
|
|
func (c Compression) MarshalText() ([]byte, error) {
|
|
return []byte(compressionMarshal[c]), nil
|
|
}
|
|
|
|
func (c *Compression) UnmarshalText(bs []byte) error {
|
|
*c = compressionUnmarshal[string(bs)]
|
|
return nil
|
|
}
|