Exemple #1
0
func (b bytea) Encode(w *pgx.WriteBuf, oid pgx.Oid) error {
	if len(b) == 0 {
		w.WriteInt32(-1)
		return nil
	}
	w.WriteInt32(int32(len(b)))
	w.WriteBytes(b)
	return nil
}
func (p NullPoint) Encode(w *pgx.WriteBuf, oid pgx.Oid) error {
	if !p.Valid {
		w.WriteInt32(-1)
		return nil
	}

	s := fmt.Sprintf("point(%v,%v)", p.X, p.Y)
	w.WriteInt32(int32(len(s)))
	w.WriteBytes([]byte(s))

	return nil
}
Exemple #3
0
func (attr Bytes) Encode(w *pgx.WriteBuf, oid pgx.Oid) error {
	if oid != pgx.ByteaOid {
		return pgx.SerializationError(fmt.Sprintf("Bytes.Encode cannot encode into OID %d", oid))
	}

	if attr.Status != Present {
		w.WriteInt32(-1)
		return nil
	}

	w.WriteBytes(attr.Value)
	return nil
}
Exemple #4
0
func (n *coreEncoder) Encode(w *pgx.WriteBuf, oid pgx.Oid) error {
	w.WriteInt32(int32(2))
	w.WriteBytes([]byte("42"))
	return nil
}