38 lines
1.4 KiB
Plaintext
38 lines
1.4 KiB
Plaintext
package pgtype
|
|
|
|
<% skip_binary ||= false %>
|
|
<% skip_text ||= false %>
|
|
<% prefer_text_format ||= false %>
|
|
|
|
func (<%= go_type %>) BinaryFormatSupported() bool {
|
|
return true
|
|
}
|
|
|
|
func (<%= go_type %>) TextFormatSupported() bool {
|
|
return true
|
|
}
|
|
|
|
func (<%= go_type %>) PreferredFormat() int16 {
|
|
return <%= prefer_text_format ? "Text" : "Binary" %>FormatCode
|
|
}
|
|
|
|
func (dst *<%= go_type %>) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error {
|
|
switch format {
|
|
case BinaryFormatCode:
|
|
<% if skip_binary %> return fmt.Errorf("binary format not supported for %T", dst) <% else %> return dst.DecodeBinary(ci, src) <% end %>
|
|
case TextFormatCode:
|
|
<% if skip_text %> return fmt.Errorf("text format not supported for %T", dst) <% else %> return dst.DecodeText(ci, src) <% end %>
|
|
}
|
|
return fmt.Errorf("unknown format code %d", format)
|
|
}
|
|
|
|
func (src <%= go_type %>) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) {
|
|
switch format {
|
|
case BinaryFormatCode:
|
|
<% if skip_binary %>return nil, fmt.Errorf("binary format not supported for %T", src)<% else %>return src.EncodeBinary(ci, buf)<% end %>
|
|
case TextFormatCode:
|
|
<% if skip_text %>return nil, fmt.Errorf("text format not supported for %T", src)<% else %>return src.EncodeText(ci, buf)<% end %>
|
|
}
|
|
return nil, fmt.Errorf("unknown format code %d", format)
|
|
}
|