本文整理匯總了Golang中github.com/balzaczyy/golucene/core/util.DataInput.ReadByte方法的典型用法代碼示例。如果您正苦於以下問題:Golang DataInput.ReadByte方法的具體用法?Golang DataInput.ReadByte怎麽用?Golang DataInput.ReadByte使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/balzaczyy/golucene/core/util.DataInput
的用法示例。
在下文中一共展示了DataInput.ReadByte方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: readLabel
func (t *FST) readLabel(in util.DataInput) (v int, err error) {
switch t.inputType {
case INPUT_TYPE_BYTE1: // Unsigned byte
if b, err := in.ReadByte(); err == nil {
v = int(b)
}
case INPUT_TYPE_BYTE2: // Unsigned short
if s, err := in.ReadShort(); err == nil {
v = int(s)
}
default:
v, err = AsInt(in.ReadVInt())
}
return v, err
}
示例2: loadFST3
/** Load a previously saved FST; maxBlockBits allows you to
* control the size of the byte[] pages used to hold the FST bytes. */
func loadFST3(in util.DataInput, outputs Outputs, maxBlockBits uint32) (fst *FST, err error) {
log.Printf("Loading FST from %v and output to %v...", in, outputs)
defer func() {
if err != nil {
log.Print("Failed to load FST.")
log.Printf("DEBUG ", err)
}
}()
fst = &FST{outputs: outputs, startNode: -1}
if maxBlockBits < 1 || maxBlockBits > 30 {
panic(fmt.Sprintf("maxBlockBits should 1..30; got %v", maxBlockBits))
}
// NOTE: only reads most recent format; we don't have
// back-compat promise for FSTs (they are experimental):
fst.version, err = codec.CheckHeader(in, FST_FILE_FORMAT_NAME, FST_VERSION_PACKED, FST_VERSION_VINT_TARGET)
if err != nil {
return fst, err
}
if b, err := in.ReadByte(); err == nil {
fst.packed = (b == 1)
} else {
return fst, err
}
if b, err := in.ReadByte(); err == nil {
if b == 1 {
// accepts empty string
// 1 KB blocks:
emptyBytes := newBytesStoreFromBits(10)
if numBytes, err := in.ReadVInt(); err == nil {
log.Printf("Number of bytes: %v", numBytes)
emptyBytes.CopyBytes(in, int64(numBytes))
// De-serialize empty-string output:
var reader BytesReader
if fst.packed {
log.Printf("Forward reader.")
reader = emptyBytes.forwardReader()
} else {
log.Printf("Reverse reader.")
reader = emptyBytes.reverseReader()
// NoOutputs uses 0 bytes when writing its output,
// so we have to check here else BytesStore gets
// angry:
if numBytes > 0 {
reader.setPosition(int64(numBytes - 1))
}
}
log.Printf("Reading final output from %v to %v...", reader, outputs)
fst.emptyOutput, err = outputs.ReadFinalOutput(reader)
}
} // else emptyOutput = nil
}
if err != nil {
return fst, err
}
if t, err := in.ReadByte(); err == nil {
switch t {
case 0:
fst.inputType = INPUT_TYPE_BYTE1
case 1:
fst.inputType = INPUT_TYPE_BYTE2
case 2:
fst.inputType = INPUT_TYPE_BYTE4
default:
panic(fmt.Sprintf("invalid input type %v", t))
}
}
if err != nil {
return fst, err
}
if fst.packed {
fst.nodeRefToAddress, err = packed.NewPackedReader(in)
if err != nil {
return fst, err
}
} // else nodeRefToAddress = nil
if fst.startNode, err = in.ReadVLong(); err == nil {
if fst.nodeCount, err = in.ReadVLong(); err == nil {
if fst.arcCount, err = in.ReadVLong(); err == nil {
if fst.arcWithOutputCount, err = in.ReadVLong(); err == nil {
if numBytes, err := in.ReadVLong(); err == nil {
if fst.bytes, err = newBytesStoreFromInput(in, numBytes, 1<<maxBlockBits); err == nil {
fst.NO_OUTPUT = outputs.NoOutput()
err = fst.cacheRootArcs()
// NOTE: bogus because this is only used during
// building; we need to break out mutable FST from
// immutable
// fst.allowArrayArcs = false
}
}
}
//.........這裏部分代碼省略.........