Moved special code for interleaver out of common.

This commit is contained in:
Sascha L. Teichmann 2014-08-23 16:01:57 +02:00
parent 954cc1928b
commit 8cd23d257f
2 changed files with 35 additions and 34 deletions

View File

@ -176,31 +176,3 @@ func TranscodeInterleavedToPlain(key []byte) ([]byte, error) {
return EncodeStringToBytes(TransformInterleavedToPlain(pos)) return EncodeStringToBytes(TransformInterleavedToPlain(pos))
} }
} }
func SelectKeySplitter(interleaved bool) KeySplitter {
if interleaved {
return InterleavedToCoord
}
return PlainToCoord
}
func SelectKeyJoiner(interleaved bool) KeyJoiner {
if interleaved {
return CoordToInterleaved
}
return CoordToPlain
}
func SelectKeyDecoder(interleaved bool) KeyDecoder {
if interleaved {
return DecodeFromBigEndian
}
return DecodeStringFromBytes
}
func SelectKeyEncoder(interleaved bool) KeyEncoder {
if interleaved {
return EncodeToBigEndian
}
return EncodeStringToBytes
}

View File

@ -20,6 +20,34 @@ func usage() {
flag.PrintDefaults() flag.PrintDefaults()
} }
func selectKeySplitter(interleaved bool) common.KeySplitter {
if interleaved {
return common.InterleavedToCoord
}
return common.PlainToCoord
}
func selectKeyJoiner(interleaved bool) common.KeyJoiner {
if interleaved {
return common.CoordToInterleaved
}
return common.CoordToPlain
}
func selectKeyDecoder(interleaved bool) common.KeyDecoder {
if interleaved {
return common.DecodeFromBigEndian
}
return common.DecodeStringFromBytes
}
func selectKeyEncoder(interleaved bool) common.KeyEncoder {
if interleaved {
return common.EncodeToBigEndian
}
return common.EncodeStringToBytes
}
func copyProducerToConsumer(producer BlockProducer, consumer BlockConsumer) (err error) { func copyProducerToConsumer(producer BlockProducer, consumer BlockConsumer) (err error) {
var block Block var block Block
i := 0 i := 0
@ -86,14 +114,14 @@ func main() {
if srcBackend == "sqlite" { if srcBackend == "sqlite" {
if producer, err = NewSQLiteBlockProducer( if producer, err = NewSQLiteBlockProducer(
flag.Arg(0), flag.Arg(0),
common.SelectKeySplitter(srcInterleaved)); err != nil { selectKeySplitter(srcInterleaved)); err != nil {
log.Fatalf("Cannot open '%s': %s", flag.Arg(0), err) log.Fatalf("Cannot open '%s': %s", flag.Arg(0), err)
} }
} else { // LevelDB } else { // LevelDB
if producer, err = NewLevelDBBlockProducer( if producer, err = NewLevelDBBlockProducer(
flag.Arg(0), flag.Arg(0),
common.SelectKeySplitter(srcInterleaved), selectKeySplitter(srcInterleaved),
common.SelectKeyDecoder(srcInterleaved)); err != nil { selectKeyDecoder(srcInterleaved)); err != nil {
log.Fatalf("Cannot open '%s': %s", flag.Arg(0), err) log.Fatalf("Cannot open '%s': %s", flag.Arg(0), err)
} }
} }
@ -101,14 +129,15 @@ func main() {
if dstBackend == "sqlite" { if dstBackend == "sqlite" {
if consumer, err = NewSQLiteBlockConsumer( if consumer, err = NewSQLiteBlockConsumer(
flag.Arg(1), common.SelectKeyJoiner(dstInterleaved)); err != nil { flag.Arg(1),
selectKeyJoiner(dstInterleaved)); err != nil {
log.Fatalf("Cannot open '%s': %s", flag.Arg(1), err) log.Fatalf("Cannot open '%s': %s", flag.Arg(1), err)
} }
} else { // LevelDB } else { // LevelDB
if consumer, err = NewLevelDBBlockConsumer( if consumer, err = NewLevelDBBlockConsumer(
flag.Arg(1), flag.Arg(1),
common.SelectKeyJoiner(dstInterleaved), selectKeyJoiner(dstInterleaved),
common.SelectKeyEncoder(dstInterleaved)); err != nil { selectKeyEncoder(dstInterleaved)); err != nil {
log.Fatalf("Cannot open '%s': %s", flag.Arg(1), err) log.Fatalf("Cannot open '%s': %s", flag.Arg(1), err)
} }
} }