Exemplo n.º 1
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
}
Exemplo n.º 2
0
func (attr *String) Encode(w *pgx.WriteBuf, oid pgx.Oid) error {
	switch attr.Status {
	case Present:
		return pgx.Encode(w, oid, attr.Value)
	case Null:
		w.WriteInt32(-1)
		return nil
	case Undefined:
		return errors.New("cannot encode undefined attr")
	default:
		panic("unreachable")
	}
}
Exemplo n.º 3
0
func (attr *IPNet) Encode(w *pgx.WriteBuf, oid pgx.Oid) error {
	if oid != pgx.InetOid && oid != pgx.CidrOid {
		return pgx.SerializationError(fmt.Sprintf("IPNet.Encode cannot encode into OID %d", oid))
	}

	switch attr.Status {
	case Present:
		return pgx.Encode(w, oid, attr.Value)
	case Null:
		w.WriteInt32(-1)
		return nil
	case Undefined:
		return errors.New("cannot encode undefined attr")
	default:
		panic("unreachable")
	}
}
Exemplo n.º 4
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
}
Exemplo n.º 5
0
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
}
Exemplo n.º 6
0
func (n *coreEncoder) Encode(w *pgx.WriteBuf, oid pgx.Oid) error {
	w.WriteInt32(int32(2))
	w.WriteBytes([]byte("42"))
	return nil
}