=本文整理汇总了Golang中encoding/gob.NewDecoder函数的典型用法代码### 示例。如果您正苦于以下问题:Golang NewDecoder函数的具体用法?Golang NewDecoder怎么用?Golang NewDecoder使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。
在下文中一共展示了NewDecoder函数的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。
示例1: receiveDecrypt
func receiveDecrypt(conn net.Conn) (Message, error) {
// Our work is:
// (receive) -> [de-GOB] -> [DECRYPT] -> [de-GOB] -> msg
// Receive data and de-serialize to get the encrypted message
encMsg := new([]byte)
receive := gob.NewDecoder(conn)
if err := receive.Decode(encMsg); err != nil {
return Message{}, err
}
// Create decrypter and pass it the encrypted message
r := bytes.NewReader(*encMsg)
decrypter, err := saltsecret.NewReader(r, conf.Key, saltsecret.DECRYPT, false)
if err != nil {
return Message{}, err
}
// Read unencrypted serialized message and de-serialize it
msg := new(Message)
dec := gob.NewDecoder(decrypter)
if err = dec.Decode(msg); err != nil {
return Message{}, err
}
return *msg, nil
}
开发者ID:andmarios,项目名称:bashistdb,代码行数:27,代码来源:encryptcomm.go
示例2: ReadFromDisk
func ReadFromDisk() {
file, err := os.Open("data/datafile.gob")
if err == nil {
dec := gob.NewDecoder(file)
err = dec.Decode(&data)
file.Close()
if err != nil {
log.Fatal("Unable to decode:", err)
}
}
var packet WritePacket
for ii := 0; ii < 128; ii++ {
file, err := os.Open("data/datafile.log." + fmt.Sprintf("%03d", ii))
if err != nil {
break
} else {
dec := gob.NewDecoder(file)
for dec.Decode(&packet) == nil {
data[packet.Key] = packet.Val
changeCount++
}
file.Close()
}
}
}
开发者ID:jcamins,项目名称:jcdbp,代码行数:25,代码来源:datastore.go
示例3: TestJsonHelperGobEncoding
func TestJsonHelperGobEncoding(t *testing.T) {
raw := `{"testing": 123,"name":"bob & more"}`
reader := strings.NewReader(raw)
jh, err := NewJsonHelperReader(reader)
assert.Tf(t, err == nil, "Unexpected error decoding gob: %s", err)
assert.Tf(t, jh.Int("testing") == 123, "Unexpected value in gob: %d", jh.Int("testing"))
var buf bytes.Buffer
err = gob.NewEncoder(&buf).Encode(&jh)
assert.T(t, err == nil, err)
var jhNew JsonHelper
err = gob.NewDecoder(&buf).Decode(&jhNew)
assert.T(t, err == nil, err)
assert.Tf(t, jhNew.Int("testing") == 123, "Unexpected value in gob: %d", jhNew.Int("testing"))
assert.Tf(t, jhNew.String("name") == "bob & more", "Unexpected value in gob: %d", jhNew.String("name"))
buf2 := bytes.Buffer{}
gt := GobTest{"Hello", jh}
err = gob.NewEncoder(&buf2).Encode(>)
assert.T(t, err == nil, err)
var gt2 GobTest
err = gob.NewDecoder(&buf2).Decode(>2)
assert.T(t, err == nil, err)
assert.Tf(t, gt2.Name == "Hello", "Unexpected value in gob: %d", gt2.Name)
assert.Tf(t, gt2.Data.Int("testing") == 123, "Unexpected value in gob: %d", gt2.Data.Int("testing"))
assert.Tf(t, gt2.Data.String("name") == "bob & more", "Unexpected value in gob: %d", gt2.Data.String("name"))
}
开发者ID:admpub,项目名称:gou,代码行数:28,代码来源:jsonhelper_test.go
示例4: DecodeValue
func (gobCoder) DecodeValue(r io.Reader, dst reflect.Value) error {
if _, ok := r.(io.ByteReader); !ok {
return gob.NewDecoder(byteReader{r}).DecodeValue(dst)
}
return gob.NewDecoder(r).DecodeValue(dst)
}
开发者ID:shaladdle,项目名称:goaaw,代码行数:7,代码来源:coders.go
示例5: Decode
func (gobCoder) Decode(r io.Reader, dst interface{}) error {
if _, ok := r.(io.ByteReader); !ok {
return gob.NewDecoder(byteReader{r}).Decode(dst)
}
return gob.NewDecoder(r).Decode(dst)
}
开发者ID:shaladdle,项目名称:goaaw,代码行数:7,代码来源:coders.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng