github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/encoding/gob/encoder.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package gob 6 7 import ( 8 "github.com/shogo82148/std/io" 9 "github.com/shogo82148/std/reflect" 10 "github.com/shogo82148/std/sync" 11 ) 12 13 // Encoderは、接続の他方に対する型とデータ情報の送信を管理します。 14 // 複数のgoroutineが同時に使用しても安全です。 15 type Encoder struct { 16 mutex sync.Mutex 17 w []io.Writer 18 sent map[reflect.Type]typeId 19 countState *encoderState 20 freeList *encoderState 21 byteBuf encBuffer 22 err error 23 } 24 25 // NewEncoderは、[io.Writer] 上で送信する新しいエンコーダを返します。 26 func NewEncoder(w io.Writer) *Encoder 27 28 // Encodeは、空のインターフェース値で表されるデータ項目を送信します。 29 // 必要なすべての型情報が最初に送信されることを保証します。 30 // nilポインタをEncoderに渡すとパニックを引き起こします、なぜならそれらはgobによって送信できないからです。 31 func (enc *Encoder) Encode(e any) error 32 33 // EncodeValueは、リフレクション値によって表されるデータ項目を送信します。 34 // 必要なすべての型情報が最初に送信されることを保証します。 35 // nilポインタをEncodeValueに渡すとパニックを引き起こします、なぜならそれらはgobによって送信できないからです。 36 func (enc *Encoder) EncodeValue(value reflect.Value) error